Class: CloudRailSi::Services::LinkedIn
- Inherits:
-
Object
- Object
- CloudRailSi::Services::LinkedIn
- Defined in:
- lib/cloudrail_si/services/LinkedIn.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.linkedin.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, 2], [ "callFunc", "checkAuthentication", "$P0"], [ "string.concat", "$L0.requestHeaders.Authorization", "Bearer ", "$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"] ], "getLIIdentifier" => [ [ "callFunc", "checkUserData", "$P0"], [ "string.concat", "$P1", "linkedin-", "$P0.userData.id"] ], "getLIFullName" => [ [ "callFunc", "checkUserData", "$P0"], [ "string.concat", "$P1", "$P0.userData.firstName", " ", "$P0.userData.lastName"] ], "getLIEmail" => [ [ "callFunc", "checkUserData", "$P0"], [ "set", "$P1", "$P0.userData.emailAddress"] ], "getLIGender" => [ ], "getLIDescription" => [ [ "callFunc", "checkUserData", "$P0"], [ "set", "$P1", "$P0.userData.summary"] ], "getLIDateOfBirth" => [ [ "callFunc", "checkUserData", "$P0"], [ "create", "$L0", "DateOfBirth"], [ "if!=than", "$P0.userData.dateOfBirth", nil, 6], [ "if!=than", "$P0.userData.dateOfBirth.day", nil, 1], [ "set", "$L0.day", "$P0.userData.dateOfBirth.day"], [ "if!=than", "$P0.userData.dateOfBirth.month", nil, 1], [ "set", "$L0.month", "$P0.userData.dateOfBirth.month"], [ "if!=than", "$P0.userData.dateOfBirth.year", nil, 1], [ "set", "$L0.year", "$P0.userData.dateOfBirth.year"], [ "set", "$P1", "$L0"] ], "getLILocale" => [ ], "getLIPictureURL" => [ [ "callFunc", "checkUserData", "$P0"], [ "set", "$P1", "$P0.userData.pictureUrl"] ], "loginLI" => [ [ "callFunc", "checkAuthentication", "$P0"] ], "logoutLI" => [ [ "set", "$S0.accessToken", nil], [ "set", "$P0.userData", nil] ], "checkAuthentication" => [ [ "create", "$L0", "Date"], [ "if==than", "$S0.accessToken", nil, 2], [ "callFunc", "authenticate", "$P0"], [ "return"], [ "create", "$L1", "Date"], [ "set", "$L1.time", "$S0.expireIn"], [ "if<than", "$L1", "$L0", 1], [ "callFunc", "authenticate", "$P0"] ], "authenticate" => [ [ "create", "$L0", "String"], [ "create", "$L1", "String"], [ "string.concat", "$L0", "https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=", "$P0.clientID", "&redirect_uri=", "$P0.redirectUri", "&state=", "$P0.state", "&scope=r_basicprofile%20r_emailaddress"], [ "awaitCodeRedirect", "$L2", "$L0"], [ "string.concat", "$L1", "grant_type=authorization_code&code=", "$L2", "&redirect_uri=", "$P0.redirectUri", "&client_id=", "$P0.clientID", "&client_secret=", "$P0.clientSecret"], [ "size", "$L15", "$L1"], [ "string.concat", "$L15", "$L15"], [ "stream.stringToStream", "$L3", "$L1"], [ "create", "$L4", "Object"], [ "set", "$L4", "application/x-www-form-urlencoded", "Content-Type"], [ "set", "$L4.Content-Length", "$L15"], [ "create", "$L5", "Object"], [ "set", "$L5.url", "https://www.linkedin.com/uas/oauth2/accessToken"], [ "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"], [ "create", "$L10", "Date"], [ "math.multiply", "$L9", "$L8.expires_in", 1000], [ "math.add", "$L9", "$L9", "$L10.time", -60000], [ "set", "$S0.expireIn", "$L9"] ], "validateResponse" => [ [ "if>=than", "$P1.code", 400, 20], [ "json.parse", "$L0", "$P1.responseBody"], [ "set", "$L2", "$L0.message"], [ "if==than", "$P1.code", 401, 2], [ "create", "$L3", "Error", "$L2", "Authentication"], [ "throwError", "$L3"], [ "if==than", "$P1.code", 400, 2], [ "create", "$L3", "Error", "$L2", "Http"], [ "throwError", "$L3"], [ "if>=than", "$P1.code", 402, 5], [ "if<=than", "$P1.code", 509, 4], [ "if!=than", "$P1.code", 503, 3], [ "if!=than", "$P1.code", 404, 2], [ "create", "$L3", "Error", "$L2", "Http"], [ "throwError", "$L3"], [ "if==than", "$P1.code", 503, 2], [ "create", "$L3", "Error", "$L2", "ServiceUnavailable"], [ "throwError", "$L3"], [ "if==than", "$P1.code", 404, 2], [ "create", "$L3", "Error", "$L2", "NotFound"], [ "throwError", "$L3"] ], "getUserData" => [ [ "callFunc", "checkAuthentication", "$P0"], [ "create", "$L0", "Object"], [ "set", "$L0.method", "GET"], [ "create", "$L1", "String"], [ "string.concat", "$L1", "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,summary,picture-url)?format=json"], [ "set", "$L0.url", "$L1"], [ "create", "$L0.requestHeaders", "Object"], [ "string.concat", "$L0.requestHeaders.Authorization", "Bearer ", "$S0.accessToken"], [ "create", "$L2", "Object"], [ "http.requestCall", "$L2", "$L0"], [ "callFunc", "validateResponse", "$P0", "$L2"], [ "create", "$L3", "String"], [ "stream.streamToString", "$L3", "$L2.responseBody"], [ "create", "$L4", "Object"], [ "json.parse", "$L4", "$L3"], [ "create", "$L5", "Date"], [ "math.add", "$L6", "$L5.time", 60000], [ "set", "$L4.expirationTime", "$L6"], [ "set", "$P0.userData", "$L4"] ], "checkUserData" => [ [ "create", "$L0", "Date"], [ "if!=than", "$P0.userData", nil, 2], [ "if>=than", "$P0.userData.expirationTime", "$L0.time", 1], [ "return"], [ "callFunc", "getUserData", "$P0"] ] }
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) ⇒ LinkedIn
constructor
A new instance of LinkedIn.
- #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) ⇒ LinkedIn
Returns a new instance of LinkedIn.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 198 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('LinkedIn') @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
333 334 335 336 337 338 339 340 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 333 def advanced_request(specification) ServiceCode::Statistics.add_call('LinkedIn', '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
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 222 def check_for_error(error) if (error) ServiceCode::Statistics.add_error('LinkedIn', '') 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
288 289 290 291 292 293 294 295 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 288 def get_date_of_birth() ServiceCode::Statistics.add_call('LinkedIn', 'get_date_of_birth') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getLIDateOfBirth', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_description ⇒ Object
279 280 281 282 283 284 285 286 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 279 def get_description() ServiceCode::Statistics.add_call('LinkedIn', 'get_description') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getLIDescription', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_email ⇒ Object
261 262 263 264 265 266 267 268 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 261 def get_email() ServiceCode::Statistics.add_call('LinkedIn', 'get_email') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getLIEmail', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_full_name ⇒ Object
252 253 254 255 256 257 258 259 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 252 def get_full_name() ServiceCode::Statistics.add_call('LinkedIn', 'get_full_name') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getLIFullName', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_gender ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 270 def get_gender() ServiceCode::Statistics.add_call('LinkedIn', 'get_gender') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getLIGender', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_identifier ⇒ Object
243 244 245 246 247 248 249 250 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 243 def get_identifier() ServiceCode::Statistics.add_call('LinkedIn', 'get_identifier') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getLIIdentifier', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_locale ⇒ Object
297 298 299 300 301 302 303 304 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 297 def get_locale() ServiceCode::Statistics.add_call('LinkedIn', 'get_locale') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getLILocale', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_picture_url ⇒ Object
306 307 308 309 310 311 312 313 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 306 def get_picture_url() ServiceCode::Statistics.add_call('LinkedIn', 'get_picture_url') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getLIPictureURL', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#load_as_string(saved_state) ⇒ Object
348 349 350 351 352 353 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 348 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
315 316 317 318 319 320 321 322 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 315 def login() ServiceCode::Statistics.add_call('LinkedIn', 'login') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('loginLI', @interpreter_storage) check_for_error(ip.sandbox.thrown_error) return nil end |
#logout ⇒ Object
324 325 326 327 328 329 330 331 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 324 def logout() ServiceCode::Statistics.add_call('LinkedIn', 'logout') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('logoutLI', @interpreter_storage) check_for_error(ip.sandbox.thrown_error) return nil end |
#resume_login(execution_state, callback) ⇒ Object
355 356 357 358 359 360 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 355 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
343 344 345 346 |
# File 'lib/cloudrail_si/services/LinkedIn.rb', line 343 def save_as_string ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) return ip.save_as_string() end |