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
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/nhr-api-ruby-client.rb', line 7 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.
5 6 7 |
# File 'lib/nhr-api-ruby-client.rb', line 5 def action @action end |
#cmdvalue ⇒ Object (readonly)
Returns the value of attribute cmdvalue.
5 6 7 |
# File 'lib/nhr-api-ruby-client.rb', line 5 def cmdvalue @cmdvalue end |
#device_ieee ⇒ Object (readonly)
Returns the value of attribute device_ieee.
5 6 7 |
# File 'lib/nhr-api-ruby-client.rb', line 5 def device_ieee @device_ieee end |
#etime ⇒ Object (readonly)
Returns the value of attribute etime.
5 6 7 |
# File 'lib/nhr-api-ruby-client.rb', line 5 def etime @etime end |
#gateway_id ⇒ Object (readonly)
Returns the value of attribute gateway_id.
5 6 7 |
# File 'lib/nhr-api-ruby-client.rb', line 5 def gateway_id @gateway_id end |
#nhr_url ⇒ Object (readonly)
Returns the value of attribute nhr_url.
5 6 7 |
# File 'lib/nhr-api-ruby-client.rb', line 5 def nhr_url @nhr_url end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/nhr-api-ruby-client.rb', line 4 def response @response end |
#stime ⇒ Object (readonly)
Returns the value of attribute stime.
5 6 7 |
# File 'lib/nhr-api-ruby-client.rb', line 5 def stime @stime end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'lib/nhr-api-ruby-client.rb', line 5 def token @token end |
Instance Method Details
#client ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/nhr-api-ruby-client.rb', line 19 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, :ssl_version => 'TLSv1').post(formdata) raise "response nil" if response == nil response = JSON.parse(response.split(';')[-1].gsub("\r\n\t\r\n?>\t",'')) raise "#{response},gateway_id: #{@gateway_id}" unless response['status'] == true or (@action = 'GetPIRMotionStatus' && response['response'] == 'not found data!!') @response = response end |