Class: CloudRailSi::Services::GitHub
- Inherits:
-
Object
- Object
- CloudRailSi::Services::GitHub
- Defined in:
- lib/cloudrail_si/services/GitHub.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.github.com"], [ "string.concat", "$L0.url", "$L0.url", "$P2.url"], [ "set", "$L0.requestHeaders", "$P2.headers"], [ "if==than", "$L0.requestHeaders.User-Agent", nil, 1], [ "set", "$L0.requestHeaders.User-Agent", "CloudRailSI"], [ "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"] ], "getGHIdentifier" => [ [ "callFunc", "checkAuthentication", "$P0"], [ "if==than", "$P0.cachedObject", nil, 2], [ "callFunc", "makeHTTPRequest", "$P0"], [ "jumpRel", 1], [ "callFunc", "checkExpirationTime", "$P0"], [ "string.concat", "$L2", "$P0.cachedObject.id", ""], [ "string.concat", "$P1", "github-", "$L2"] ], "getGHFullName" => [ [ "callFunc", "checkAuthentication", "$P0"], [ "if==than", "$P0.cachedObject", nil, 2], [ "callFunc", "makeHTTPRequest", "$P0"], [ "jumpRel", 1], [ "callFunc", "checkExpirationTime", "$P0"], [ "set", "$P1", "$P0.cachedObject.name"] ], "getGHEmail" => [ [ "callFunc", "checkAuthentication", "$P0"], [ "if==than", "$P0.cachedObject", nil, 2], [ "callFunc", "makeHTTPRequest", "$P0"], [ "jumpRel", 1], [ "callFunc", "checkExpirationTime", "$P0"], [ "set", "$P1", "$P0.cachedObject.email"] ], "getGHGender" => [ [ "set", "$P1", nil] ], "getGHDescription" => [ [ "callFunc", "checkAuthentication", "$P0"], [ "if==than", "$P0.cachedObject", nil, 2], [ "callFunc", "makeHTTPRequest", "$P0"], [ "jumpRel", 1], [ "callFunc", "checkExpirationTime", "$P0"], [ "set", "$P1", "$P0.cachedObject.bio"] ], "getGHDateOfBirth" => [ [ "create", "$P1", "DateOfBirth"] ], "getGHLocale" => [ [ "set", "$P1", nil] ], "getGHPictureURL" => [ [ "callFunc", "checkAuthentication", "$P0"], [ "if==than", "$P0.cachedObject", nil, 2], [ "callFunc", "makeHTTPRequest", "$P0"], [ "jumpRel", 1], [ "callFunc", "checkExpirationTime", "$P0"], [ "set", "$P1", "$P0.cachedObject.avatar_url"] ], "loginGH" => [ [ "callFunc", "checkAuthentication", "$P0"] ], "logoutGH" => [ [ "set", "$S0.accessToken", nil], [ "set", "$P0.cachedObject", nil] ], "makeHTTPRequest" => [ [ "create", "$L0", "Object"], [ "set", "$L0.method", "GET"], [ "set", "$L0.url", "https://api.github.com/user"], [ "create", "$L0.requestHeaders", "Object"], [ "string.concat", "$L0.requestHeaders.Authorization", "token ", "$S0.accessToken"], [ "set", "$L0.requestHeaders.User-Agent", "CloudRailSI"], [ "create", "$L1", "Object"], [ "http.requestCall", "$L1", "$L0"], [ "callFunc", "validateResponse", "$P0", "$L1"], [ "json.parse", "$P0.cachedObject", "$L1.responseBody"], [ "create", "$L2", "Date"], [ "set", "$P0.readTime", "$L2.time"] ], "checkExpirationTime" => [ [ "create", "$L0", "Date"], [ "math.multiply", "$L1", "$P0.readTime", -1], [ "math.add", "$L2", "$L0.time", "$L1"], [ "if>than", "$L2", 60000, 1], [ "callFunc", "makeHTTPRequest", "$P0"] ], "checkAuthentication" => [ [ "if==than", "$S0.accessToken", nil, 2], [ "callFunc", "authenticate", "$P0"], [ "return"] ], "authenticate" => [ [ "create", "$L0", "String"], [ "string.concat", "$L0", "https://github.com/login/oauth/authorize?client_id=", "$P0.clientId", "&redirect_uri=", "$P0.redirectUri", "&state=", "$P0.state"], [ "awaitCodeRedirect", "$L1", "$L0"], [ "string.concat", "$L2", "client_id=", "$P0.clientId", "&client_secret=", "$P0.clientSecret", "&code=", "$L1"], [ "stream.stringToStream", "$L3", "$L2"], [ "create", "$L4", "Object"], [ "set", "$L4.Accept", "application/json"], [ "set", "$L4", "application/x-www-form-urlencoded", "Content-Type"], [ "create", "$L5", "Object"], [ "set", "$L5.url", "https://github.com/login/oauth/access_token"], [ "set", "$L5.method", "POST"], [ "set", "$L5.requestBody", "$L3"], [ "set", "$L5.requestHeaders", "$L4"], [ "http.requestCall", "$L6", "$L5"], [ "callFunc", "validateResponse", "$P0", "$L6"], [ "create", "$L7", "String"], [ "stream.streamToString", "$L7", "$L6.responseBody"], [ "json.parse", "$L8", "$L7"], [ "set", "$S0.accessToken", "$L8.access_token"] ], "validateResponse" => [ [ "if>=than", "$P1.code", 400, 13], [ "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", 404, 2], [ "create", "$L3", "Error", "$L2", "NotFound"], [ "throwError", "$L3"], [ "if==than", "$P1.code", 503, 2], [ "create", "$L3", "Error", "$L2", "ServiceUnavailable"], [ "throwError", "$L3"], [ "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) ⇒ GitHub
constructor
A new instance of GitHub.
- #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) ⇒ GitHub
Returns a new instance of GitHub.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 189 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('GitHub') @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
324 325 326 327 328 329 330 331 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 324 def advanced_request(specification) ServiceCode::Statistics.add_call('GitHub', '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
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 213 def check_for_error(error) if (error) ServiceCode::Statistics.add_error('GitHub', '') 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
279 280 281 282 283 284 285 286 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 279 def get_date_of_birth() ServiceCode::Statistics.add_call('GitHub', 'get_date_of_birth') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getGHDateOfBirth', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_description ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 270 def get_description() ServiceCode::Statistics.add_call('GitHub', 'get_description') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getGHDescription', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_email ⇒ Object
252 253 254 255 256 257 258 259 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 252 def get_email() ServiceCode::Statistics.add_call('GitHub', 'get_email') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getGHEmail', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_full_name ⇒ Object
243 244 245 246 247 248 249 250 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 243 def get_full_name() ServiceCode::Statistics.add_call('GitHub', 'get_full_name') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getGHFullName', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_gender ⇒ Object
261 262 263 264 265 266 267 268 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 261 def get_gender() ServiceCode::Statistics.add_call('GitHub', 'get_gender') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getGHGender', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_identifier ⇒ Object
234 235 236 237 238 239 240 241 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 234 def get_identifier() ServiceCode::Statistics.add_call('GitHub', 'get_identifier') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getGHIdentifier', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_locale ⇒ Object
288 289 290 291 292 293 294 295 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 288 def get_locale() ServiceCode::Statistics.add_call('GitHub', 'get_locale') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getGHLocale', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#get_picture_url ⇒ Object
297 298 299 300 301 302 303 304 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 297 def get_picture_url() ServiceCode::Statistics.add_call('GitHub', 'get_picture_url') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('getGHPictureURL', @interpreter_storage, nil) check_for_error(ip.sandbox.thrown_error) return nil || ip.get_parameter(1) end |
#load_as_string(saved_state) ⇒ Object
339 340 341 342 343 344 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 339 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
306 307 308 309 310 311 312 313 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 306 def login() ServiceCode::Statistics.add_call('GitHub', 'login') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('loginGH', @interpreter_storage) check_for_error(ip.sandbox.thrown_error) return nil end |
#logout ⇒ Object
315 316 317 318 319 320 321 322 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 315 def logout() ServiceCode::Statistics.add_call('GitHub', 'logout') ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) ip.call_function('logoutGH', @interpreter_storage) check_for_error(ip.sandbox.thrown_error) return nil end |
#resume_login(execution_state, callback) ⇒ Object
346 347 348 349 350 351 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 346 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
334 335 336 337 |
# File 'lib/cloudrail_si/services/GitHub.rb', line 334 def save_as_string ip = ServiceCode::Interpreter.new(ServiceCode::Sandbox.new(SERVICE_CODE, @persistent_storage, @instance_dependency_storage)) return ip.save_as_string() end |