require 'mongo' require 'json' require 'rubygems' require 'nokogiri' require 'rails' require 'imperituroard/add_functions/logger/any_functions' class MongoVpn attr_accessor :mongo_vpn_ip, :mongo_vpn_port, :client_vpn, :mongo_vpn_database, :internal_vpn_func, :logger_any def initialize(mongo_vpn_ip, mongo_vpn_port, mongo_vpn_database) @mongo_vpn_database = mongo_vpn_database @mongo_vpn_ip = mongo_vpn_ip @mongo_vpn_port = mongo_vpn_port client_vpn_host = [mongo_vpn_ip + ":" + mongo_vpn_port] @client_vpn = Mongo::Client.new(client_vpn_host, :database => mongo_vpn_database) @logger_any = LogAddFunctions_2.new end #get data by msisdn. Validate data from collection msisdn_list def get_mongo_msisdn(msisdn) out_resp = {} begin msisdn_data = [] collection = client_vpn[:msisdn_list] collection.find({:msisdn => msisdn.to_s}).each {|row| msisdn_data = row } if msisdn_data != [] && msisdn_data["msisdn"] != nil && msisdn_data["msisdn"] != "" if msisdn_data["group_id"] != [] && msisdn_data["group_id"] != nil && msisdn_data["group_id"] != "" if msisdn_data["profile_id"] != [] && msisdn_data["profile_id"] != nil && msisdn_data["profile_id"] != "" out_resp = {:code => 200, :result => "get_mongo_msisdn: Request completed successfully", :body => msisdn_data} else out_resp = {:code => 406, :result => "get_mongo_msisdn: invalid data. profile_id not found"} end else out_resp = {:code => 405, :result => "get_mongo_msisdn: invalid data. organization_id not found"} end else out_resp = {:code => 404, :result => "get_mongo_msisdn: login not found in database"} end rescue out_resp = {:code => 507, :result => "get_mongo_msisdn: Unknown SDK error"} end logger_any.printer_texter(out_resp, "debug") out_resp end end