Class: Nhr::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionObject (readonly)

Returns the value of attribute action.



8
9
10
# File 'lib/nhr-api-ruby-client.rb', line 8

def action
  @action
end

#cmdvalueObject (readonly)

Returns the value of attribute cmdvalue.



8
9
10
# File 'lib/nhr-api-ruby-client.rb', line 8

def cmdvalue
  @cmdvalue
end

#device_ieeeObject (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

#etimeObject (readonly)

Returns the value of attribute etime.



8
9
10
# File 'lib/nhr-api-ruby-client.rb', line 8

def etime
  @etime
end

#gateway_idObject (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_urlObject (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

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/nhr-api-ruby-client.rb', line 7

def response
  @response
end

#stimeObject (readonly)

Returns the value of attribute stime.



8
9
10
# File 'lib/nhr-api-ruby-client.rb', line 8

def stime
  @stime
end

#tokenObject (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

#clientObject



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