lib/imperituroard.rb in imperituroard-0.3.8 vs lib/imperituroard.rb in imperituroard-0.3.9

- old
+ new

@@ -1,18 +1,21 @@ $LOAD_PATH.unshift File.expand_path("../projects/iot", __dir__) $LOAD_PATH.unshift File.expand_path("../projects/wttx", __dir__) $LOAD_PATH.unshift File.expand_path("../projects/mhub", __dir__) +$LOAD_PATH.unshift File.expand_path("../projects/mhub/subs/dabrab", __dir__) + require "imperituroard/version" require "imperituroard/phpipamdb" require "imperituroard/phpipamcps" require "imperituroard/projects/iot/mongoconnector" require "imperituroard/projects/iot/hua_oceanconnect_adapter" require "imperituroard/projects/iot/add_functions" require "imperituroard/projects/iot/internal_functions" require 'imperituroard/projects/mhub/infobip' require 'imperituroard/projects/mhub/sk' +require 'imperituroard/projects/mhub/subs/dabrab/dabrab_proced' require 'json' require 'ipaddr' require 'date' require 'net/http' require 'uri' @@ -795,19 +798,20 @@ end class Mhub_2 - attr_accessor :sk_url, :sk_login, :sk_password, :mhub_connector, :internal_func + attr_accessor :sk_url, :sk_login, :sk_password, :mhub_connector, :internal_func, :dabrab_connecter - def initialize(sk_url, sk_login, sk_password, telegram_api_url, telegram_chat_id) - @sk_url = sk_url + def initialize(sk_url_simple, sk_login, sk_password, telegram_api_url, telegram_chat_id, sk_url_broadcast) + @sk_url = sk_url_simple @sk_login = sk_login @sk_password = sk_password @internal_func = InternalFunc.new - @mhub_connector = Sksk_1.new(sk_url, sk_login, sk_password) + @mhub_connector = Sksk_1.new(sk_url_simple, sk_login, sk_password, sk_url_broadcast) @internal_func = InternalFunc.new + @dabrab_connecter = Dabrab.new @add_functions_connector = AdditionalFunc.new(telegram_api_url, telegram_chat_id) end #{"destinations"=>[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}], @@ -818,46 +822,73 @@ # "viber"=>nil, "sms"=>{"text"=>"карточка готова"}, "sendAt"=>"2019-08-15T08:40:00.000", # "notifyUrl"=>"https://bpmonline.bankdabrabyt.by:444/0/ServiceModel/ScGetReports.svc/GetReports", # "notifyContentType"=>"application/json"}} - def get_send_message(params) + def get_send_message(params, ip_src, ip_real, ip_vip) input_params = {:params => params} - - p input_params - output_params = {} + hub_resp = {} + null_statement = [nil, "nil", "", "null"] begin - msisdn = params["destinations"][0]["to"]["phoneNumber"] + # if params["destinations"].length == 1 + # msisdn = params["destinations"][0]["to"]["phoneNumber"] + # if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) + # hub_resp = mhub_connector.sk_send_sms_one(msisdn, params["notifyUrl"], params["sms"]["text"], "TEST") + # elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) + # hub_resp = mhub_connector.sk_send_viber_one(msisdn, params["notifyUrl"], params["viber"]["text"]) + # elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) + # hub_resp = mhub_connector.sk_send_viber_sms_one(msisdn, params["notifyUrl"], params["sms"]["text"], params["viber"]["text"], "TEST") + # else + # output_params = {"code": 501, "result": "Invalid input data st1", "answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}} + # end + # elsif params["destinations"].length > 1 + # + # msisdn2 = dabrab_connecter.num_formatter(params["destinations"], params["notifyUrl"].split(":")[2]) + # + # if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) + # hub_resp = mhub_connector.sk_send_sms_list(msisdn2, params["notifyUrl"], params["sms"]["text"], "TEST") + # elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) + # hub_resp = mhub_connector.sk_send_viber_list(msisdn2, params["notifyUrl"], params["viber"]["text"]) + # elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) + # hub_resp = mhub_connector.sk_send_viber_sms_list(msisdn2, params["notifyUrl"], params["sms"]["text"], params["viber"]["text"], "TEST") + # else + # output_params = {"code": 502, "result": "Invalid input data st2", "answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}} + # end + # else + # output_params = {"code": 503, "result": "Invalid recipients", "answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}} + # end + if params["destinations"].length >= 1 - if params["viber"] == nil && params["sms"] != nil + msisdn2 = dabrab_connecter.num_formatter(params["destinations"], params["notifyUrl"].split(":")[2]) - mhub_connector.sk_send_sms(msisdn, params["notifyUrl"], params["sms"]["text"], "TEST") - - elsif params["viber"] != nil && params["sms"] == nil - - mhub_connector.sk_send_viber(msisdn, params["notifyUrl"], params["viber"]["text"]) - - elsif params["viber"] != nil && params["sms"] != nil - - mhub_connector.sk_send_viber_sms(msisdn, params["notifyUrl"], params["sms"]["text"], params["viber"]["text"], "TEST") - + if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) + hub_resp = mhub_connector.sk_send_sms_list(msisdn2, params["notifyUrl"], params["sms"]["text"], "TEST") + elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) + hub_resp = mhub_connector.sk_send_viber_list(msisdn2, params["notifyUrl"], params["viber"]["text"]) + elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) + hub_resp = mhub_connector.sk_send_viber_sms_list(msisdn2, params["notifyUrl"], params["sms"]["text"], params["viber"]["text"], "TEST") + else + output_params = {"code": 502, "result": "Invalid input data st2", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} + end else + output_params = {"code": 503, "result": "Invalid recipients", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} + end - output_params = {"code": 500, "result": "Invalid input data"} + mes_data = dabrab_connecter.send_responce_formatter(hub_resp) + p hub_resp - end + output_params = {"code": 200, "result": "Data processed", "body": {"answer": mes_data[:body][:mess_to_recip], "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} rescue - output_params = {"code": 500, "result": "Invalid input data"} + output_params = {"code": 500, "result": "Unknown SDK error", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end - internal_func.printer_texter({:input => input_params, :output => output_params, :procedure => "Mhub_2.get_send_message"}, "debug") - + internal_func.printer_texter({:input => input_params, :output => output_params, :hub_resp => hub_resp, :procedure => "Mhub_2.get_send_message"}, "debug") output_params end \ No newline at end of file