Class: Geni::Client
- Inherits:
-
Object
- Object
- Geni::Client
- Defined in:
- lib/geni/client.rb
Constant Summary collapse
- SITE =
'https://www.geni.com'
- ACCESS_TOKEN_PATH =
'/oauth/token'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#oauth_client ⇒ Object
readonly
Returns the value of attribute oauth_client.
Instance Method Summary collapse
- #authorize_url(request) ⇒ Object
- #get_profile(id_or_ids = nil) ⇒ Object
- #get_token(code, request) ⇒ Object
-
#initialize(params = {}) ⇒ Client
constructor
A new instance of Client.
- #redirect_uri(request) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 |
# File 'lib/geni/client.rb', line 9 def initialize(params = {}) @oauth_client = OAuth2::Client.new(params[:app_id], params[:app_secret], :site => SITE, :parse_json => true, :access_token_path => ACCESS_TOKEN_PATH ) @access_token = OAuth2::AccessToken.new(oauth_client, params[:token]) end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/geni/client.rb', line 7 def access_token @access_token end |
#oauth_client ⇒ Object (readonly)
Returns the value of attribute oauth_client.
7 8 9 |
# File 'lib/geni/client.rb', line 7 def oauth_client @oauth_client end |
Instance Method Details
#authorize_url(request) ⇒ Object
52 53 54 55 56 |
# File 'lib/geni/client.rb', line 52 def (request) oauth_client.web_server.({ :redirect_uri => redirect_uri(request) }) end |
#get_profile(id_or_ids = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/geni/client.rb', line 19 def get_profile(id_or_ids = nil) if id_or_ids.nil? url = "/api/profile" elsif id_or_ids.kind_of?(Array) if id_or_ids.any? url = "/api/profile-#{id_or_ids.join(',')}" else return [] end else url = "/api/profile-#{id_or_ids}" end results = access_token.get(url) results = results['results'] if results.has_key?('results') profiles = [results].flatten.collect do |profile_attrs| Geni::Profile.new({ :client => self, :attrs => profile_attrs }) end id_or_ids.kind_of?(Array) ? profiles : profiles.first end |
#get_token(code, request) ⇒ Object
58 59 60 61 62 |
# File 'lib/geni/client.rb', line 58 def get_token(code, request) oauth_client.web_server.get_access_token(code, { :redirect_uri => redirect_uri(request) }).token end |
#redirect_uri(request) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/geni/client.rb', line 45 def redirect_uri(request) uri = URI.parse(request.url) uri.path = '/callback' uri.query = nil uri.to_s end |