cloudrail_si 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +3 -0
  3. data/examples/README.md +3 -0
  4. data/examples/simple/index.rb +11 -0
  5. data/lib/cloudrail_si.rb +41 -0
  6. data/lib/cloudrail_si/RedirectReceivers.rb +40 -0
  7. data/lib/cloudrail_si/Settings.rb +12 -0
  8. data/lib/cloudrail_si/errors/DetailErrors.rb +13 -0
  9. data/lib/cloudrail_si/errors/InternalError.rb +10 -0
  10. data/lib/cloudrail_si/errors/UserError.rb +11 -0
  11. data/lib/cloudrail_si/helpers/Helper.rb +151 -0
  12. data/lib/cloudrail_si/helpers/LimitedReadableStream.rb +55 -0
  13. data/lib/cloudrail_si/helpers/SequenceReadableStream.rb +59 -0
  14. data/lib/cloudrail_si/servicecode/InitSelfTest.rb +92 -0
  15. data/lib/cloudrail_si/servicecode/Interpreter.rb +213 -0
  16. data/lib/cloudrail_si/servicecode/Sandbox.rb +361 -0
  17. data/lib/cloudrail_si/servicecode/VarAddress.rb +11 -0
  18. data/lib/cloudrail_si/servicecode/commands/AwaitCodeRedirect.rb +48 -0
  19. data/lib/cloudrail_si/servicecode/commands/Break.rb +16 -0
  20. data/lib/cloudrail_si/servicecode/commands/CallFunc.rb +26 -0
  21. data/lib/cloudrail_si/servicecode/commands/Clone.rb +18 -0
  22. data/lib/cloudrail_si/servicecode/commands/Concat.rb +22 -0
  23. data/lib/cloudrail_si/servicecode/commands/Conditional.rb +27 -0
  24. data/lib/cloudrail_si/servicecode/commands/Create.rb +56 -0
  25. data/lib/cloudrail_si/servicecode/commands/Delete.rb +21 -0
  26. data/lib/cloudrail_si/servicecode/commands/Get.rb +25 -0
  27. data/lib/cloudrail_si/servicecode/commands/GetMimeType.rb +1005 -0
  28. data/lib/cloudrail_si/servicecode/commands/JumpRel.rb +18 -0
  29. data/lib/cloudrail_si/servicecode/commands/Pull.rb +34 -0
  30. data/lib/cloudrail_si/servicecode/commands/Push.rb +32 -0
  31. data/lib/cloudrail_si/servicecode/commands/Return.rb +16 -0
  32. data/lib/cloudrail_si/servicecode/commands/Set.rb +23 -0
  33. data/lib/cloudrail_si/servicecode/commands/Size.rb +26 -0
  34. data/lib/cloudrail_si/servicecode/commands/ThrowError.rb +17 -0
  35. data/lib/cloudrail_si/servicecode/commands/array/Uint8ToBase64.rb +25 -0
  36. data/lib/cloudrail_si/servicecode/commands/debug/Out.rb +24 -0
  37. data/lib/cloudrail_si/servicecode/commands/hash/md5.rb +29 -0
  38. data/lib/cloudrail_si/servicecode/commands/hash/sha1.rb +30 -0
  39. data/lib/cloudrail_si/servicecode/commands/http/RequestCall.rb +51 -0
  40. data/lib/cloudrail_si/servicecode/commands/json/Parse.rb +40 -0
  41. data/lib/cloudrail_si/servicecode/commands/json/Stringify.rb +21 -0
  42. data/lib/cloudrail_si/servicecode/commands/math/Floor.rb +27 -0
  43. data/lib/cloudrail_si/servicecode/commands/math/MathCombine.rb +35 -0
  44. data/lib/cloudrail_si/servicecode/commands/object/GetKeyArray.rb +21 -0
  45. data/lib/cloudrail_si/servicecode/commands/object/GetKeyValueArrays.rb +29 -0
  46. data/lib/cloudrail_si/servicecode/commands/stream/MakeJoinedStream.rb +38 -0
  47. data/lib/cloudrail_si/servicecode/commands/stream/MakeLimitedStream.rb +23 -0
  48. data/lib/cloudrail_si/servicecode/commands/stream/StreamToString.rb +25 -0
  49. data/lib/cloudrail_si/servicecode/commands/stream/StringToStream.rb +20 -0
  50. data/lib/cloudrail_si/servicecode/commands/string/Base64Encode.rb +42 -0
  51. data/lib/cloudrail_si/servicecode/commands/string/Format.rb +43 -0
  52. data/lib/cloudrail_si/servicecode/commands/string/IndexOf.rb +29 -0
  53. data/lib/cloudrail_si/servicecode/commands/string/LastIndexOf.rb +29 -0
  54. data/lib/cloudrail_si/servicecode/commands/string/Split.rb +29 -0
  55. data/lib/cloudrail_si/servicecode/commands/string/StringTransform.rb +29 -0
  56. data/lib/cloudrail_si/servicecode/commands/string/Substr.rb +30 -0
  57. data/lib/cloudrail_si/servicecode/commands/string/Substring.rb +30 -0
  58. data/lib/cloudrail_si/services/Facebook.rb +528 -0
  59. data/lib/cloudrail_si/services/FacebookPage.rb +310 -0
  60. data/lib/cloudrail_si/services/Foursquare.rb +314 -0
  61. data/lib/cloudrail_si/services/GitHub.rb +354 -0
  62. data/lib/cloudrail_si/services/GooglePlaces.rb +309 -0
  63. data/lib/cloudrail_si/services/GooglePlus.rb +367 -0
  64. data/lib/cloudrail_si/services/Instagram.rb +342 -0
  65. data/lib/cloudrail_si/services/LinkedIn.rb +363 -0
  66. data/lib/cloudrail_si/services/MicrosoftLive.rb +346 -0
  67. data/lib/cloudrail_si/services/Nexmo.rb +173 -0
  68. data/lib/cloudrail_si/services/Slack.rb +318 -0
  69. data/lib/cloudrail_si/services/Twilio.rb +173 -0
  70. data/lib/cloudrail_si/services/Twitter.rb +795 -0
  71. data/lib/cloudrail_si/services/Yahoo.rb +408 -0
  72. data/lib/cloudrail_si/services/Yelp.rb +389 -0
  73. data/lib/cloudrail_si/statistics/Statistics.rb +125 -0
  74. data/lib/cloudrail_si/types/Address.rb +9 -0
  75. data/lib/cloudrail_si/types/Charge.rb +33 -0
  76. data/lib/cloudrail_si/types/CloudMetaData.rb +19 -0
  77. data/lib/cloudrail_si/types/CreditCard.rb +76 -0
  78. data/lib/cloudrail_si/types/Date.rb +49 -0
  79. data/lib/cloudrail_si/types/DateOfBirth.rb +16 -0
  80. data/lib/cloudrail_si/types/Error.rb +21 -0
  81. data/lib/cloudrail_si/types/Location.rb +8 -0
  82. data/lib/cloudrail_si/types/POI.rb +17 -0
  83. data/lib/cloudrail_si/types/Refund.rb +25 -0
  84. data/lib/cloudrail_si/types/SandboxObject.rb +20 -0
  85. data/lib/cloudrail_si/types/SpaceAllocation.rb +13 -0
  86. data/lib/cloudrail_si/types/Subscription.rb +27 -0
  87. data/lib/cloudrail_si/types/SubscriptionPlan.rb +26 -0
  88. data/lib/cloudrail_si/types/Types.rb +43 -0
  89. data/lib/cloudrail_si/version.rb +3 -0
  90. metadata +205 -0
@@ -0,0 +1,173 @@
1
+ require_relative '../servicecode/Interpreter'
2
+ require_relative '../servicecode/Sandbox'
3
+ require_relative '../errors/DetailErrors'
4
+ require_relative '../servicecode/InitSelfTest'
5
+ require_relative '../statistics/Statistics'
6
+
7
+ module CloudRailSi
8
+ module Services
9
+ class Nexmo
10
+
11
+ SERVICE_CODE = {
12
+
13
+ "SendNexmoSMS" => [
14
+ [ "callFunc", "validateUserInput", "$P0", "$P1", "$P2", "$P3"],
15
+ [ "create", "$L0", "Object"],
16
+ [ "create", "$L1", "Object"],
17
+ [ "create", "$L2", "Object"],
18
+ [ "create", "$L3", "String"],
19
+ [ "create", "$L4", "String"],
20
+ [ "string.urlEncode", "$L3", "$P3"],
21
+ [ "string.urlEncode", "$L5", "$P1"],
22
+ [ "string.concat", "$L0.url", "https://rest.nexmo.com/sms/json?api_key=", "$P0.clientID", "&api_secret=", "$P0.clientSecret", "&to=", "$P2", "&from=", "$L5", "&text=", "$L3"],
23
+ [ "set", "$L0.method", "POST"],
24
+ [ "set", "$L1.Content-Type", "application/x-www-form-urlencoded"],
25
+ [ "set", "$L1.Content-Length", "0"],
26
+ [ "set", "$L0.requestHeaders", "$L1"],
27
+ [ "debug.out", "$L0.url"],
28
+ [ "http.requestCall", "$L2", "$L0"],
29
+ [ "debug.out", "$L2"],
30
+ [ "callFunc", "checkError", "$P0", "$L2"]
31
+
32
+ ],
33
+
34
+ "validateUserInput" => [
35
+ [ "if==than", "$P1", nil, 2],
36
+ [ "create", "$L1", "Error", "One of the arguments is 'null'. You need to assign a value to it.", "IllegalArgument"],
37
+ [ "throwError", "$L1"],
38
+ [ "if==than", "$P2", nil, 2],
39
+ [ "create", "$L1", "Error", "One of the arguments is 'null'. You need to assign a value to it.", "IllegalArgument"],
40
+ [ "throwError", "$L1"],
41
+ [ "if==than", "$P3", nil, 2],
42
+ [ "create", "$L1", "Error", "One of the arguments is 'null'. You need to assign a value to it.", "IllegalArgument"],
43
+ [ "throwError", "$L1"],
44
+ [ "size", "$L2", "$P1"],
45
+ [ "if==than", "$L2", 0, 2],
46
+ [ "create", "$L1", "Error", "The 'From' number parameter is empty.", "IllegalArgument"],
47
+ [ "throwError", "$L1"],
48
+ [ "size", "$L2", "$P2"],
49
+ [ "if==than", "$L2", 0, 2],
50
+ [ "create", "$L1", "Error", "The 'To' number parameter is empty.", "IllegalArgument"],
51
+ [ "throwError", "$L1"],
52
+ [ "size", "$L2", "$P3"],
53
+ [ "if==than", "$L2", 0, 2],
54
+ [ "create", "$L1", "Error", "The message is empty.", "IllegalArgument"],
55
+ [ "throwError", "$L1"],
56
+ [ "size", "$L2", "$P1"],
57
+ [ "if>than", "$L2", 16, 2],
58
+ [ "create", "$L1", "Error", "The 'From' phone number is too big, it should have maximum 15 digits. Example: +16175551212", "IllegalArgument"],
59
+ [ "throwError", "$L1"],
60
+ [ "string.lastIndexOf", "$L0", "$P2", "+"],
61
+ [ "if!=than", "$L0", 0, 2],
62
+ [ "create", "$L1", "Error", "The 'To' phone number isn't in E.164 format. Example: +16175551212", "IllegalArgument"],
63
+ [ "throwError", "$L1"],
64
+ [ "size", "$L2", "$P2"],
65
+ [ "if>than", "$L2", 16, 2],
66
+ [ "create", "$L1", "Error", "The 'To' phone number is too big, it should have maximum 15 digits. Example: +16175551212", "IllegalArgument"],
67
+ [ "throwError", "$L1"],
68
+ [ "size", "$L2", "$P3"],
69
+ [ "if>than", "$L2", 1600, 2],
70
+ [ "create", "$L1", "Error", "The length of the message exceeds the 1600 allowed characters.", "IllegalArgument"],
71
+ [ "throwError", "$L1"]
72
+
73
+ ],
74
+
75
+ "checkError" => [
76
+ [ "if>=than", "$P1.code", 400, 8],
77
+ [ "if==than", "$P1.code", 401, 2],
78
+ [ "create", "$L3", "Error", "Invalid credentials or access rights. Make sure that your application has read and write permission.", "Authentication"],
79
+ [ "throwError", "$L3"],
80
+ [ "if==than", "$P1.code", 503, 2],
81
+ [ "create", "$L3", "Error", "Service unavailable. Try again later.", "ServiceUnavailable"],
82
+ [ "throwError", "$L3"],
83
+ [ "create", "$L3", "Error", "$P1.message", "Http"],
84
+ [ "throwError", "$L3"],
85
+ [ "stream.streamToString", "$L11", "$P1.responseBody"],
86
+ [ "create", "$L12", "Object"],
87
+ [ "json.parse", "$L12", "$L11"],
88
+ [ "debug.out", "$L12"],
89
+ [ "set", "$L13", "$L12.messages.0.status"],
90
+ [ "set", "$L14", "$L12.messages.0.error-text"],
91
+ [ "debug.out", "$L13"],
92
+ [ "if!=than", "$L13", "0", 2],
93
+ [ "create", "$L15", "Error", "$L14", "Http"],
94
+ [ "throwError", "$L15"]
95
+
96
+ ]
97
+
98
+ }
99
+
100
+ def initialize(redirect_receiver, client_id, client_secret)
101
+ @interpreter_storage = {}
102
+ @persistent_storage = [{}]
103
+ @instance_dependency_storage = {
104
+ redirect_receiver: redirect_receiver
105
+ }
106
+
107
+ ServiceCode::InitSelfTest.init_test('Nexmo')
108
+
109
+ @interpreter_storage['clientID'] = client_id
110
+ @interpreter_storage['clientSecret'] = client_secret
111
+
112
+
113
+
114
+
115
+ # call init servicecode function
116
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
117
+ # check and call the initialization function if is available
118
+
119
+ ip.call_function_sync('init', @interpreter_storage) if (SERVICE_CODE['init'])
120
+ end
121
+
122
+ def check_for_error(error)
123
+ if (error)
124
+ ServiceCode::Statistics.add_error('Nexmo', '')
125
+ case (error.type)
126
+ when 'IllegalArgument'
127
+ raise Errors::IllegalArgumentError.new(error.message)
128
+ when 'Authentication'
129
+ raise Errors::AuthenticationError.new(error.message)
130
+ when 'NotFound'
131
+ raise Errors::NotFoundError.new(error.message)
132
+ when 'Http'
133
+ raise Errors::HttpError.new(error.message)
134
+ when 'ServiceUnavailable'
135
+ raise Errors::ServiceUnavailableError.new(error.message)
136
+ else
137
+ raise Errors::StandardError.new(error.message)
138
+ end
139
+ end
140
+ end
141
+
142
+
143
+ def send_sms(from_name, to_number, content)
144
+ ServiceCode::Statistics.add_call('Nexmo', 'send_sms')
145
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
146
+ ip.call_function('SendNexmoSMS', @interpreter_storage, from_name, to_number, content)
147
+
148
+ check_for_error(ip.sandbox.thrown_error)
149
+ return nil
150
+ end
151
+
152
+
153
+ def save_as_string
154
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
155
+ return ip.save_as_string()
156
+ end
157
+
158
+ def load_as_string(saved_state)
159
+ sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
160
+ ip = ServiceCode::Interpreter.new(sandbox)
161
+ ip.load_as_string(saved_state)
162
+ @persistent_storage = sandbox.persistent_storage
163
+ end
164
+
165
+ def resume_login(execution_state, callback)
166
+ sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
167
+ sandbox.load_state_from_string(execution_state)
168
+ ip = ServiceCode::Interpreter.new(sandbox)
169
+ ip.resume_function('Authenticating:login', @interpreter_storage, callback)
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,318 @@
1
+ require_relative '../servicecode/Interpreter'
2
+ require_relative '../servicecode/Sandbox'
3
+ require_relative '../errors/DetailErrors'
4
+ require_relative '../servicecode/InitSelfTest'
5
+ require_relative '../statistics/Statistics'
6
+
7
+ module CloudRailSi
8
+ module Services
9
+ class Slack
10
+
11
+ SERVICE_CODE = {
12
+
13
+ "AdvancedRequestSupporter:advancedRequest" => [
14
+ [ "create", "$L0", "Object"],
15
+ [ "create", "$L0.url", "String"],
16
+ [ "if!=than", "$P2.appendBaseUrl", 0, 1],
17
+ [ "set", "$L0.url", "https://slack.com/api"],
18
+ [ "string.concat", "$L0.url", "$L0.url", "$P2.url"],
19
+ [ "set", "$L0.requestHeaders", "$P2.headers"],
20
+ [ "set", "$L0.method", "$P2.method"],
21
+ [ "set", "$L0.requestBody", "$P2.body"],
22
+ [ "if!=than", "$P2.appendAuthorization", 0, 6],
23
+ [ "callFunc", "checkAuthentication", "$P0"],
24
+ [ "string.indexOf", "$L2", "$P2.url", "?"],
25
+ [ "if==than", "$L2", -1, 2],
26
+ [ "string.concat", "$L0.url", "$L0.url", "?token=", "$S0.accessToken"],
27
+ [ "jumpRel", 1],
28
+ [ "string.concat", "$L0.url", "$L0.url", "&token=", "$S0.accessToken"],
29
+ [ "http.requestCall", "$L1", "$L0"],
30
+ [ "if!=than", "$P2.checkErrors", 0, 1],
31
+ [ "callFunc", "validateResponse", "$P0", "$L1"],
32
+ [ "create", "$P1", "AdvancedRequestResponse"],
33
+ [ "set", "$P1.status", "$L1.code"],
34
+ [ "set", "$P1.headers", "$L1.responseHeaders"],
35
+ [ "set", "$P1.body", "$L1.responseBody"]
36
+
37
+ ],
38
+
39
+ "Authenticating:login" => [
40
+ [ "callFunc", "checkAuthentication", "$P0"]
41
+
42
+ ],
43
+
44
+ "Authenticating:logout" => [
45
+ [ "set", "$S0.accessToken", nil],
46
+ [ "set", "$P0.userInfo", nil]
47
+
48
+ ],
49
+
50
+ "Profile:getIdentifier" => [
51
+ [ "callFunc", "checkUserInfo", "$P0"],
52
+ [ "string.concat", "$P1", "slack-", "$P0.userInfo.team.id", "-", "$P0.userInfo.user.id"]
53
+
54
+ ],
55
+
56
+ "Profile:getFullName" => [
57
+ [ "callFunc", "checkUserInfo", "$P0"],
58
+ [ "if!=than", "$P0.userInfo.user.name", nil, 1],
59
+ [ "set", "$P1", "$P0.userInfo.user.name"]
60
+
61
+ ],
62
+
63
+ "Profile:getEmail" => [
64
+ [ "callFunc", "checkUserInfo", "$P0"],
65
+ [ "if!=than", "$P0.userInfo.user.email", nil, 1],
66
+ [ "set", "$P1", "$P0.userInfo.user.email"]
67
+
68
+ ],
69
+
70
+ "Profile:getGender" => [
71
+
72
+ ],
73
+
74
+ "Profile:getDescription" => [
75
+
76
+ ],
77
+
78
+ "Profile:getDateOfBirth" => [
79
+ [ "create", "$P1", "DateOfBirth"]
80
+
81
+ ],
82
+
83
+ "Profile:getLocale" => [
84
+
85
+ ],
86
+
87
+ "Profile:getPictureURL" => [
88
+ [ "callFunc", "checkUserInfo", "$P0"],
89
+ [ "if!=than", "$P0.userInfo.user.image_192", nil, 1],
90
+ [ "set", "$P1", "$P0.userInfo.user.image_192"]
91
+
92
+ ],
93
+
94
+ "checkUserInfo" => [
95
+ [ "create", "$L0", "Date"],
96
+ [ "if!=than", "$P0.userInfo", nil, 2],
97
+ [ "if>than", "$P0.expirationTime", "$L0", 1],
98
+ [ "return"],
99
+ [ "callFunc", "checkAuthentication", "$P0"],
100
+ [ "create", "$L2", "Object"],
101
+ [ "string.concat", "$L2.url", "https://slack.com/api/users.identity?token=", "$S0.accessToken"],
102
+ [ "set", "$L2.method", "GET"],
103
+ [ "http.requestCall", "$L3", "$L2"],
104
+ [ "callFunc", "validateResponse", "$P0", "$L3"],
105
+ [ "callFunc", "parseAndCheckResponse", "$P0", "$P0.userInfo", "$L3.responseBody"],
106
+ [ "create", "$P0.expirationTime", "Date"],
107
+ [ "math.add", "$P0.expirationTime.time", "$P0.expirationTime.time", 60000]
108
+
109
+ ],
110
+
111
+ "checkAuthentication" => [
112
+ [ "if!=than", nil, "$S0.accessToken", 1],
113
+ [ "return"],
114
+ [ "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"],
115
+ [ "awaitCodeRedirect", "$L1", "$L0"],
116
+ [ "create", "$L2", "Object"],
117
+ [ "set", "$L2.method", "GET"],
118
+ [ "string.concat", "$L3", "code=", "$L1", "&redirect_uri=", "$P0.redirectUri", "&client_id=", "$P0.clientId", "&client_secret=", "$P0.clientSecret"],
119
+ [ "string.concat", "$L2.url", "https://slack.com/api/oauth.access?", "$L3"],
120
+ [ "http.requestCall", "$L5", "$L2"],
121
+ [ "callFunc", "validateResponse", "$P0", "$L5"],
122
+ [ "callFunc", "parseAndCheckResponse", "$P0", "$L6", "$L5.responseBody"],
123
+ [ "set", "$S0.accessToken", "$L6.access_token"]
124
+
125
+ ],
126
+
127
+ "validateResponse" => [
128
+ [ "if>=than", "$P1.code", 400, 10],
129
+ [ "if==than", "$P1.code", 401, 2],
130
+ [ "create", "$L3", "Error", "Invalid credentials or access rights. Make sure that your application has read and write permission.", "Authentication"],
131
+ [ "throwError", "$L3"],
132
+ [ "if==than", "$P1.code", 503, 2],
133
+ [ "create", "$L3", "Error", "Service unavailable. Try again later.", "ServiceUnavailable"],
134
+ [ "throwError", "$L3"],
135
+ [ "json.parse", "$L0", "$P1.responseBody"],
136
+ [ "string.concat", "$L2", "$P1.code", " - ", "$L0.error"],
137
+ [ "create", "$L3", "Error", "$L2", "Http"],
138
+ [ "throwError", "$L3"]
139
+
140
+ ],
141
+
142
+ "parseAndCheckResponse" => [
143
+ [ "json.parse", "$L0", "$P2"],
144
+ [ "if==than", "$L0.ok", 0, 2],
145
+ [ "create", "$L3", "Error", "$L0.error", "Http"],
146
+ [ "throwError", "$L3"],
147
+ [ "set", "$P1", "$L0"]
148
+
149
+ ]
150
+
151
+ }
152
+
153
+ def initialize(redirect_receiver, client_id, client_secret, redirect_uri, state)
154
+ @interpreter_storage = {}
155
+ @persistent_storage = [{}]
156
+ @instance_dependency_storage = {
157
+ redirect_receiver: redirect_receiver
158
+ }
159
+
160
+ ServiceCode::InitSelfTest.init_test('Slack')
161
+
162
+ @interpreter_storage['clientId'] = client_id
163
+ @interpreter_storage['clientSecret'] = client_secret
164
+ @interpreter_storage['redirectUri'] = redirect_uri
165
+ @interpreter_storage['state'] = state
166
+
167
+
168
+
169
+
170
+ # call init servicecode function
171
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
172
+ # check and call the initialization function if is available
173
+
174
+ ip.call_function_sync('init', @interpreter_storage) if (SERVICE_CODE['init'])
175
+ end
176
+
177
+ def check_for_error(error)
178
+ if (error)
179
+ ServiceCode::Statistics.add_error('Slack', '')
180
+ case (error.type)
181
+ when 'IllegalArgument'
182
+ raise Errors::IllegalArgumentError.new(error.message)
183
+ when 'Authentication'
184
+ raise Errors::AuthenticationError.new(error.message)
185
+ when 'NotFound'
186
+ raise Errors::NotFoundError.new(error.message)
187
+ when 'Http'
188
+ raise Errors::HttpError.new(error.message)
189
+ when 'ServiceUnavailable'
190
+ raise Errors::ServiceUnavailableError.new(error.message)
191
+ else
192
+ raise Errors::StandardError.new(error.message)
193
+ end
194
+ end
195
+ end
196
+
197
+
198
+ def get_identifier()
199
+ ServiceCode::Statistics.add_call('Slack', 'get_identifier')
200
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
201
+ ip.call_function('Profile:getIdentifier', @interpreter_storage, nil)
202
+
203
+ check_for_error(ip.sandbox.thrown_error)
204
+ return nil || ip.get_parameter(1)
205
+ end
206
+
207
+ def get_full_name()
208
+ ServiceCode::Statistics.add_call('Slack', 'get_full_name')
209
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
210
+ ip.call_function('Profile:getFullName', @interpreter_storage, nil)
211
+
212
+ check_for_error(ip.sandbox.thrown_error)
213
+ return nil || ip.get_parameter(1)
214
+ end
215
+
216
+ def get_email()
217
+ ServiceCode::Statistics.add_call('Slack', 'get_email')
218
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
219
+ ip.call_function('Profile:getEmail', @interpreter_storage, nil)
220
+
221
+ check_for_error(ip.sandbox.thrown_error)
222
+ return nil || ip.get_parameter(1)
223
+ end
224
+
225
+ def get_gender()
226
+ ServiceCode::Statistics.add_call('Slack', 'get_gender')
227
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
228
+ ip.call_function('Profile:getGender', @interpreter_storage, nil)
229
+
230
+ check_for_error(ip.sandbox.thrown_error)
231
+ return nil || ip.get_parameter(1)
232
+ end
233
+
234
+ def get_description()
235
+ ServiceCode::Statistics.add_call('Slack', 'get_description')
236
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
237
+ ip.call_function('Profile:getDescription', @interpreter_storage, nil)
238
+
239
+ check_for_error(ip.sandbox.thrown_error)
240
+ return nil || ip.get_parameter(1)
241
+ end
242
+
243
+ def get_date_of_birth()
244
+ ServiceCode::Statistics.add_call('Slack', 'get_date_of_birth')
245
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
246
+ ip.call_function('Profile:getDateOfBirth', @interpreter_storage, nil)
247
+
248
+ check_for_error(ip.sandbox.thrown_error)
249
+ return nil || ip.get_parameter(1)
250
+ end
251
+
252
+ def get_locale()
253
+ ServiceCode::Statistics.add_call('Slack', 'get_locale')
254
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
255
+ ip.call_function('Profile:getLocale', @interpreter_storage, nil)
256
+
257
+ check_for_error(ip.sandbox.thrown_error)
258
+ return nil || ip.get_parameter(1)
259
+ end
260
+
261
+ def get_picture_url()
262
+ ServiceCode::Statistics.add_call('Slack', 'get_picture_url')
263
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
264
+ ip.call_function('Profile:getPictureURL', @interpreter_storage, nil)
265
+
266
+ check_for_error(ip.sandbox.thrown_error)
267
+ return nil || ip.get_parameter(1)
268
+ end
269
+
270
+ def login()
271
+ ServiceCode::Statistics.add_call('Slack', 'login')
272
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
273
+ ip.call_function('Authenticating:login', @interpreter_storage)
274
+
275
+ check_for_error(ip.sandbox.thrown_error)
276
+ return nil
277
+ end
278
+
279
+ def logout()
280
+ ServiceCode::Statistics.add_call('Slack', 'logout')
281
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
282
+ ip.call_function('Authenticating:logout', @interpreter_storage)
283
+
284
+ check_for_error(ip.sandbox.thrown_error)
285
+ return nil
286
+ end
287
+
288
+ def advanced_request(specification)
289
+ ServiceCode::Statistics.add_call('Slack', 'advanced_request')
290
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
291
+ ip.call_function('AdvancedRequestSupporter:advancedRequest', @interpreter_storage, nil, specification)
292
+
293
+ check_for_error(ip.sandbox.thrown_error)
294
+ return nil || ip.get_parameter(1)
295
+ end
296
+
297
+
298
+ def save_as_string
299
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
300
+ return ip.save_as_string()
301
+ end
302
+
303
+ def load_as_string(saved_state)
304
+ sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
305
+ ip = ServiceCode::Interpreter.new(sandbox)
306
+ ip.load_as_string(saved_state)
307
+ @persistent_storage = sandbox.persistent_storage
308
+ end
309
+
310
+ def resume_login(execution_state, callback)
311
+ sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
312
+ sandbox.load_state_from_string(execution_state)
313
+ ip = ServiceCode::Interpreter.new(sandbox)
314
+ ip.resume_function('Authenticating:login', @interpreter_storage, callback)
315
+ end
316
+ end
317
+ end
318
+ end