Class: CloudRailSi::Services::GooglePlus
- Inherits:
-
Object
- Object
- CloudRailSi::Services::GooglePlus
- Defined in:
- lib/cloudrail_si/services/GooglePlus.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://www.googleapis.com/plus/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"] ], "Authenticating:login" => [ [ "callFunc", "checkAuthentication", "$P0"] ], "Authenticating:logout" => [ [ "create", "$L0", "Object"], [ "string.concat", "$L0.url", "https://accounts.google.com/o/oauth2/revoke?token=", "$S0.accessToken"], [ "set", "$L0.method", "GET"], [ "http.requestCall", "$L1", "$L0"], [ "callFunc", "validateResponse", "$P0", "$L1"], [ "set", "$S0.accessToken", nil], [ "set", "$P0.userInfo", nil] ], "Profile:getIdentifier" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "string.concat", "$P1", "googleplus-", "$P0.userInfo.id"] ], "Profile:getFullName" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.displayName", nil, 1], [ "set", "$P1", "$P0.userInfo.displayName"] ], "Profile:getEmail" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "get", "$P1", "$P0.userInfo.emails", 0, "value"] ], "Profile:getGender" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.gender", nil, 1], [ "set", "$P1", "$P0.userInfo.gender"] ], "Profile:getDescription" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.aboutMe", nil, 1], [ "set", "$P1", "$P0.userInfo.aboutMe"] ], "Profile:getDateOfBirth" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "create", "$P1", "DateOfBirth"], [ "if!=than", "$P0.userInfo.birthday", nil, 10], [ "string.split", "$L0", "$P0.userInfo.birthday", "-"], [ "get", "$L1", "$L0", 0], [ "if!=than", "$L1", "0000", 1], [ "math.add", "$P1.year", "$L1", 0], [ "get", "$L1", "$L0", 1], [ "if!=than", "$L1", "00", 1], [ "math.add", "$P1.month", "$L1", 0], [ "get", "$L1", "$L0", 2], [ "if!=than", "$L1", "00", 1], [ "math.add", "$P1.day", "$L1", 0] ], "Profile:getLocale" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.language", nil, 1], [ "set", "$P1", "$P0.userInfo.language"] ], "Profile:getPictureURL" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.image.url", nil, 1], [ "set", "$P1", "$P0.userInfo.image.url"] ], "checkUserInfo" => [ [ "create", "$L0", "Date"], [ "if!=than", "$P0.userInfo", nil, 2], [ "if>than", "$P0.expirationTime", "$L0", 1], [ "return"], [ "callFunc", "checkAuthentication", "$P0"], [ "create", "$L2", "Object"], [ "set", "$L2.url", "https://www.googleapis.com/plus/v1/people/me"], [ "create", "$L2.requestHeaders", "Object"], [ "string.concat", "$L2.requestHeaders.Authorization", "Bearer ", "$S0.accessToken"], [ "set", "$L2.method", "GET"], [ "http.requestCall", "$L3", "$L2"], [ "callFunc", "validateResponse", "$P0", "$L3"], [ "json.parse", "$P0.userInfo", "$L3.responseBody"], [ "create", "$P0.expirationTime", "Date"], [ "math.add", "$P0.expirationTime.time", "$P0.expirationTime.time", 60000] ], "checkAuthentication" => [ [ "create", "$L0", "Date"], [ "if==than", "$S0.accessToken", nil, 2], [ "callFunc", "authenticate", "$P0", "accessToken"], [ "return"], [ "create", "$L1", "Date"], [ "set", "$L1.time", "$S0.expireIn"], [ "if<than", "$L1", "$L0", 1], [ "callFunc", "authenticate", "$P0", "refreshToken"] ], "authenticate" => [ [ "create", "$L2", "String"], [ "if==than", "$P1", "accessToken", 4], [ "string.concat", "$L0", "https://accounts.google.com/o/oauth2/v2/auth?client_id=", "$P0.clientID", "&scope=", "https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.me+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile", "&response_type=code&prompt=consent&access_type=offline&redirect_uri=", "$P0.redirectUri", "&state=", "$P0.state", "&suppress_webview_warning=true"], [ "awaitCodeRedirect", "$L1", "$L0"], [ "string.concat", "$L2", "client_id=", "$P0.clientID", "&redirect_uri=", "$P0.redirectUri", "&client_secret=", "$P0.clientSecret", "&code=", "$L1", "&grant_type=authorization_code"], [ "jumpRel", 1], [ "string.concat", "$L2", "client_id=", "$P0.clientID", "&redirect_uri=", "$P0.redirectUri", "&client_secret=", "$P0.clientSecret", "&refresh_token=", "$S0.refreshToken", "&grant_type=refresh_token"], [ "stream.stringToStream", "$L3", "$L2"], [ "create", "$L4", "Object"], [ "set", "$L4", "application/x-www-form-urlencoded", "Content-Type"], [ "create", "$L5", "Object"], [ "set", "$L5.url", "https://www.googleapis.com/oauth2/v4/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"], [ "if!=than", "$L8.refresh_token", nil, 1], [ "set", "$S0.refreshToken", "$L8.refresh_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, 19], [ "stream.streamToString", "$L2", "$P1.responseBody"], [ "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"] ] }
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) ⇒ GooglePlus
constructor
A new instance of GooglePlus.
- #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) ⇒ GooglePlus
Returns a new instance of GooglePlus.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 202 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('GooglePlus') @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
337 338 339 340 341 342 343 344 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 337 def advanced_request(specification) ServiceCode::Statistics.add_call('GooglePlus', '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
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 226 def check_for_error(error) if (error) ServiceCode::Statistics.add_error('GooglePlus', '') 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
292 293 294 295 296 297 298 299 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 292 def get_date_of_birth() ServiceCode::Statistics.add_call('GooglePlus', '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
283 284 285 286 287 288 289 290 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 283 def get_description() ServiceCode::Statistics.add_call('GooglePlus', '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
265 266 267 268 269 270 271 272 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 265 def get_email() ServiceCode::Statistics.add_call('GooglePlus', '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
256 257 258 259 260 261 262 263 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 256 def get_full_name() ServiceCode::Statistics.add_call('GooglePlus', '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
274 275 276 277 278 279 280 281 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 274 def get_gender() ServiceCode::Statistics.add_call('GooglePlus', '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
247 248 249 250 251 252 253 254 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 247 def get_identifier() ServiceCode::Statistics.add_call('GooglePlus', '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
301 302 303 304 305 306 307 308 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 301 def get_locale() ServiceCode::Statistics.add_call('GooglePlus', '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
310 311 312 313 314 315 316 317 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 310 def get_picture_url() ServiceCode::Statistics.add_call('GooglePlus', '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
352 353 354 355 356 357 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 352 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
319 320 321 322 323 324 325 326 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 319 def login() ServiceCode::Statistics.add_call('GooglePlus', '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
328 329 330 331 332 333 334 335 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 328 def logout() ServiceCode::Statistics.add_call('GooglePlus', '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
359 360 361 362 363 364 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 359 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
347 348 349 350 |
# File 'lib/cloudrail_si/services/GooglePlus.rb', line 347 def save_as_string ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) return ip.save_as_string() end |