Class: Auth

Inherits:
ChinoBaseAPI show all
Defined in:
lib/chino_ruby.rb

Instance Method Summary collapse

Methods inherited from ChinoBaseAPI

#delete_resource, #get_resource, #initialize, #parse_response, #patch_resource, #post_resource, #post_resource_with_string_result, #put_resource, #return_uri

Methods inherited from CheckValues

#check_boolean, #check_int, #check_json, #check_string

Constructor Details

This class inherits a constructor from ChinoBaseAPI

Instance Method Details

#login_authentication_code(code, redirect_url, application_id, application_secret) ⇒ Object



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/chino_ruby.rb', line 435

def (code, redirect_url, application_id, application_secret)
    check_string(code)
    check_string(redirect_url)
    check_string(application_id)
    check_string(application_secret)
    uri = return_uri("/auth/token/")
    req = Net::HTTP::Post.new(uri.path)
    req.basic_auth application_id, application_secret
    req.set_form_data([["code", code], ["redirect_uri", redirect_url], ["grant_type", "authorization_code"], ["scope", "read write"], ["client_id", application_id], ["client_secret", application_secret]])
    res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
        http.request(req)
    }
    usr = LoggedUser.new
    usr.from_json((parse_response(res)['data']).to_json)
    usr
end

#login_password(username, password, application_id, application_secret) ⇒ Object



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/chino_ruby.rb', line 418

def (username, password, application_id, application_secret)
    check_string(username)
    check_string(password)
    check_string(application_id)
    check_string(application_secret)
    uri = return_uri("/auth/token/")
    req = Net::HTTP::Post.new(uri.path)
    req.basic_auth application_id, application_secret
    req.set_form_data([["username", username], ["password", password], ["grant_type", "password"]])
    res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
        http.request(req)
    }
    usr = LoggedUser.new
    usr.from_json((parse_response(res)['data']).to_json)
    usr
end

#logout(token, application_id, application_secret) ⇒ Object



468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/chino_ruby.rb', line 468

def logout(token, application_id, application_secret)
    check_string(token)
    check_string(application_id)
    check_string(application_secret)
    uri = return_uri("/auth/revoke_token/")
    req = Net::HTTP::Post.new(uri.path)
    req.basic_auth application_id, application_secret
    req.set_form_data([["token", token], ["client_id", application_id], ["client_secret", application_secret]])
    res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
        http.request(req)
    }
    parse_response(res)['result']
    
end

#refresh_token(refresh_token, application_id, application_secret) ⇒ Object



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/chino_ruby.rb', line 452

def refresh_token(refresh_token, application_id, application_secret)
    check_string(refresh_token)
    check_string(application_id)
    check_string(application_secret)
    uri = return_uri("/auth/token/")
    req = Net::HTTP::Post.new(uri.path)
    req.basic_auth application_id, application_secret
    req.set_form_data([["refresh_token", refresh_token], ["client_id", application_id], ["client_secret", application_secret], ["grant_type", "refresh_token"]])
    res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
        http.request(req)
    }
    usr = LoggedUser.new
    usr.from_json((parse_response(res)['data']).to_json)
    usr
end