Class: CloudRailSi::Services::MicrosoftLive
- Inherits:
-
Object
- Object
- CloudRailSi::Services::MicrosoftLive
- Defined in:
- lib/cloudrail_si/services/MicrosoftLive.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://apis.live.net/v5.0"], [ "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], [ "set", "$P0.userInfo", nil] ], "Profile:getIdentifier" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "string.concat", "$P1", "microsoftlive-", "$P0.userInfo.id"] ], "Profile:getFullName" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.name", nil, 1], [ "set", "$P1", "$P0.userInfo.name"] ], "Profile:getEmail" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "set", "$P1", "$P0.userInfo.emails.account"] ], "Profile:getGender" => [ ], "Profile:getDescription" => [ ], "Profile:getDateOfBirth" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "create", "$P1", "DateOfBirth"], [ "if!=than", "$P0.userInfo.birth_day", nil, 1], [ "set", "$P1.day", "$P0.userInfo.birth_day"], [ "if!=than", "$P0.userInfo.birth_month", nil, 1], [ "set", "$P1.month", "$P0.userInfo.birth_month"], [ "if!=than", "$P0.userInfo.birth_year", nil, 1], [ "set", "$P1.year", "$P0.userInfo.birth_year"] ], "Profile:getLocale" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "if!=than", "$P0.userInfo.locale", nil, 1], [ "string.substring", "$P1", "$P0.userInfo.locale", 0, 2] ], "Profile:getPictureURL" => [ [ "callFunc", "checkUserInfo", "$P0"], [ "string.concat", "$P1", "https://apis.live.net/v5.0/", "$P0.userInfo.id", "/picture"] ], "checkUserInfo" => [ [ "create", "$L0", "Date"], [ "if!=than", "$P0.userInfo", nil, 2], [ "if>than", "$P0.expirationTime", "$L0", 1], [ "return"], [ "callFunc", "checkAuthentication", "$P0"], [ "create", "$L2", "Object"], [ "string.concat", "$L2.url", "https://apis.live.net/v5.0/me?access_token=", "$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://login.live.com/oauth20_authorize.srf?client_id=", "$P0.clientID", "&scope=", "wl.emails%20wl.birthday", "&response_type=code&redirect_uri=", "$P0.redirectUri"], [ "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"], [ "size", "$L19", "$L2"], [ "string.concat", "$L4.Content-Length", "$L19"], [ "create", "$L5", "Object"], [ "set", "$L5.url", "https://login.live.com/oauth20_token.srf"], [ "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"], [ "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, 12], [ "if==than", "$P1.code", 401, 2], [ "create", "$L3", "Error", "Invalid credentials or access rights. Make sure that your application has read and write permission.", "Authentication"], [ "throwError", "$L3"], [ "if==than", "$P1.code", 503, 2], [ "create", "$L3", "Error", "Service unavailable. Try again later.", "ServiceUnavailable"], [ "throwError", "$L3"], [ "json.parse", "$L0", "$P1.responseBody"], [ "set", "$L1", "$L0.error"], [ "set", "$L2", "$L1.message"], [ "string.concat", "$L2", "$P1.code", " - ", "$L2"], [ "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) ⇒ MicrosoftLive
constructor
A new instance of MicrosoftLive.
- #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) ⇒ MicrosoftLive
Returns a new instance of MicrosoftLive.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 181 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('MicrosoftLive') @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
316 317 318 319 320 321 322 323 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 316 def advanced_request(specification) ServiceCode::Statistics.add_call('MicrosoftLive', '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
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 205 def check_for_error(error) if (error) ServiceCode::Statistics.add_error('MicrosoftLive', '') 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
271 272 273 274 275 276 277 278 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 271 def get_date_of_birth() ServiceCode::Statistics.add_call('MicrosoftLive', '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
262 263 264 265 266 267 268 269 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 262 def get_description() ServiceCode::Statistics.add_call('MicrosoftLive', '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
244 245 246 247 248 249 250 251 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 244 def get_email() ServiceCode::Statistics.add_call('MicrosoftLive', '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
235 236 237 238 239 240 241 242 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 235 def get_full_name() ServiceCode::Statistics.add_call('MicrosoftLive', '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
253 254 255 256 257 258 259 260 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 253 def get_gender() ServiceCode::Statistics.add_call('MicrosoftLive', '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
226 227 228 229 230 231 232 233 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 226 def get_identifier() ServiceCode::Statistics.add_call('MicrosoftLive', '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
280 281 282 283 284 285 286 287 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 280 def get_locale() ServiceCode::Statistics.add_call('MicrosoftLive', '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
289 290 291 292 293 294 295 296 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 289 def get_picture_url() ServiceCode::Statistics.add_call('MicrosoftLive', '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
331 332 333 334 335 336 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 331 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
298 299 300 301 302 303 304 305 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 298 def login() ServiceCode::Statistics.add_call('MicrosoftLive', '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
307 308 309 310 311 312 313 314 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 307 def logout() ServiceCode::Statistics.add_call('MicrosoftLive', '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
338 339 340 341 342 343 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 338 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
326 327 328 329 |
# File 'lib/cloudrail_si/services/MicrosoftLive.rb', line 326 def save_as_string ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) return ip.save_as_string() end |