Class: Insnergy::Client::Token
- Inherits:
-
Object
- Object
- Insnergy::Client::Token
- Defined in:
- lib/insnergy-api-ruby-client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#oauth_key ⇒ Object
Returns the value of attribute oauth_key.
-
#oauth_secert ⇒ Object
Returns the value of attribute oauth_secert.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
-
#initialize(domain: nil, oauth_key: nil, oauth_secert: nil, refresh_token: nil) ⇒ Token
constructor
A new instance of Token.
- #token! ⇒ Object
- #user_id! ⇒ Object
Constructor Details
#initialize(domain: nil, oauth_key: nil, oauth_secert: nil, refresh_token: nil) ⇒ Token
Returns a new instance of Token.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/insnergy-api-ruby-client.rb', line 10 def initialize(domain: nil, oauth_key: nil, oauth_secert: nil, refresh_token: nil) @domain = domain @oauth_key = oauth_key @oauth_secert = oauth_secert @refresh_token = refresh_token @access_token = nil @user_id = nil token! user_id! end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
8 9 10 |
# File 'lib/insnergy-api-ruby-client.rb', line 8 def access_token @access_token end |
#domain ⇒ Object
Returns the value of attribute domain.
7 8 9 |
# File 'lib/insnergy-api-ruby-client.rb', line 7 def domain @domain end |
#oauth_key ⇒ Object
Returns the value of attribute oauth_key.
7 8 9 |
# File 'lib/insnergy-api-ruby-client.rb', line 7 def oauth_key @oauth_key end |
#oauth_secert ⇒ Object
Returns the value of attribute oauth_secert.
7 8 9 |
# File 'lib/insnergy-api-ruby-client.rb', line 7 def oauth_secert @oauth_secert end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
7 8 9 |
# File 'lib/insnergy-api-ruby-client.rb', line 7 def refresh_token @refresh_token end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
8 9 10 |
# File 'lib/insnergy-api-ruby-client.rb', line 8 def user_id @user_id end |
Instance Method Details
#token! ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/insnergy-api-ruby-client.rb', line 21 def token! response = JSON.parse(RestClient.post "#{@domain}/if/oauth/token" ,{:client_id => @oauth_key, :client_secret => @oauth_secert, :absytem => 'IFA', :grant_type => 'refresh_token', :refresh_token => @refresh_token }, :accept => :json) raise "<no got refresh_token>\n#{response}" unless response.key?('refresh_token') raise "<no got access_token>\n#{response}" unless response.key?('access_token') @refresh_token = response['refresh_token'] @access_token = response['access_token'] end |
#user_id! ⇒ Object
29 30 31 32 33 |
# File 'lib/insnergy-api-ruby-client.rb', line 29 def user_id! response = JSON.parse(RestClient.get "#{@domain}/if/3/user/me" ,{:Authorization => "Bearer #{@access_token}"}) raise "<no got user_id>\n#{response}" unless response.key?('user') && response['user'].key?('user_id') @user_id = response['user']['user_id'] end |