Sha256: fff90d7115cdf7f12e72b4f0f56495430f95bb0f1c931c975a733b9397b8651f

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

module Nhr
  class Client

    attr_accessor :response
	  attr_reader :nhr_url, :token, :gateway_id, :action, :stime, :etime, :device_ieee, :cmdvalue

  	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

  	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",'')) 
      return 'not_found_data' if @action = 'GetPIRMotionStatus' && response['response'] == 'not found data!!'
      raise "#{response},gateway_id: #{@gateway_id}" unless response['status'] == true  
      @response = response
  	end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nhr-api-ruby-client-0.1.1 lib/nhr-api-ruby-client.rb