Class: Nhr::Client
- Inherits:
-
Object
- Object
- Nhr::Client
- Defined in:
- lib/nhr-api-ruby-client.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#cmdvalue ⇒ Object
readonly
Returns the value of attribute cmdvalue.
-
#device_ieee ⇒ Object
readonly
Returns the value of attribute device_ieee.
-
#etime ⇒ Object
readonly
Returns the value of attribute etime.
-
#gateway_id ⇒ Object
readonly
Returns the value of attribute gateway_id.
-
#nhr_url ⇒ Object
readonly
Returns the value of attribute nhr_url.
-
#response ⇒ Object
Returns the value of attribute response.
-
#stime ⇒ Object
readonly
Returns the value of attribute stime.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #client ⇒ Object
-
#initialize(nhr_url: nil, token: nil, gateway_id: nil, device_ieee: nil, cmdvalue: nil, action: nil, stime: nil, etime: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(nhr_url: nil, token: nil, gateway_id: nil, device_ieee: nil, cmdvalue: nil, action: nil, stime: nil, etime: nil) ⇒ Client
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nhr-api-ruby-client.rb', line 10 def initialize(nhr_url: nil, token: nil, gateway_id: nil, device_ieee: nil, cmdvalue: nil, action: nil, stime: nil, etime: nil) @nhr_url = nhr_url @token = token @gateway_id = gateway_id @device_ieee = device_ieee @action = action @stime = stime @etime = etime @cmdvalue = cmdvalue client end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
8 9 10 |
# File 'lib/nhr-api-ruby-client.rb', line 8 def action @action end |
#cmdvalue ⇒ Object (readonly)
Returns the value of attribute cmdvalue.
8 9 10 |
# File 'lib/nhr-api-ruby-client.rb', line 8 def cmdvalue @cmdvalue end |
#device_ieee ⇒ Object (readonly)
Returns the value of attribute device_ieee.
8 9 10 |
# File 'lib/nhr-api-ruby-client.rb', line 8 def device_ieee @device_ieee end |
#etime ⇒ Object (readonly)
Returns the value of attribute etime.
8 9 10 |
# File 'lib/nhr-api-ruby-client.rb', line 8 def etime @etime end |
#gateway_id ⇒ Object (readonly)
Returns the value of attribute gateway_id.
8 9 10 |
# File 'lib/nhr-api-ruby-client.rb', line 8 def gateway_id @gateway_id end |
#nhr_url ⇒ Object (readonly)
Returns the value of attribute nhr_url.
8 9 10 |
# File 'lib/nhr-api-ruby-client.rb', line 8 def nhr_url @nhr_url end |
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/nhr-api-ruby-client.rb', line 7 def response @response end |
#stime ⇒ Object (readonly)
Returns the value of attribute stime.
8 9 10 |
# File 'lib/nhr-api-ruby-client.rb', line 8 def stime @stime end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
8 9 10 |
# File 'lib/nhr-api-ruby-client.rb', line 8 def token @token end |
Instance Method Details
#client ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/nhr-api-ruby-client.rb', line 22 def client parameter = {token: @token, gateway_id: @gateway_id, action: @action, stime: @stime, etime: @etime, device_ieee: @device_ieee, cmdvalue: @cmdvalue} formdata = URI.encode_www_form(parameter) response = RestClient::Resource.new(@nhr_url).post(formdata) raise "response nil,it should must be a json string and could be gsub" unless response response = JSON.parse(response.split(';')[-1].gsub("\r\n\t\r\n?>\t",'')) raise "#{response['response']}" unless response['status'] == true or (@action = 'GetPIRMotionStatus' && response['response'] == 'not found data!!') @response = response end |