Class: Insnergy::Client::Sensor
- Inherits:
-
Object
- Object
- Insnergy::Client::Sensor
- Defined in:
- lib/insnergy-api-ruby-client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#widgets ⇒ Object
readonly
Returns the value of attribute widgets.
Instance Method Summary collapse
- #each ⇒ Object
- #get_device ⇒ Object
- #get_response ⇒ Object
-
#initialize(client: nil, category: nil) ⇒ Sensor
constructor
A new instance of Sensor.
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_token ⇒ Object (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_id ⇒ Object (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 |
#widgets ⇒ Object (readonly)
Returns the value of attribute widgets.
96 97 98 |
# File 'lib/insnergy-api-ruby-client.rb', line 96 def @widgets end |
Instance Method Details
#each ⇒ Object
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_device ⇒ Object
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_response ⇒ Object
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 |