Class: Insnergy::Client
- Inherits:
-
Object
- Object
- Insnergy::Client
- Defined in:
- lib/insnergy-api-ruby-client.rb
Defined Under Namespace
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) ⇒ Client
constructor
A new instance of Client.
- #power(device_id: nil, start_time: nil, end_time: nil) ⇒ Object
- #refresh! ⇒ Object
- #sensor ⇒ Object
- #user_id! ⇒ Object
Constructor Details
#initialize(domain: nil, oauth_key: nil, oauth_secert: nil, refresh_token: nil) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 |
# File 'lib/insnergy-api-ruby-client.rb', line 7 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 @user_id = nil refresh! user_id! end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/insnergy-api-ruby-client.rb', line 5 def access_token @access_token end |
#domain ⇒ Object
Returns the value of attribute domain.
4 5 6 |
# File 'lib/insnergy-api-ruby-client.rb', line 4 def domain @domain end |
#oauth_key ⇒ Object
Returns the value of attribute oauth_key.
4 5 6 |
# File 'lib/insnergy-api-ruby-client.rb', line 4 def oauth_key @oauth_key end |
#oauth_secert ⇒ Object
Returns the value of attribute oauth_secert.
4 5 6 |
# File 'lib/insnergy-api-ruby-client.rb', line 4 def oauth_secert @oauth_secert end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
4 5 6 |
# File 'lib/insnergy-api-ruby-client.rb', line 4 def refresh_token @refresh_token end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/insnergy-api-ruby-client.rb', line 5 def user_id @user_id end |
Instance Method Details
#power(device_id: nil, start_time: nil, end_time: nil) ⇒ Object
35 36 37 38 |
# File 'lib/insnergy-api-ruby-client.rb', line 35 def power(device_id: nil, start_time: nil, end_time: nil) client = Client::Power.new(client: self, device_id: device_id, start_time: start_time, end_time: end_time) client.get_device end |
#refresh! ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/insnergy-api-ruby-client.rb', line 17 def refresh! 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 "<refresh_token is nil>\n#{response}" unless response['refresh_token'] != nil raise "<access_token is nil>\n#{response}" unless response['access_token'] != nil @refresh_token = response['refresh_token'] @access_token = response['access_token'] end |
#sensor ⇒ Object
31 32 33 |
# File 'lib/insnergy-api-ruby-client.rb', line 31 def sensor Client::Sensor.new(client: self, category: 'sensor') end |
#user_id! ⇒ Object
25 26 27 28 29 |
# File 'lib/insnergy-api-ruby-client.rb', line 25 def user_id! response = JSON.parse(RestClient.get "#{@domain}/if/3/user/me" ,{:Authorization => "Bearer #{@access_token}"}) raise "<user_id is nil>\n#{response}" unless response['user']['user_id'] != nil @user_id = response['user']['user_id'] end |