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

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

#actionObject (readonly)

Returns the value of attribute action.



5
6
7
# File 'lib/nhr-api-ruby-client.rb', line 5

def action
  @action
end

#cmdvalueObject (readonly)

Returns the value of attribute cmdvalue.



5
6
7
# File 'lib/nhr-api-ruby-client.rb', line 5

def cmdvalue
  @cmdvalue
end

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

#etimeObject (readonly)

Returns the value of attribute etime.



5
6
7
# File 'lib/nhr-api-ruby-client.rb', line 5

def etime
  @etime
end

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

#responseObject

Returns the value of attribute response.



4
5
6
# File 'lib/nhr-api-ruby-client.rb', line 4

def response
  @response
end

#stimeObject (readonly)

Returns the value of attribute stime.



5
6
7
# File 'lib/nhr-api-ruby-client.rb', line 5

def stime
  @stime
end

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

#clientObject



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