Class: CloudRailSi::Services::Instagram
- Inherits:
-
Object
- Object
- CloudRailSi::Services::Instagram
- Defined in:
- lib/cloudrail_si/services/Instagram.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://api.instagram.com/v1"], [ "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", "?access_token=", "$S0.accessToken"], [ "jumpRel", 1], [ "string.concat", "$L0.url", "$L0.url", "&access_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] ], "Profile:getIdentifier" => [ [ "callFunc", "updateUserInfo", "$P0"], [ "set", "$P1", "$P0.userInfo.id"] ], "Profile:getFullName" => [ [ "callFunc", "updateUserInfo", "$P0"], [ "set", "$P1", "$P0.userInfo.fullName"] ], "Profile:getPictureURL" => [ [ "callFunc", "updateUserInfo", "$P0"], [ "set", "$P1", "$P0.userInfo.pictureURL"] ], "Profile:getDescription" => [ [ "callFunc", "updateUserInfo", "$P0"], [ "set", "$P1", "$P0.userInfo.description"] ], "Profile:getEmail" => [ [ "set", "$P1", nil] ], "Profile:getGender" => [ [ "set", "$P1", nil] ], "Profile:getDateOfBirth" => [ [ "create", "$P1", "DateOfBirth"] ], "Profile:getLocale" => [ ], "checkAuthentication" => [ [ "if==than", "$S0.accessToken", nil, 1], [ "callFunc", "authenticate", "$P0"] ], "authenticate" => [ [ "create", "$L2", "String"], [ "string.concat", "$L0", "https://api.instagram.com/oauth/authorize/?client_id=", "$P0.clientID", "&response_type=code&redirect_uri=", "$P0.redirectUri", "&state=", "$P0.state"], [ "awaitCodeRedirect", "$L1", "$L0"], [ "string.concat", "$L2", "--------------------------c77df4126e3a1dc1\r\n"], [ "string.concat", "$L2", "$L2", "Content-Disposition: form-data; name=\"client_id\"\r\n\r\n"], [ "string.concat", "$L2", "$L2", "$P0.clientID", "\r\n"], [ "string.concat", "$L2", "$L2", "--------------------------c77df4126e3a1dc1\r\n"], [ "string.concat", "$L2", "$L2", "Content-Disposition: form-data; name=\"client_secret\"\r\n\r\n"], [ "string.concat", "$L2", "$L2", "$P0.clientSecret", "\r\n"], [ "string.concat", "$L2", "$L2", "--------------------------c77df4126e3a1dc1\r\n"], [ "string.concat", "$L2", "$L2", "Content-Disposition: form-data; name=\"grant_type\"\r\n\r\n"], [ "string.concat", "$L2", "$L2", "authorization_code\r\n"], [ "string.concat", "$L2", "$L2", "--------------------------c77df4126e3a1dc1\r\n"], [ "string.concat", "$L2", "$L2", "Content-Disposition: form-data; name=\"redirect_uri\"\r\n\r\n"], [ "string.concat", "$L2", "$L2", "$P0.redirectUri", "\r\n"], [ "string.concat", "$L2", "$L2", "--------------------------c77df4126e3a1dc1\r\n"], [ "string.concat", "$L2", "$L2", "Content-Disposition: form-data; name=\"code\"\r\n\r\n"], [ "string.concat", "$L2", "$L2", "$L1", "\r\n"], [ "string.concat", "$L2", "$L2", "--------------------------c77df4126e3a1dc1--\r\n"], [ "stream.stringToStream", "$L3", "$L2"], [ "create", "$L4", "Object"], [ "set", "$L4", "multipart/form-data; boundary=------------------------c77df4126e3a1dc1", "Content-Type"], [ "size", "$L20", "$L2"], [ "string.concat", "$L4.Content-Length", "$L20"], [ "create", "$L5", "Object"], [ "set", "$L5.url", "https://api.instagram.com/oauth/access_token"], [ "set", "$L5.method", "POST"], [ "set", "$L5.requestBody", "$L3"], [ "set", "$L5.requestHeaders", "$L4"], [ "http.requestCall", "$L6", "$L5"], [ "callFunc", "validateResponse", "$P0", "$L6"], [ "stream.streamToString", "$L7", "$L6.responseBody"], [ "json.parse", "$L8", "$L7"], [ "set", "$S0.accessToken", "$L8.access_token"] ], "parseUser" => [ [ "create", "$L0", "Object"], [ "create", "$L1", "Date"], [ "math.add", "$L0.expires", "$L1.time", 60000], [ "string.concat", "$L0.id", "instagram-", "$P1.id"], [ "set", "$L0.fullName", "$P1.full_name"], [ "set", "$L0.pictureURL", "$P1.profile_picture"], [ "set", "$L0.description", "$P1.bio"], [ "set", "$P0.userInfo", "$L0"] ], "updateUserInfo" => [ [ "callFunc", "checkAuthentication", "$P0"], [ "if!=than", "$P0.userInfo", nil, 3], [ "create", "$L0", "Date"], [ "if<than", "$L0.time", "$P0.userInfo.expires", 1], [ "return"], [ "create", "$L0", "Object"], [ "set", "$L0.method", "GET"], [ "string.concat", "$L0.url", "https://api.instagram.com/v1/users/self/?access_token=", "$S0.accessToken"], [ "http.requestCall", "$L1", "$L0"], [ "callFunc", "validateResponse", "$P0", "$L1"], [ "json.parse", "$L2", "$L1.responseBody"], [ "callFunc", "parseUser", "$P0", "$L2.data"] ], "validateResponse" => [ [ "if>=than", "$P1.code", 400, 6], [ "json.parse", "$L0", "$P1.responseBody"], [ "set", "$L2", "$L0.error_message"], [ "if==than", "$L2", nil, 1], [ "set", "$L2", "$L0.meta.error_message"], [ "create", "$L3", "Error", "$L2", "Http"], [ "throwError", "$L3"] ] }
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) ⇒ Instagram
constructor
A new instance of Instagram.
- #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) ⇒ Instagram
Returns a new instance of Instagram.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 177 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('Instagram') @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
312 313 314 315 316 317 318 319 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 312 def advanced_request(specification) ServiceCode::Statistics.add_call('Instagram', '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
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 201 def check_for_error(error) if (error) ServiceCode::Statistics.add_error('Instagram', '') 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
267 268 269 270 271 272 273 274 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 267 def get_date_of_birth() ServiceCode::Statistics.add_call('Instagram', '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
258 259 260 261 262 263 264 265 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 258 def get_description() ServiceCode::Statistics.add_call('Instagram', '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
240 241 242 243 244 245 246 247 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 240 def get_email() ServiceCode::Statistics.add_call('Instagram', '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
231 232 233 234 235 236 237 238 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 231 def get_full_name() ServiceCode::Statistics.add_call('Instagram', '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
249 250 251 252 253 254 255 256 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 249 def get_gender() ServiceCode::Statistics.add_call('Instagram', '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
222 223 224 225 226 227 228 229 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 222 def get_identifier() ServiceCode::Statistics.add_call('Instagram', '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
276 277 278 279 280 281 282 283 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 276 def get_locale() ServiceCode::Statistics.add_call('Instagram', '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
285 286 287 288 289 290 291 292 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 285 def get_picture_url() ServiceCode::Statistics.add_call('Instagram', '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
327 328 329 330 331 332 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 327 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
294 295 296 297 298 299 300 301 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 294 def login() ServiceCode::Statistics.add_call('Instagram', '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
303 304 305 306 307 308 309 310 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 303 def logout() ServiceCode::Statistics.add_call('Instagram', '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
334 335 336 337 338 339 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 334 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
322 323 324 325 |
# File 'lib/cloudrail_si/services/Instagram.rb', line 322 def save_as_string ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) return ip.save_as_string() end |