class Nhr::Client
Attributes
action[R]
cmdvalue[R]
device_ieee[R]
etime[R]
gateway_id[R]
nhr_url[R]
response[RW]
stime[R]
token[R]
Public Class Methods
new(nhr_url: nil, token: nil, gateway_id: nil, device_ieee: nil, cmdvalue: nil, action: nil, stime: nil, etime: nil)
click to toggle source
# 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
Public Instance Methods
client()
click to toggle source
# 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