Class: CloudRailSi::Services::Slack
- Inherits:
-
Object
- Object
- CloudRailSi::Services::Slack
- Defined in:
- lib/cloudrail_si/services/Slack.rb
Constant Summary collapse
- SERVICE_CODE =
{ "AdvancedRequestSupporter:advancedRequest" => [ [ "create", "$L0", "Object"], [ "create", "$L0.url", "String"], [ "if!=than", "$P2.appendBaseUrl", 0, 1], [ "set", "$L0.url", "https://slack.com/api"], [ "string.concat", "$L0.url", "$L0.url", "$P2.url"], [ "set", "$L0.requestHeaders", "$P2.headers"], [ "set", "$L0.method", "$P2.method"], [ "set", "$L0.requestBody", "$P2.body"], [ "if!=than", "$P2.appendAuthorization", 0, 6], [ "callFunc", "checkAuthentication", "$P0"], [ "string.indexOf", "$L2", "$P2.url", "?"], [ "if==than", "$L2", -1, 2], [ "string.concat", "$L0.url", "$L0.url", "?token=", "$S0.accessToken"], [ "jumpRel", 1], [ "string.concat", "$L0.url", "$L0.url", "&token=", "$S0.accessToken"], [ "http.requestCall", "$L1", "$L0"], [ "if!=than", "$P2.checkErrors", 0, 1], [ "callFunc", "validateResponse", "$P0", "$L1"], [ "create", "$P1", "AdvancedRequestResponse"], [ "set", "$P1.status", "$L1.code"], [ "set", "$P1.headers", "$L1.responseHeaders"], [ "set", "$P1.body", "$L1.responseBody"] ], "Authenticating:login" => [ [ "callFunc", "checkAuthentication", "$P0"] ], "Authenticating:logout" => [ [ "set", "$S0.accessToken", nil], [ "set", "$P0.userInfo", nil] ], "Profile:getIdentifier" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "string.concat", "$P1", "slack-", "$P0.userInfo.team.id", "-", "$P0.userInfo.user.id"] ], "Profile:getFullName" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.user.name", nil, 1], [ "set", "$P1", "$P0.userInfo.user.name"] ], "Profile:getEmail" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.user.email", nil, 1], [ "set", "$P1", "$P0.userInfo.user.email"] ], "Profile:getGender" => [ ], "Profile:getDescription" => [ ], "Profile:getDateOfBirth" => [ [ "create", "$P1", "DateOfBirth"] ], "Profile:getLocale" => [ ], "Profile:getPictureURL" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.user.image_192", nil, 1], [ "set", "$P1", "$P0.userInfo.user.image_192"] ], "checkUserInfo" => [ [ "create", "$L0", "Date"], [ "if!=than", "$P0.userInfo", nil, 2], [ "if>than", "$P0.expirationTime", "$L0", 1], [ "return"], [ "callFunc", "checkAuthentication", "$P0"], [ "create", "$L2", "Object"], [ "string.concat", "$L2.url", "https://slack.com/api/users.identity?token=", "$S0.accessToken"], [ "set", "$L2.method", "GET"], [ "http.requestCall", "$L3", "$L2"], [ "callFunc", "validateResponse", "$P0", "$L3"], [ "callFunc", "parseAndCheckResponse", "$P0", "$P0.userInfo", "$L3.responseBody"], [ "create", "$P0.expirationTime", "Date"], [ "math.add", "$P0.expirationTime.time", "$P0.expirationTime.time", 60000] ], "checkAuthentication" => [ [ "if!=than", nil, "$S0.accessToken", 1], [ "return"], [ "string.concat", "$L0", "https://slack.com/oauth/authorize?redirect_uri=", "$P0.redirectUri", "&client_id=", "$P0.clientId", "&state=", "$P0.state", "&scope=", "identity.basic,identity.team,identity.avatar,identity.email"], [ "awaitCodeRedirect", "$L1", "$L0"], [ "create", "$L2", "Object"], [ "set", "$L2.method", "GET"], [ "string.concat", "$L3", "code=", "$L1", "&redirect_uri=", "$P0.redirectUri", "&client_id=", "$P0.clientId", "&client_secret=", "$P0.clientSecret"], [ "string.concat", "$L2.url", "https://slack.com/api/oauth.access?", "$L3"], [ "http.requestCall", "$L5", "$L2"], [ "callFunc", "validateResponse", "$P0", "$L5"], [ "callFunc", "parseAndCheckResponse", "$P0", "$L6", "$L5.responseBody"], [ "set", "$S0.accessToken", "$L6.access_token"] ], "validateResponse" => [ [ "if>=than", "$P1.code", 400, 10], [ "if==than", "$P1.code", 401, 2], [ "create", "$L3", "Error", "Invalid credentials or access rights. Make sure that your application has read and write permission.", "Authentication"], [ "throwError", "$L3"], [ "if==than", "$P1.code", 503, 2], [ "create", "$L3", "Error", "Service unavailable. Try again later.", "ServiceUnavailable"], [ "throwError", "$L3"], [ "json.parse", "$L0", "$P1.responseBody"], [ "string.concat", "$L2", "$P1.code", " - ", "$L0.error"], [ "create", "$L3", "Error", "$L2", "Http"], [ "throwError", "$L3"] ], "parseAndCheckResponse" => [ [ "json.parse", "$L0", "$P2"], [ "if==than", "$L0.ok", 0, 2], [ "create", "$L3", "Error", "$L0.error", "Http"], [ "throwError", "$L3"], [ "set", "$P1", "$L0"] ] }
Instance Method Summary collapse
- #advanced_request(specification) ⇒ Object
- #check_for_error(error) ⇒ Object
- #get_date_of_birth ⇒ Object
- #get_description ⇒ Object
- #get_email ⇒ Object
- #get_full_name ⇒ Object
- #get_gender ⇒ Object
- #get_identifier ⇒ Object
- #get_locale ⇒ Object
- #get_picture_url ⇒ Object
-
#initialize(redirect_receiver, client_id, client_secret, redirect_uri, state) ⇒ Slack
constructor
A new instance of Slack.
- #load_as_string(saved_state) ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #resume_login(execution_state, callback) ⇒ Object
- #save_as_string ⇒ Object
Constructor Details
#initialize(redirect_receiver, client_id, client_secret, redirect_uri, state) ⇒ Slack
Returns a new instance of Slack.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/cloudrail_si/services/Slack.rb', line 153 def initialize(redirect_receiver, client_id, client_secret, redirect_uri, state) @interpreter_storage = {} @persistent_storage = [{}] @instance_dependency_storage = { redirect_receiver: redirect_receiver } ServiceCode::InitSelfTest.init_test('Slack') @interpreter_storage['clientId'] = client_id @interpreter_storage['clientSecret'] = client_secret @interpreter_storage['redirectUri'] = redirect_uri @interpreter_storage['state'] = state # call init servicecode function ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) # check and call the initialization function if is available ip.call_function_sync('init', @interpreter_storage) if (SERVICE_CODE['init']) end |
Instance Method Details
#advanced_request(specification) ⇒ Object
288 289 290 291 292 293 294 295 |
# File 'lib/cloudrail_si/services/Slack.rb', line 288 def advanced_request(specification) ServiceCode::Statistics.add_call('Slack', 'advanced_request') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('AdvancedRequestSupporter:advancedRequest', @interpreter_storage, nil, specification) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#check_for_error(error) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/cloudrail_si/services/Slack.rb', line 177 def check_for_error(error) if (error) ServiceCode::Statistics.add_error('Slack', '') case (error.type) when 'IllegalArgument' raise Errors::IllegalArgumentError.new(error.) when 'Authentication' raise Errors::AuthenticationError.new(error.) when 'NotFound' raise Errors::NotFoundError.new(error.) when 'Http' raise Errors::HttpError.new(error.) when 'ServiceUnavailable' raise Errors::ServiceUnavailableError.new(error.) else raise Errors::StandardError.new(error.) end end end |
#get_date_of_birth ⇒ Object
243 244 245 246 247 248 249 250 |
# File 'lib/cloudrail_si/services/Slack.rb', line 243 def get_date_of_birth() ServiceCode::Statistics.add_call('Slack', 'get_date_of_birth') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Profile:getDateOfBirth', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_description ⇒ Object
234 235 236 237 238 239 240 241 |
# File 'lib/cloudrail_si/services/Slack.rb', line 234 def get_description() ServiceCode::Statistics.add_call('Slack', 'get_description') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Profile:getDescription', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_email ⇒ Object
216 217 218 219 220 221 222 223 |
# File 'lib/cloudrail_si/services/Slack.rb', line 216 def get_email() ServiceCode::Statistics.add_call('Slack', 'get_email') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Profile:getEmail', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_full_name ⇒ Object
207 208 209 210 211 212 213 214 |
# File 'lib/cloudrail_si/services/Slack.rb', line 207 def get_full_name() ServiceCode::Statistics.add_call('Slack', 'get_full_name') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Profile:getFullName', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_gender ⇒ Object
225 226 227 228 229 230 231 232 |
# File 'lib/cloudrail_si/services/Slack.rb', line 225 def get_gender() ServiceCode::Statistics.add_call('Slack', 'get_gender') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Profile:getGender', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_identifier ⇒ Object
198 199 200 201 202 203 204 205 |
# File 'lib/cloudrail_si/services/Slack.rb', line 198 def get_identifier() ServiceCode::Statistics.add_call('Slack', 'get_identifier') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Profile:getIdentifier', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_locale ⇒ Object
252 253 254 255 256 257 258 259 |
# File 'lib/cloudrail_si/services/Slack.rb', line 252 def get_locale() ServiceCode::Statistics.add_call('Slack', 'get_locale') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Profile:getLocale', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_picture_url ⇒ Object
261 262 263 264 265 266 267 268 |
# File 'lib/cloudrail_si/services/Slack.rb', line 261 def get_picture_url() ServiceCode::Statistics.add_call('Slack', 'get_picture_url') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Profile:getPictureURL', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#load_as_string(saved_state) ⇒ Object
303 304 305 306 307 308 |
# File 'lib/cloudrail_si/services/Slack.rb', line 303 def load_as_string(saved_state) sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage) ip = ServiceCode::Interpreter.new(sandbox) ip.load_as_string(saved_state) @persistent_storage = sandbox.persistent_storage end |
#login ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'lib/cloudrail_si/services/Slack.rb', line 270 def login() ServiceCode::Statistics.add_call('Slack', 'login') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Authenticating:login', @interpreter_storage) check_for_error(ip.sandbox.thrown_error) return nil end |
#logout ⇒ Object
279 280 281 282 283 284 285 286 |
# File 'lib/cloudrail_si/services/Slack.rb', line 279 def logout() ServiceCode::Statistics.add_call('Slack', 'logout') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('Authenticating:logout', @interpreter_storage) check_for_error(ip.sandbox.thrown_error) return nil end |
#resume_login(execution_state, callback) ⇒ Object
310 311 312 313 314 315 |
# File 'lib/cloudrail_si/services/Slack.rb', line 310 def resume_login(execution_state, callback) sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage) sandbox.load_state_from_string(execution_state) ip = ServiceCode::Interpreter.new(sandbox) ip.resume_function('Authenticating:login', @interpreter_storage, callback) end |
#save_as_string ⇒ Object
298 299 300 301 |
# File 'lib/cloudrail_si/services/Slack.rb', line 298 def save_as_string ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) return ip.save_as_string() end |