require 'net/https' require 'json' require 'uri' require 'net/http' require 'rubygems' require 'nokogiri' require 'rails' require 'imperituroard/projects/iot/internal_functions' class Gms_2 attr_accessor :gms_login, :gms_password, :telegram_connector, :internal_func def initialize(gms_login, gms_password, telegram_api_url, telegram_chat_id) @gms_login = gms_login @gms_password = gms_password @internal_func = InternalFunc.new @telegram_connector = Telegram_2.new(telegram_api_url, telegram_chat_id) end def get_advanced_by_external(external_id) input_params = {:external_id => external_id} output_params = {} thr1_get_advanced_by_external = Thread.new do begin uri = URI("https://dr-v2.hyber.im/2160/api/dr/external/" + external_id + "/advanced") https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Get.new(uri.path, initheader = {:"Content-Type" => 'application/json'}) req.basic_auth gms_login, gms_password req["Content-Type"] = "application/json" res = https.request(req) p res.code p res.body if res.code == "200" output_params = {:code => 200, :result => "Gms_2.get_advanced_by_external: Request processed", :body => {:request_message => input_params, :res_code => res.code, :res_body => JSON.parse(res.body.to_s)}} else output_params = {:code => res.code.to_i, :result => "Gms_2.get_advanced_by_external: Request processed", :body => {:request_message => input_params, :res_code => res.code, :res_body => res.body.to_s}} end rescue output_params = {:code => 500, :result => "Gms_2.get_advanced_by_external: Something wrong", :body => {:request_message => input_params}} end end thr1_get_advanced_by_external.join internal_func.printer_texter({:input => input_params, :output => output_params, :procedure => "Gms_2.get_advanced_by_external"}, "debug") output_params end end