lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-0.3.1 vs lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-0.3.2

- old
+ new

@@ -48,15 +48,16 @@ {:status => 500, :result => "failed"} end end def get_token(app_id, secret) - internal_func.test + internal_func.printer_texter("get_token: start. Step1, iput: app_id: #{app_id.to_s}, #{secret.to_s}", "debug") out_resp = {} begin path = "/iocm/app/sec/v1.1.0/login" url_string = "https://" + platformip + ":" + platformport + path + internal_func.printer_texter("get_token: start. Step2, url_string: #{url_string}", "debug") uri = URI.parse url_string https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file)) https.key = OpenSSL::PKey::RSA.new(File.read(key_file)) @@ -64,48 +65,51 @@ request = Net::HTTP::Post.new(uri.path) data = { :appId => app_id, :secret => secret } + internal_func.printer_texter("get_token: start. Step3, data: #{data.to_s}", "debug") request.content_type = 'application/x-www-form-urlencoded' request.body = URI.encode_www_form(data) res = https.request(request) out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)} rescue out_resp = {:code => 500, :message => "failed get token"} end jjj = {:procedure => "get_token", :answ => out_resp} - internal_func.printer_texter(jjj) + internal_func.printer_texter(jjj, "debug") out_resp end def token_logout(token) - internal_func.printer_texter("token_logout token: #{token}") + internal_func.printer_texter("token_logout Step1 token: #{token}", "debug") out_resp = {} begin path = "/iocm/app/sec/v1.1.0/logout" url_string = "https://" + platformip + ":" + platformport + path + internal_func.printer_texter("token_logout Step2 url_string: #{url_string}", "debug") uri = URI.parse url_string https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file)) https.key = OpenSSL::PKey::RSA.new(File.read(key_file)) https.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri.path) data = { :accessToken => token } + internal_func.printer_texter("token_logout Step3 data: #{data.to_s}", "debug") request.content_type = 'application/json' request.body = URI.encode_www_form(data) res = https.request(request) out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)} rescue out_resp = {:code => 500, :message => "failed logout token"} end jjj = {:procedure => "token_logout", :answ => out_resp} - internal_func.printer_texter(jjj) + internal_func.printer_texter(jjj, "debug") out_resp end #Registering a Directly Connected Device (Verification Code Mode) (V2) def dev_register_verif_code_mode(app_id, secret, node_id) \ No newline at end of file