Class: Insnergy::Client::Sensor

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, category: nil) ⇒ Sensor

Returns a new instance of Sensor.



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

def initialize(client: nil,category: nil)
  @access_token = client.access_token
  @user_id = client.user_id
  @domain = client.domain
  @category = category
  get_device
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



96
97
98
# File 'lib/insnergy-api-ruby-client.rb', line 96

def access_token
  @access_token
end

#user_idObject (readonly)

Returns the value of attribute user_id.



96
97
98
# File 'lib/insnergy-api-ruby-client.rb', line 96

def user_id
  @user_id
end

#widgetsObject (readonly)

Returns the value of attribute widgets.



96
97
98
# File 'lib/insnergy-api-ruby-client.rb', line 96

def widgets
  @widgets
end

Instance Method Details

#eachObject



113
114
115
116
117
# File 'lib/insnergy-api-ruby-client.rb', line 113

def each
  @widgets.each do |ele|
    yield ele
  end
end

#get_deviceObject



106
107
108
109
110
111
# File 'lib/insnergy-api-ruby-client.rb', line 106

def get_device
  @widgets = Array.new
  get_response['widgets'].each do |ele|
      @widgets << Sensor.new(ele)
  end 
end

#get_responseObject



119
120
121
122
123
124
# File 'lib/insnergy-api-ruby-client.rb', line 119

def get_response
  parameter = {:params => {:apsystem => "IFA", :email => @user_id, :type_code => 1, :dev_category => "#{@category}"}, :Authorization => "Bearer #{@access_token}"}
  response = JSON.parse(RestClient.get "#{@domain}/if/3/user/widgets", parameter)
  raise "err code is not zero\n#{response}" unless response['err']['code'] == '0'  
  response
end