lib/imperituroard/projects/iot/mongoconnector.rb in imperituroard-0.3.0 vs lib/imperituroard/projects/iot/mongoconnector.rb in imperituroard-0.3.1

- old
+ new

@@ -2,22 +2,24 @@ require 'json' require 'rubygems' require 'nokogiri' require 'rails' +require "imperituroard/projects/iot/internal_functions" #class for communication with mongo database for iot API class MongoIot - attr_accessor :mongo_ip, :mongo_port, :client, :mongo_database + attr_accessor :mongo_ip, :mongo_port, :client, :mongo_database, :internal_func def initialize(mongo_ip, mongo_port, mongo_database) @mongo_database = mongo_database @mongo_ip = mongo_ip @mongo_port = mongo_port client_host = [mongo_ip + ":" + mongo_port] @client = Mongo::Client.new(client_host, :database => mongo_database) + @internal_func = InternalFunc.new end def audit_logger(proc_name, src_ip, input_json, output_json, real_ip) out_resp = {} begin @@ -34,11 +36,11 @@ result = collection.insert_one(doc) out_resp = {:code => 200, :result => "audit_logger: Request completed successfully", :body => result} rescue out_resp = {:code => 507, :result => "audit_logger: Unknown SDK error"} end - p out_resp + internal_func.printer_texter(out_resp) out_resp end #:code => 507, :result => "Unknown SDK error" #{:code => 200, :result => "Request completed successfully", :body => result_ps} @@ -68,11 +70,11 @@ end rescue out_resp = {:code => 507, :result => "get_profiles_by_login: Unknown SDK error"} end - p out_resp + internal_func.printer_texter(out_resp) out_resp end def get_imei_info_from_db(imeilist) out_resp = {} @@ -90,11 +92,11 @@ } out_resp = {:code => 200, :result => "get_imei_info_from_db: Request completed successfully", :body => result_ps} rescue out_resp = {:code => 507, :result => "get_imei_info_from_db: Unknown SDK error"} end - p out_resp + internal_func.printer_texter(out_resp) out_resp end def get_profile_id_by_name(profile_name) begin @@ -158,11 +160,11 @@ out_resp = {:code => 500, :result => "check_login_profile_permiss: Access denied. Login not found"} end else out_resp = {:code => 500, :result => "check_login_profile_permiss: Access denied. Login not found"} end - p out_resp + internal_func.printer_texter(out_resp) out_resp end def check_login_prof_perm_id_one(login, profile_id) @@ -187,11 +189,11 @@ end end else out_resp = {:code => 500, :result => "check_login_prof_perm_id_one: Login not found"} end - p out_resp + internal_func.printer_texter(out_resp) out_resp end def check_imei_exists(imei_list) out_resp = {} @@ -210,12 +212,11 @@ p "not_ex" p not_ex p res_exists out_resp = {:code => 200, :result => "check_imei_exists: Request completed successfully", :body => {:exists => res_exists, :not_exists => not_ex}} - - p out_resp + internal_func.printer_texter(out_resp) out_resp end def imei_insert_list(imei_list) @@ -289,11 +290,10 @@ if res.key?("profile") res=res else out_resp = {:code => 505, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not returned profile. Invalid data in database and returned: #{res.to_s}"} end - rescue out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not processed correctly and returned: #{res.to_s}"} end begin @@ -301,24 +301,20 @@ out_resp = {:code => 200, :result => "get_profile_name_from_imei: Request completed successfully", :body => res} end rescue out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_profile_name_by_id not processed correctly and returned: #{res.to_s}"} end - - end rescue out_resp = {:code => 506, :result => "get_profile_name_from_imei: Function get_imei_info_from_db not processed correctly and returned: #{info.to_s}"} end rescue out_resp = {:code => 507, :result => "get_profile_name_from_imei: Unknown SDK error"} end - - p out_resp + internal_func.printer_texter(out_resp) out_resp - end def device_remove_single_mongo(imei) out_resp = {} @@ -331,13 +327,12 @@ p result out_resp = {:code => 200, :result => "device_remove_single_mongo: Request completed successfully"} rescue out_resp = {:code => 507, :result => "device_remove_single_mongo: Unknown SDK error"} end - p out_resp + internal_func.printer_texter(out_resp) out_resp - end def device_modify_attr_mongo(imei, address) out_resp = {} begin @@ -349,11 +344,11 @@ result = collection.update_one(doc, sett) out_resp = {:code => 200, :result => "device_modify_attr_mongo: Request completed successfully"} rescue out_resp = {:code => 507, :result => "device_modify_attr_mongo: Unknown SDK error"} end - p out_resp + internal_func.printer_texter(out_resp) out_resp end def device_modify_any_attr_mongo(imei, attr_list) out_resp = {} @@ -384,12 +379,11 @@ secret = result_ps[0][:iot_data][:secret] out_resp = {:code => 200, :result => "get_iot_oceanconnect_credent: Request completed successfully", :body => {:app_id => app_id, :secret => secret}} rescue out_resp = {:code => 500, :result => "get_iot_oceanconnect_credent: Process failed"} end - p out_resp + internal_func.printer_texter(out_resp) out_resp - end def ttt p "111111" \ No newline at end of file