Class: Insnergy::Client::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/insnergy-api-ruby-client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, device_id: nil, action: nil) ⇒ Control

Returns a new instance of Control.



89
90
91
92
93
94
95
96
97
# File 'lib/insnergy-api-ruby-client.rb', line 89

def initialize(client: nil, device_id: nil, action: nil)
  @access_token = client.access_token
  @user_id = client.user_id
  @domain = client.domain
  @device_id = device_id
  @action = action
  @response = nil
  response!
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



87
88
89
# File 'lib/insnergy-api-ruby-client.rb', line 87

def action
  @action
end

#device_idObject

Returns the value of attribute device_id.



87
88
89
# File 'lib/insnergy-api-ruby-client.rb', line 87

def device_id
  @device_id
end

#responseObject (readonly)

Returns the value of attribute response.



88
89
90
# File 'lib/insnergy-api-ruby-client.rb', line 88

def response
  @response
end

Instance Method Details

#response!Object



99
100
101
102
103
104
# File 'lib/insnergy-api-ruby-client.rb', line 99

def response!
  parameter = {:params => {:apsystem => "IFA", :email => @user_id,  :dev_id => @device_id ,:action => @action}, :Authorization => "Bearer #{@access_token}"}
  @response = JSON.parse(RestClient.get "#{@domain}/if/3/device/control" , parameter)
  raise "#{response['err']['code']}" unless response['err']['code'] == '0' 
  @response 
end