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,408 @@
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 Yahoo
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://social.yahooapis.com/v1"],
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, 2],
23
+ [ "callFunc", "checkAuthentication", "$P0"],
24
+ [ "string.concat", "$L0.requestHeaders.Authorization", "Bearer ", "$S0.accessToken"],
25
+ [ "http.requestCall", "$L1", "$L0"],
26
+ [ "if!=than", "$P2.checkErrors", 0, 1],
27
+ [ "callFunc", "validateResponse", "$P0", "$L1"],
28
+ [ "create", "$P1", "AdvancedRequestResponse"],
29
+ [ "set", "$P1.status", "$L1.code"],
30
+ [ "set", "$P1.headers", "$L1.responseHeaders"],
31
+ [ "set", "$P1.body", "$L1.responseBody"]
32
+
33
+ ],
34
+
35
+ "getYUIdentifier" => [
36
+ [ "callFunc", "checkAuthentication", "$P0"],
37
+ [ "if==than", "$P0.cachedObject", nil, 2],
38
+ [ "callFunc", "makeHTTPRequest", "$P0"],
39
+ [ "jumpRel", 1],
40
+ [ "callFunc", "checkExpirationTime", "$P0"],
41
+ [ "string.concat", "$P1", "yahoo-", "$P0.userID"]
42
+
43
+ ],
44
+
45
+ "getYUFullName" => [
46
+ [ "callFunc", "checkAuthentication", "$P0"],
47
+ [ "if==than", "$P0.cachedObject", nil, 2],
48
+ [ "callFunc", "makeHTTPRequest", "$P0"],
49
+ [ "jumpRel", 1],
50
+ [ "callFunc", "checkExpirationTime", "$P0"],
51
+ [ "if==than", "$P0.cachedObject.profile.givenName", nil, 2],
52
+ [ "set", "$P1", nil],
53
+ [ "jumpRel", 2],
54
+ [ "string.concat", "$L0", "$P0.cachedObject.profile.givenName", " ", "$P0.cachedObject.profile.familyName"],
55
+ [ "set", "$P1", "$L0"]
56
+
57
+ ],
58
+
59
+ "getYUEmail" => [
60
+ [ "callFunc", "checkAuthentication", "$P0"],
61
+ [ "if==than", "$P0.cachedObject", nil, 2],
62
+ [ "callFunc", "makeHTTPRequest", "$P0"],
63
+ [ "jumpRel", 1],
64
+ [ "callFunc", "checkExpirationTime", "$P0"],
65
+ [ "if==than", "$P0.cachedObject.profile.emails.0.handle", nil, 2],
66
+ [ "set", "$P1", nil],
67
+ [ "jumpRel", 1],
68
+ [ "set", "$P1", "$P0.cachedObject.profile.emails.0.handle"]
69
+
70
+ ],
71
+
72
+ "getYUGender" => [
73
+ [ "callFunc", "checkAuthentication", "$P0"],
74
+ [ "if==than", "$P0.cachedObject", nil, 2],
75
+ [ "callFunc", "makeHTTPRequest", "$P0"],
76
+ [ "jumpRel", 1],
77
+ [ "callFunc", "checkExpirationTime", "$P0"],
78
+ [ "if==than", "$P0.cachedObject.profile.gender", nil, 2],
79
+ [ "set", "$P1", nil],
80
+ [ "jumpRel", 8],
81
+ [ "if==than", "$P0.cachedObject.profile.gender", "M", 2],
82
+ [ "set", "$P1", "male"],
83
+ [ "jumpRel", 5],
84
+ [ "if==than", "$P0.cachedObject.profile.gender", "F", 2],
85
+ [ "set", "$P1", "female"],
86
+ [ "jumpRel", 2],
87
+ [ "if==than", "$P0.cachedObject.profile.gender", "Unspecified", 1],
88
+ [ "set", "$P1", "other"]
89
+
90
+ ],
91
+
92
+ "getYUDescription" => [
93
+ [ "set", "$P1", nil]
94
+
95
+ ],
96
+
97
+ "getYUDateOfBirth" => [
98
+ [ "create", "$P1", "DateOfBirth"]
99
+
100
+ ],
101
+
102
+ "getYULocale" => [
103
+ [ "callFunc", "checkAuthentication", "$P0"],
104
+ [ "if==than", "$P0.cachedObject", nil, 2],
105
+ [ "callFunc", "makeHTTPRequest", "$P0"],
106
+ [ "jumpRel", 1],
107
+ [ "callFunc", "checkExpirationTime", "$P0"],
108
+ [ "if==than", "$P0.cachedObject.profile.lang", nil, 2],
109
+ [ "set", "$P1", nil],
110
+ [ "jumpRel", 1],
111
+ [ "string.substring", "$P1", "$P0.cachedObject.profile.lang", 0, 2]
112
+
113
+ ],
114
+
115
+ "getYUPictureURL" => [
116
+ [ "callFunc", "checkAuthentication", "$P0"],
117
+ [ "if==than", "$P0.cachedObject", nil, 2],
118
+ [ "callFunc", "makeHTTPRequest", "$P0"],
119
+ [ "jumpRel", 1],
120
+ [ "callFunc", "checkExpirationTime", "$P0"],
121
+ [ "if==than", "$P0.cachedObject.profile.image.imageUrl", nil, 2],
122
+ [ "set", "$P1", nil],
123
+ [ "jumpRel", 1],
124
+ [ "set", "$P1", "$P0.cachedObject.profile.image.imageUrl"]
125
+
126
+ ],
127
+
128
+ "loginYU" => [
129
+ [ "callFunc", "authenticate", "$P0", "accessToken"]
130
+
131
+ ],
132
+
133
+ "logoutYU" => [
134
+ [ "set", "$S0.accessToken", nil],
135
+ [ "set", "$P0.userID", nil],
136
+ [ "set", "$P0.cachedObject", nil]
137
+
138
+ ],
139
+
140
+ "getUserID" => [
141
+ [ "create", "$L0", "Object"],
142
+ [ "set", "$L0.method", "GET"],
143
+ [ "set", "$L0.url", "https://social.yahooapis.com/v1/me/guid"],
144
+ [ "create", "$L0.requestHeaders", "Object"],
145
+ [ "string.concat", "$L0.requestHeaders.Authorization", "Bearer ", "$S0.accessToken"],
146
+ [ "set", "$L0.requestHeaders.Accept", "application/json"],
147
+ [ "create", "$L1", "Object"],
148
+ [ "http.requestCall", "$L1", "$L0"],
149
+ [ "callFunc", "validateResponse", "$P0", "$L1"],
150
+ [ "create", "$L2", "Object"],
151
+ [ "json.parse", "$L2", "$L1.responseBody"],
152
+ [ "set", "$P0.userID", "$L2.guid.value"]
153
+
154
+ ],
155
+
156
+ "makeHTTPRequest" => [
157
+ [ "callFunc", "getUserID", "$P0"],
158
+ [ "create", "$L0", "Object"],
159
+ [ "set", "$L0.method", "GET"],
160
+ [ "string.concat", "$L0.url", "https://social.yahooapis.com/v1/user/", "$P0.userID", "/profile"],
161
+ [ "create", "$L0.requestHeaders", "Object"],
162
+ [ "string.concat", "$L0.requestHeaders.Authorization", "Bearer ", "$S0.accessToken"],
163
+ [ "set", "$L0.requestHeaders.Accept", "application/json"],
164
+ [ "create", "$L1", "Object"],
165
+ [ "http.requestCall", "$L1", "$L0"],
166
+ [ "callFunc", "validateResponse", "$P0", "$L1"],
167
+ [ "json.parse", "$P0.cachedObject", "$L1.responseBody"],
168
+ [ "create", "$L2", "Date"],
169
+ [ "set", "$P0.readTime", "$L2.time"]
170
+
171
+ ],
172
+
173
+ "checkExpirationTime" => [
174
+ [ "create", "$L0", "Date"],
175
+ [ "math.multiply", "$L1", "$P0.readTime", -1],
176
+ [ "math.add", "$L2", "$L0.time", "$L1"],
177
+ [ "if>than", "$L2", 60000, 1],
178
+ [ "callFunc", "makeHTTPRequest", "$P0"]
179
+
180
+ ],
181
+
182
+ "checkAuthentication" => [
183
+ [ "create", "$L0", "Date"],
184
+ [ "if==than", "$S0.accessToken", nil, 2],
185
+ [ "callFunc", "authenticate", "$P0", "accessToken"],
186
+ [ "return"],
187
+ [ "create", "$L1", "Date"],
188
+ [ "set", "$L1.time", "$S0.expireIn"],
189
+ [ "if<than", "$L1", "$L0", 1],
190
+ [ "callFunc", "authenticate", "$P0", "refreshToken"]
191
+
192
+ ],
193
+
194
+ "authenticate" => [
195
+ [ "if==than", "$P1", "accessToken", 4],
196
+ [ "string.concat", "$L0", "https://api.login.yahoo.com/oauth2/request_auth?client_id=", "$P0.clientId", "&redirect_uri=", "$P0.redirectUri", "&response_type=code&language=en-us"],
197
+ [ "awaitCodeRedirect", "$L1", "$L0"],
198
+ [ "string.concat", "$L2", "redirect_uri=", "$P0.redirectUri", "&code=", "$L1", "&grant_type=authorization_code"],
199
+ [ "jumpRel", 1],
200
+ [ "string.concat", "$L2", "redirect_uri=", "$P0.redirectUri", "&refresh_token=", "$S0.refreshToken", "&grant_type=refresh_token"],
201
+ [ "stream.stringToStream", "$L3", "$L2"],
202
+ [ "create", "$L4", "Object"],
203
+ [ "set", "$L4", "application/x-www-form-urlencoded", "Content-Type"],
204
+ [ "string.concat", "$L15", "$P0.clientId", ":", "$P0.clientSecret"],
205
+ [ "string.base64encode", "$L15", "$L15"],
206
+ [ "string.concat", "$L4.Authorization", "Basic ", "$L15"],
207
+ [ "create", "$L5", "Object"],
208
+ [ "set", "$L5.url", "https://api.login.yahoo.com/oauth2/get_token"],
209
+ [ "set", "$L5.method", "POST"],
210
+ [ "set", "$L5.requestBody", "$L3"],
211
+ [ "set", "$L5.requestHeaders", "$L4"],
212
+ [ "http.requestCall", "$L6", "$L5"],
213
+ [ "callFunc", "validateResponse", "$P0", "$L6"],
214
+ [ "create", "$L7", "String"],
215
+ [ "stream.streamToString", "$L7", "$L6.responseBody"],
216
+ [ "json.parse", "$L8", "$L7"],
217
+ [ "set", "$S0.accessToken", "$L8.access_token"],
218
+ [ "set", "$S0.refreshToken", "$L8.refresh_token"],
219
+ [ "create", "$L10", "Date"],
220
+ [ "math.multiply", "$L9", "$L8.expires_in", 1000],
221
+ [ "math.add", "$L9", "$L9", "$L10.time", -60000],
222
+ [ "set", "$S0.expireIn", "$L9"]
223
+
224
+ ],
225
+
226
+ "validateResponse" => [
227
+ [ "if>=than", "$P1.code", 400, 10],
228
+ [ "if==than", "$P1.code", 401, 2],
229
+ [ "create", "$L3", "Error", "Invalid credentials or access rights. Make sure that your application has read and write permission.", "Authentication"],
230
+ [ "throwError", "$L3"],
231
+ [ "if==than", "$P1.code", 503, 2],
232
+ [ "create", "$L3", "Error", "Service unavailable. Try again later.", "ServiceUnavailable"],
233
+ [ "throwError", "$L3"],
234
+ [ "stream.streamToString", "$L0", "$P1.responseBody"],
235
+ [ "string.concat", "$L2", "$P1.code", " - ", "$L0"],
236
+ [ "create", "$L3", "Error", "$L2", "Http"],
237
+ [ "throwError", "$L3"]
238
+
239
+ ]
240
+
241
+ }
242
+
243
+ def initialize(redirect_receiver, client_id, client_secret, redirect_uri, state)
244
+ @interpreter_storage = {}
245
+ @persistent_storage = [{}]
246
+ @instance_dependency_storage = {
247
+ redirect_receiver: redirect_receiver
248
+ }
249
+
250
+ ServiceCode::InitSelfTest.init_test('Yahoo')
251
+
252
+ @interpreter_storage['clientId'] = client_id
253
+ @interpreter_storage['clientSecret'] = client_secret
254
+ @interpreter_storage['redirectUri'] = redirect_uri
255
+ @interpreter_storage['state'] = state
256
+
257
+
258
+
259
+
260
+ # call init servicecode function
261
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
262
+ # check and call the initialization function if is available
263
+
264
+ ip.call_function_sync('init', @interpreter_storage) if (SERVICE_CODE['init'])
265
+ end
266
+
267
+ def check_for_error(error)
268
+ if (error)
269
+ ServiceCode::Statistics.add_error('Yahoo', '')
270
+ case (error.type)
271
+ when 'IllegalArgument'
272
+ raise Errors::IllegalArgumentError.new(error.message)
273
+ when 'Authentication'
274
+ raise Errors::AuthenticationError.new(error.message)
275
+ when 'NotFound'
276
+ raise Errors::NotFoundError.new(error.message)
277
+ when 'Http'
278
+ raise Errors::HttpError.new(error.message)
279
+ when 'ServiceUnavailable'
280
+ raise Errors::ServiceUnavailableError.new(error.message)
281
+ else
282
+ raise Errors::StandardError.new(error.message)
283
+ end
284
+ end
285
+ end
286
+
287
+
288
+ def get_identifier()
289
+ ServiceCode::Statistics.add_call('Yahoo', 'get_identifier')
290
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
291
+ ip.call_function('getYUIdentifier', @interpreter_storage, nil)
292
+
293
+ check_for_error(ip.sandbox.thrown_error)
294
+ return nil || ip.get_parameter(1)
295
+ end
296
+
297
+ def get_full_name()
298
+ ServiceCode::Statistics.add_call('Yahoo', 'get_full_name')
299
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
300
+ ip.call_function('getYUFullName', @interpreter_storage, nil)
301
+
302
+ check_for_error(ip.sandbox.thrown_error)
303
+ return nil || ip.get_parameter(1)
304
+ end
305
+
306
+ def get_email()
307
+ ServiceCode::Statistics.add_call('Yahoo', 'get_email')
308
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
309
+ ip.call_function('getYUEmail', @interpreter_storage, nil)
310
+
311
+ check_for_error(ip.sandbox.thrown_error)
312
+ return nil || ip.get_parameter(1)
313
+ end
314
+
315
+ def get_gender()
316
+ ServiceCode::Statistics.add_call('Yahoo', 'get_gender')
317
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
318
+ ip.call_function('getYUGender', @interpreter_storage, nil)
319
+
320
+ check_for_error(ip.sandbox.thrown_error)
321
+ return nil || ip.get_parameter(1)
322
+ end
323
+
324
+ def get_description()
325
+ ServiceCode::Statistics.add_call('Yahoo', 'get_description')
326
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
327
+ ip.call_function('getYUDescription', @interpreter_storage, nil)
328
+
329
+ check_for_error(ip.sandbox.thrown_error)
330
+ return nil || ip.get_parameter(1)
331
+ end
332
+
333
+ def get_date_of_birth()
334
+ ServiceCode::Statistics.add_call('Yahoo', 'get_date_of_birth')
335
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
336
+ ip.call_function('getYUDateOfBirth', @interpreter_storage, nil)
337
+
338
+ check_for_error(ip.sandbox.thrown_error)
339
+ return nil || ip.get_parameter(1)
340
+ end
341
+
342
+ def get_locale()
343
+ ServiceCode::Statistics.add_call('Yahoo', 'get_locale')
344
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
345
+ ip.call_function('getYULocale', @interpreter_storage, nil)
346
+
347
+ check_for_error(ip.sandbox.thrown_error)
348
+ return nil || ip.get_parameter(1)
349
+ end
350
+
351
+ def get_picture_url()
352
+ ServiceCode::Statistics.add_call('Yahoo', 'get_picture_url')
353
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
354
+ ip.call_function('getYUPictureURL', @interpreter_storage, nil)
355
+
356
+ check_for_error(ip.sandbox.thrown_error)
357
+ return nil || ip.get_parameter(1)
358
+ end
359
+
360
+ def login()
361
+ ServiceCode::Statistics.add_call('Yahoo', 'login')
362
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
363
+ ip.call_function('loginYU', @interpreter_storage)
364
+
365
+ check_for_error(ip.sandbox.thrown_error)
366
+ return nil
367
+ end
368
+
369
+ def logout()
370
+ ServiceCode::Statistics.add_call('Yahoo', 'logout')
371
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
372
+ ip.call_function('logoutYU', @interpreter_storage)
373
+
374
+ check_for_error(ip.sandbox.thrown_error)
375
+ return nil
376
+ end
377
+
378
+ def advanced_request(specification)
379
+ ServiceCode::Statistics.add_call('Yahoo', 'advanced_request')
380
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
381
+ ip.call_function('AdvancedRequestSupporter:advancedRequest', @interpreter_storage, nil, specification)
382
+
383
+ check_for_error(ip.sandbox.thrown_error)
384
+ return nil || ip.get_parameter(1)
385
+ end
386
+
387
+
388
+ def save_as_string
389
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
390
+ return ip.save_as_string()
391
+ end
392
+
393
+ def load_as_string(saved_state)
394
+ sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
395
+ ip = ServiceCode::Interpreter.new(sandbox)
396
+ ip.load_as_string(saved_state)
397
+ @persistent_storage = sandbox.persistent_storage
398
+ end
399
+
400
+ def resume_login(execution_state, callback)
401
+ sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
402
+ sandbox.load_state_from_string(execution_state)
403
+ ip = ServiceCode::Interpreter.new(sandbox)
404
+ ip.resume_function('Authenticating:login', @interpreter_storage, callback)
405
+ end
406
+ end
407
+ end
408
+ end
@@ -0,0 +1,389 @@
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 Yelp
10
+
11
+ SERVICE_CODE = {
12
+
13
+ "init" => [
14
+ [ "create", "$P0.crToYelp", "Object"],
15
+ [ "create", "$P0.yelpToCr", "Object"],
16
+ [ "callFunc", "addCategory", "$P0", "airport", "airports"],
17
+ [ "callFunc", "addCategory", "$P0", "amusement_park", "amusementparks"],
18
+ [ "callFunc", "addCategory", "$P0", "aquarium", "aquariums"],
19
+ [ "callFunc", "addCategory", "$P0", "art_gallery", "galleries"],
20
+ [ "callFunc", "addCategory", "$P0", "bakery", "bakeries"],
21
+ [ "callFunc", "addCategory", "$P0", "bank", "banks"],
22
+ [ "callFunc", "addCategory", "$P0", "bar", "bars"],
23
+ [ "callFunc", "addCategory", "$P0", "beauty_salon", "beautysvc"],
24
+ [ "callFunc", "addCategory", "$P0", "bicycle_store", "bicycles"],
25
+ [ "callFunc", "addCategory", "$P0", "book_store", "bookstores"],
26
+ [ "callFunc", "addCategory", "$P0", "bowling_alley", "bowling"],
27
+ [ "callFunc", "addCategory", "$P0", "bus_station", "buses"],
28
+ [ "callFunc", "addCategory", "$P0", "cafe", "cafes"],
29
+ [ "callFunc", "addCategory", "$P0", "car_dealer", "car_dealers"],
30
+ [ "callFunc", "addCategory", "$P0", "car_rental", "carrental"],
31
+ [ "callFunc", "addCategory", "$P0", "car_wash", "carwash"],
32
+ [ "callFunc", "addCategory", "$P0", "casino", "casinos"],
33
+ [ "callFunc", "addCategory", "$P0", "cemetery", "funeralservices"],
34
+ [ "callFunc", "addCategory", "$P0", "church", "churches"],
35
+ [ "callFunc", "addCategory", "$P0", "clothing_store", "fashion"],
36
+ [ "callFunc", "addCategory", "$P0", "convenience_store", "convenience"],
37
+ [ "callFunc", "addCategory", "$P0", "courthouse", "courthouses"],
38
+ [ "callFunc", "addCategory", "$P0", "dentist", "dentists"],
39
+ [ "callFunc", "addCategory", "$P0", "department_store", "deptstores"],
40
+ [ "callFunc", "addCategory", "$P0", "doctor", "physicians"],
41
+ [ "callFunc", "addCategory", "$P0", "electronics_store", "electronics"],
42
+ [ "callFunc", "addCategory", "$P0", "embassy", "embassy"],
43
+ [ "callFunc", "addCategory", "$P0", "finance", "financialservices"],
44
+ [ "callFunc", "addCategory", "$P0", "fire_station", "firedepartments"],
45
+ [ "callFunc", "addCategory", "$P0", "florist", "florists"],
46
+ [ "callFunc", "addCategory", "$P0", "food", "food"],
47
+ [ "callFunc", "addCategory", "$P0", "funeral_home", "funeralservices"],
48
+ [ "callFunc", "addCategory", "$P0", "furniture_store", "furniture"],
49
+ [ "callFunc", "addCategory", "$P0", "gas_station", "servicestations"],
50
+ [ "callFunc", "addCategory", "$P0", "grocery_or_supermarket", "grocery"],
51
+ [ "callFunc", "addCategory", "$P0", "gym", "gyms"],
52
+ [ "callFunc", "addCategory", "$P0", "hardware_store", "hardware"],
53
+ [ "callFunc", "addCategory", "$P0", "health", "health"],
54
+ [ "callFunc", "addCategory", "$P0", "hindu_temple", "hindu_temples"],
55
+ [ "callFunc", "addCategory", "$P0", "hospital", "hospitals"],
56
+ [ "callFunc", "addCategory", "$P0", "jewelry_store", "jewelry"],
57
+ [ "callFunc", "addCategory", "$P0", "laundry", "drycleaninglaundry"],
58
+ [ "callFunc", "addCategory", "$P0", "lawyer", "lawyers"],
59
+ [ "callFunc", "addCategory", "$P0", "library", "libraries"],
60
+ [ "callFunc", "addCategory", "$P0", "locksmith", "locksmiths"],
61
+ [ "callFunc", "addCategory", "$P0", "mosque", "mosques"],
62
+ [ "callFunc", "addCategory", "$P0", "movie_theater", "movietheaters"],
63
+ [ "callFunc", "addCategory", "$P0", "museum", "museums"],
64
+ [ "callFunc", "addCategory", "$P0", "night_club", "danceclubs"],
65
+ [ "callFunc", "addCategory", "$P0", "parks", "parks"],
66
+ [ "callFunc", "addCategory", "$P0", "parking", "parking"],
67
+ [ "callFunc", "addCategory", "$P0", "pet_store", "petstore"],
68
+ [ "callFunc", "addCategory", "$P0", "pharmacy", "pharmacy"],
69
+ [ "callFunc", "addCategory", "$P0", "physiotherapist", "physicaltherapy"],
70
+ [ "callFunc", "addCategory", "$P0", "police", "policedepartments"],
71
+ [ "callFunc", "addCategory", "$P0", "post_office", "postoffices"],
72
+ [ "callFunc", "addCategory", "$P0", "real_estate_agency", "realestateagents"],
73
+ [ "callFunc", "addCategory", "$P0", "restaurant", "restaurants"],
74
+ [ "callFunc", "addCategory", "$P0", "rv_park", "rvparks"],
75
+ [ "callFunc", "addCategory", "$P0", "school", "education"],
76
+ [ "callFunc", "addCategory", "$P0", "shoe_store", "shoes"],
77
+ [ "callFunc", "addCategory", "$P0", "shopping_mall", "shoppingcenters"],
78
+ [ "callFunc", "addCategory", "$P0", "spa", "spas"],
79
+ [ "callFunc", "addCategory", "$P0", "stadium", "stadiumsarenas"],
80
+ [ "callFunc", "addCategory", "$P0", "synagogue", "synagogues"],
81
+ [ "callFunc", "addCategory", "$P0", "taxi_stand", "taxis"],
82
+ [ "callFunc", "addCategory", "$P0", "train_station", "trainstations"],
83
+ [ "callFunc", "addCategory", "$P0", "travel_agency", "travelagents"],
84
+ [ "callFunc", "addCategory", "$P0", "university", "collegeuniv"],
85
+ [ "callFunc", "addCategory", "$P0", "veterinary_care", "vet"],
86
+ [ "callFunc", "addCategory", "$P0", "zoo", "zoos"]
87
+
88
+ ],
89
+
90
+ "getNearbyPOIs" => [
91
+ [ "callFunc", "checkNull", "$P0", "$P2", "Latitude"],
92
+ [ "callFunc", "checkNull", "$P0", "$P3", "Longitude"],
93
+ [ "callFunc", "checkNull", "$P0", "$P4", "Radius"],
94
+ [ "callFunc", "checkLessThan", "$P0", "$P2", -90, "Latitude"],
95
+ [ "callFunc", "checkLessThan", "$P0", "$P3", -180, "Longitude"],
96
+ [ "callFunc", "checkLessThan", "$P0", "$P4", 0, "Radius"],
97
+ [ "callFunc", "checkGreaterThan", "$P0", "$P2", 90, "Latitude"],
98
+ [ "callFunc", "checkGreaterThan", "$P0", "$P3", 180, "Longitude"],
99
+ [ "callFunc", "checkGreaterThan", "$P0", "$P4", 40000, "Radius"],
100
+ [ "if!=than", "$P6", nil, 1],
101
+ [ "callFunc", "checkIsEmpty", "$P0", "$P6", "Categories"],
102
+ [ "create", "$L0", "Object"],
103
+ [ "set", "$L0.method", "GET"],
104
+ [ "set", "$L0.url", "https://api.yelp.com/v2/search"],
105
+ [ "create", "$L1", "String", "?"],
106
+ [ "string.concat", "$L1", "$L1", "ll=", "$P2", "%2C", "$P3"],
107
+ [ "string.concat", "$L1", "$L1", "&radius_filter=", "$P4"],
108
+ [ "if!=than", "$P5", nil, 2],
109
+ [ "string.urlEncode", "$L2", "$P5"],
110
+ [ "string.concat", "$L1", "$L1", "&term=", "$L2"],
111
+ [ "if!=than", "$P6", nil, 3],
112
+ [ "callFunc", "getCategoriesString", "$P0", "$L2", "$P6"],
113
+ [ "string.urlEncode", "$L2", "$L2"],
114
+ [ "string.concat", "$L1", "$L1", "&category_filter=", "$L2"],
115
+ [ "create", "$L2", "Array"],
116
+ [ "if!=than", "$P6", nil, 1],
117
+ [ "push", "$L2", "category_filter"],
118
+ [ "push", "$L2", "ll"],
119
+ [ "push", "$L2", "oauth_consumer_key"],
120
+ [ "push", "$L2", "oauth_nonce"],
121
+ [ "push", "$L2", "oauth_signature_method"],
122
+ [ "push", "$L2", "oauth_timestamp"],
123
+ [ "push", "$L2", "oauth_token"],
124
+ [ "push", "$L2", "oauth_version"],
125
+ [ "push", "$L2", "radius_filter"],
126
+ [ "if!=than", "$P5", nil, 1],
127
+ [ "push", "$L2", "term"],
128
+ [ "create", "$L3", "Object"],
129
+ [ "string.concat", "$L3.ll", "$P2", ",", "$P3"],
130
+ [ "string.concat", "$L3.radius_filter", "$P4", ""],
131
+ [ "if!=than", "$P5", nil, 1],
132
+ [ "set", "$L3.term", "$P5"],
133
+ [ "if!=than", "$P6", nil, 1],
134
+ [ "callFunc", "getCategoriesString", "$P0", "$L3.category_filter", "$P6"],
135
+ [ "callFunc", "oAuth1:signRequest", "$P0", "$L0", "$L2", "$L3"],
136
+ [ "string.concat", "$L0.url", "$L0.url", "$L1"],
137
+ [ "http.requestCall", "$L2", "$L0"],
138
+ [ "callFunc", "checkHttpResponse", "$P0", "$L2"],
139
+ [ "json.parse", "$L3", "$L2.responseBody"],
140
+ [ "create", "$P1", "Array"],
141
+ [ "create", "$L4", "Number", 0],
142
+ [ "size", "$L5", "$L3.businesses"],
143
+ [ "if<than", "$L4", "$L5", 5],
144
+ [ "get", "$L6", "$L3.businesses", "$L4"],
145
+ [ "callFunc", "extractBusiness", "$P0", "$L7", "$L6"],
146
+ [ "push", "$P1", "$L7"],
147
+ [ "math.add", "$L4", "$L4", 1],
148
+ [ "jumpRel", -6]
149
+
150
+ ],
151
+
152
+ "checkNull" => [
153
+ [ "if==than", "$P1", nil, 3],
154
+ [ "string.concat", "$L0", "$P2", " is not allowed to be null."],
155
+ [ "create", "$L1", "Error", "$L0", "IllegalArgument"],
156
+ [ "throwError", "$L1"]
157
+
158
+ ],
159
+
160
+ "checkLessThan" => [
161
+ [ "if<than", "$P1", "$P2", 3],
162
+ [ "string.concat", "$L0", "$P3", " is not allowed to be less than ", "$P2", "."],
163
+ [ "create", "$L1", "Error", "$L0", "IllegalArgument"],
164
+ [ "throwError", "$L1"]
165
+
166
+ ],
167
+
168
+ "checkGreaterThan" => [
169
+ [ "if>than", "$P1", "$P2", 3],
170
+ [ "string.concat", "$L0", "$P3", " is not allowed to be greater than ", "$P2", "."],
171
+ [ "create", "$L1", "Error", "$L0", "IllegalArgument"],
172
+ [ "throwError", "$L1"]
173
+
174
+ ],
175
+
176
+ "checkIsEmpty" => [
177
+ [ "size", "$L0", "$P2"],
178
+ [ "if==than", "$L0", 0, 3],
179
+ [ "string.concat", "$L0", "$P3", " is not allowed to be empty."],
180
+ [ "create", "$L1", "Error", "$L0", "IllegalArgument"],
181
+ [ "throwError", "$L1"]
182
+
183
+ ],
184
+
185
+ "oAuth1:signRequest" => [
186
+ [ "if==than", "$P1.requestHeaders", nil, 1],
187
+ [ "create", "$P1.requestHeaders", "Object"],
188
+ [ "create", "$L0", "Object"],
189
+ [ "set", "$L0.oauth_consumer_key", "$P0.consumerKey"],
190
+ [ "callFunc", "oAuth1:generateNonce", "$L0.oauth_nonce"],
191
+ [ "set", "$L0.oauth_signature_method", "HMAC-SHA1"],
192
+ [ "create", "$L1", "Date"],
193
+ [ "math.multiply", "$L1", "$L1.Time", 0.001],
194
+ [ "math.floor", "$L1", "$L1"],
195
+ [ "string.format", "$L0.oauth_timestamp", "%d", "$L1"],
196
+ [ "set", "$L0.oauth_token", "$P0.token"],
197
+ [ "set", "$L0.oauth_version", "1.0"],
198
+ [ "string.urlEncode", "$L2", "$P1.url"],
199
+ [ "string.concat", "$L1", "$P1.method", "&", "$L2", "&"],
200
+ [ "set", "$L2", ""],
201
+ [ "set", "$L3", 0],
202
+ [ "size", "$L4", "$P2"],
203
+ [ "if<than", "$L3", "$L4", 12],
204
+ [ "get", "$L5", "$P2", "$L3"],
205
+ [ "if==than", "$L5", "oauth_callback", 1],
206
+ [ "set", "$L0.oauth_callback", "$P0.redirectUri"],
207
+ [ "get", "$L6", "$L0", "$L5"],
208
+ [ "if>than", "$L3", 0, 1],
209
+ [ "string.concat", "$L2", "$L2", "&"],
210
+ [ "if==than", "$L6", nil, 1],
211
+ [ "get", "$L6", "$P3", "$L5"],
212
+ [ "string.urlEncode", "$L6", "$L6"],
213
+ [ "string.concat", "$L2", "$L2", "$L5", "=", "$L6"],
214
+ [ "math.add", "$L3", "$L3", 1],
215
+ [ "jumpRel", -13],
216
+ [ "string.urlEncode", "$L2", "$L2"],
217
+ [ "string.concat", "$L1", "$L1", "$L2"],
218
+ [ "set", "$L2", "$P0.tokenSecret"],
219
+ [ "string.concat", "$L2", "$P0.consumerSecret", "&", "$L2"],
220
+ [ "crypt.hmac.sha1", "$L2", "$L2", "$L1"],
221
+ [ "array.uint8ToBase64", "$L2", "$L2"],
222
+ [ "string.urlEncode", "$L2", "$L2"],
223
+ [ "set", "$L0.oauth_signature", "$L2"],
224
+ [ "set", "$L2", "OAuth "],
225
+ [ "if!=than", "$L0.oauth_callback", nil, 2],
226
+ [ "string.urlEncode", "$L3", "$L0.oauth_callback"],
227
+ [ "string.concat", "$L2", "$L2", "oauth_callback", "=\"", "$L3", "\"", ", "],
228
+ [ "string.concat", "$L2", "$L2", "oauth_consumer_key", "=\"", "$L0.oauth_consumer_key", "\""],
229
+ [ "string.concat", "$L2", "$L2", ", ", "oauth_nonce", "=\"", "$L0.oauth_nonce", "\""],
230
+ [ "string.concat", "$L2", "$L2", ", ", "oauth_signature", "=\"", "$L0.oauth_signature", "\""],
231
+ [ "string.concat", "$L2", "$L2", ", ", "oauth_signature_method", "=\"", "$L0.oauth_signature_method", "\""],
232
+ [ "string.concat", "$L2", "$L2", ", ", "oauth_timestamp", "=\"", "$L0.oauth_timestamp", "\""],
233
+ [ "if!=than", "$L0.oauth_token", nil, 1],
234
+ [ "string.concat", "$L2", "$L2", ", ", "oauth_token", "=\"", "$L0.oauth_token", "\""],
235
+ [ "string.concat", "$L2", "$L2", ", ", "oauth_version", "=\"", "$L0.oauth_version", "\""],
236
+ [ "set", "$P1.requestHeaders.Authorization", "$L2"]
237
+
238
+ ],
239
+
240
+ "oAuth1:generateNonce" => [
241
+ [ "create", "$L0", "Date"],
242
+ [ "string.format", "$L0", "%d", "$L0.Time"],
243
+ [ "hash.md5", "$L0", "$L0"],
244
+ [ "size", "$L1", "$L0"],
245
+ [ "set", "$L2", 0],
246
+ [ "set", "$P0", ""],
247
+ [ "get", "$L3", "$L0", "$L2"],
248
+ [ "string.format", "$L4", "%02x", "$L3"],
249
+ [ "string.concat", "$P0", "$P0", "$L4"],
250
+ [ "math.add", "$L2", "$L2", 1],
251
+ [ "if>=than", "$L2", "$L1", -5]
252
+
253
+ ],
254
+
255
+ "checkHttpResponse" => [
256
+ [ "if>=than", "$P1.code", 400, 9],
257
+ [ "if==than", "$P2.code", 401, 2],
258
+ [ "create", "$L3", "Error", "Invalid credentials or access rights. Make sure that your application has read and write permission.", "Authentication"],
259
+ [ "throwError", "$L3"],
260
+ [ "if==than", "$P2.code", 503, 2],
261
+ [ "create", "$L3", "Error", "Service unavailable. Try again later.", "ServiceUnavailable"],
262
+ [ "throwError", "$L3"],
263
+ [ "json.parse", "$L0", "$P1.responseBody"],
264
+ [ "create", "$L1", "Error", "$L0.error.description", "Http"],
265
+ [ "throwError", "$L1"]
266
+
267
+ ],
268
+
269
+ "getCategoriesString" => [
270
+ [ "create", "$P1", "String"],
271
+ [ "create", "$L0", "Number", 0],
272
+ [ "size", "$L1", "$P2"],
273
+ [ "if<than", "$L0", "$L1", 10],
274
+ [ "get", "$L2", "$P2", "$L0"],
275
+ [ "get", "$L2", "$P0.crToYelp", "$L2"],
276
+ [ "if==than", "$L2", nil, 2],
277
+ [ "create", "$L3", "Error", "Unknown category.", "IllegalArgument"],
278
+ [ "throwError", "$L3"],
279
+ [ "if!=than", "$L0", 0, 1],
280
+ [ "string.concat", "$P1", "$P1", ","],
281
+ [ "string.concat", "$P1", "$P1", "$L2"],
282
+ [ "math.add", "$L0", "$L0", 1],
283
+ [ "jumpRel", -11]
284
+
285
+ ],
286
+
287
+ "extractBusiness" => [
288
+ [ "create", "$L0", "Location"],
289
+ [ "set", "$L0.latitude", "$P2.location.coordinate.latitude"],
290
+ [ "set", "$L0.longitude", "$P2.location.coordinate.longitude"],
291
+ [ "create", "$L1", "Array"],
292
+ [ "create", "$L2", "Number", 0],
293
+ [ "size", "$L3", "$P2.categories"],
294
+ [ "if<than", "$L2", "$L3", 7],
295
+ [ "get", "$L4", "$P2.categories", "$L2"],
296
+ [ "get", "$L5", "$L4", 1],
297
+ [ "get", "$L6", "$P0.yelpToCr", "$L5"],
298
+ [ "if!=than", "$L6", nil, 1],
299
+ [ "push", "$L1", "$L6"],
300
+ [ "math.add", "$L2", "$L2", 1],
301
+ [ "jumpRel", -8],
302
+ [ "create", "$P1", "POI", "$L1", "$P2.image_url", "$L0", "$P2.name", "$P2.phone"]
303
+
304
+ ],
305
+
306
+ "addCategory" => [
307
+ [ "set", "$P0.crToYelp", "$P2", "$P1"],
308
+ [ "set", "$P0.yelpToCr", "$P1", "$P2"]
309
+
310
+ ]
311
+
312
+ }
313
+
314
+ def initialize(redirect_receiver, consumer_key, consumer_secret, token, token_secret)
315
+ @interpreter_storage = {}
316
+ @persistent_storage = [{}]
317
+ @instance_dependency_storage = {
318
+ redirect_receiver: redirect_receiver
319
+ }
320
+
321
+ ServiceCode::InitSelfTest.init_test('Yelp')
322
+
323
+ @interpreter_storage['consumerKey'] = consumer_key
324
+ @interpreter_storage['consumerSecret'] = consumer_secret
325
+ @interpreter_storage['token'] = token
326
+ @interpreter_storage['tokenSecret'] = token_secret
327
+
328
+
329
+
330
+
331
+ # call init servicecode function
332
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
333
+ # check and call the initialization function if is available
334
+
335
+ ip.call_function_sync('init', @interpreter_storage) if (SERVICE_CODE['init'])
336
+ end
337
+
338
+ def check_for_error(error)
339
+ if (error)
340
+ ServiceCode::Statistics.add_error('Yelp', '')
341
+ case (error.type)
342
+ when 'IllegalArgument'
343
+ raise Errors::IllegalArgumentError.new(error.message)
344
+ when 'Authentication'
345
+ raise Errors::AuthenticationError.new(error.message)
346
+ when 'NotFound'
347
+ raise Errors::NotFoundError.new(error.message)
348
+ when 'Http'
349
+ raise Errors::HttpError.new(error.message)
350
+ when 'ServiceUnavailable'
351
+ raise Errors::ServiceUnavailableError.new(error.message)
352
+ else
353
+ raise Errors::StandardError.new(error.message)
354
+ end
355
+ end
356
+ end
357
+
358
+
359
+ def get_nearby_pois(latitude, longitude, radius, search_term, categories)
360
+ ServiceCode::Statistics.add_call('Yelp', 'get_nearby_pois')
361
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
362
+ ip.call_function('getNearbyPOIs', @interpreter_storage, nil, latitude, longitude, radius, search_term, categories)
363
+
364
+ check_for_error(ip.sandbox.thrown_error)
365
+ return nil || ip.get_parameter(1)
366
+ end
367
+
368
+
369
+ def save_as_string
370
+ ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage))
371
+ return ip.save_as_string()
372
+ end
373
+
374
+ def load_as_string(saved_state)
375
+ sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
376
+ ip = ServiceCode::Interpreter.new(sandbox)
377
+ ip.load_as_string(saved_state)
378
+ @persistent_storage = sandbox.persistent_storage
379
+ end
380
+
381
+ def resume_login(execution_state, callback)
382
+ sandbox = ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)
383
+ sandbox.load_state_from_string(execution_state)
384
+ ip = ServiceCode::Interpreter.new(sandbox)
385
+ ip.resume_function('Authenticating:login', @interpreter_storage, callback)
386
+ end
387
+ end
388
+ end
389
+ end