class MhubFunctions_2

Attributes

crm_connector[RW]
dabrab_connecter[RW]
internal_func[RW]
log_level[RW]
mhub_connector[RW]
sk_login[RW]
sk_password[RW]
sk_url[RW]
sms_alphaname[RW]
static_callback[RW]
telegram_connector[RW]

Public Class Methods

new(sk_url_simple, sk_login, sk_password, telegram_api_url, telegram_chat_id, sk_url_broadcast, static_callback, crm_callback_url, crm_login, crm_password, sms_alphaname, log_level) click to toggle source
# File lib/imperituroard/projects/mhub.rb, line 30
def initialize(sk_url_simple, sk_login, sk_password, telegram_api_url, telegram_chat_id, sk_url_broadcast, static_callback, crm_callback_url, crm_login, crm_password, sms_alphaname, log_level)
  @sk_url = sk_url_simple
  @sk_login = sk_login
  @sk_password = sk_password
  @log_level = log_level
  @internal_func = InternalFunc.new
  @mhub_connector = Sksk_2.new(sk_url_simple, sk_login, sk_password, sk_url_broadcast, telegram_api_url, telegram_chat_id, log_level)
  @internal_func = InternalFunc.new
  @dabrab_connecter = Dabrab.new(log_level)
  @telegram_connector = Telegram_2.new(telegram_api_url, telegram_chat_id)
  @static_callback = static_callback
  @crm_connector = Crm_2.new(crm_callback_url, crm_login, crm_password, telegram_api_url, telegram_chat_id, log_level)
  @sms_alphaname = sms_alphaname
end

Public Instance Methods

get_send_message_2(params, ip_src, ip_real, ip_vip) click to toggle source

for bank dabrabyt

# File lib/imperituroard/projects/mhub.rb, line 57
def get_send_message_2(params, ip_src, ip_real, ip_vip)

  input_params = {:params => params}
  output_params = {}
  hub_resp = {}
  null_statement = [nil, "nil", "", "null"]
  mes_data = {}

  begin

    # 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

      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, static_callback, params["sms"]["text"], sms_alphaname)
      elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"])
        hub_resp = mhub_connector.sk_send_viber_list(msisdn2, static_callback, params["viber"]["text"])
      elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"])
        p "vibersms"
        p msisdn2
        hub_resp = mhub_connector.sk_send_viber_sms_list(msisdn2, static_callback, params["sms"]["text"], params["viber"]["text"], sms_alphaname)
      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
      mes_data = dabrab_connecter.send_responce_formatter(hub_resp)


    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": 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": "MhubFunctions_2.get_send_message_2: Unknown SDK error", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}}
    telegram_connector.telegram_message(output_params)
  end

  internal_func.printer_texter({:input => input_params, :output => output_params, :hub_resp => hub_resp, :procedure => "Mhub_2.get_send_message"}, log_level)
  output_params

end
get_send_message_mass_2(params, ip_src, ip_real, ip_vip, slice_number, time_pause_minutes, viberttl, params_manual_set, smsttl ) click to toggle source

for bank dabrabyt for massive nums

# File lib/imperituroard/projects/mhub.rb, line 132
def get_send_message_mass_2(params,
                            ip_src,
                            ip_real,
                            ip_vip,
                            slice_number,
                            time_pause_minutes,
                            viberttl,
                            params_manual_set,
                            smsttl
)

  input_params = {:params => params}
  output_params = {}

  null_statement = [nil, "nil", "", "null"]
  mes_data_answ = []

  begin
    internal_func.printer_texter({:input => params, :procedure => "Mhub_2.get_send_message_mass_2"}, log_level)
    if params["destinations"].length >= 1
      msisdn2 = dabrab_connecter.num_formatter(params["destinations"], params["notifyUrl"].split(":")[2])
      splitted_parts = msisdn2.each_slice(slice_number).to_a
      for part_list in splitted_parts

        internal_func.printer_texter({:input => part_list, :procedure => "Mhub_2.get_send_message_mass_2"}, log_level)

        hub_resp = {}


        viber_param = params["viber"]
        sms_param = params["sms"]

        if params_manual_set != 0
          begin
            if params_manual_set[:viber] == 0
              viber_param = nil
            end
            if params_manual_set[:sms] == 0
              sms_param = nil
            end
          rescue
            nil
          end
        end

        if null_statement.include?(viber_param) && !null_statement.include?(sms_param)
          hub_resp = mhub_connector.sk_send_sms_list(part_list, static_callback, params["sms"]["text"], sms_alphaname, time_pause_minutes, smsttl)
        elsif !null_statement.include?(viber_param) && null_statement.include?(sms_param)
          hub_resp = mhub_connector.sk_send_viber_list(part_list, static_callback, params["viber"]["text"], time_pause_minutes, viberttl)
        elsif !null_statement.include?(viber_param) && !null_statement.include?(sms_param)
          hub_resp = mhub_connector.sk_send_viber_sms_list(part_list, static_callback, params["sms"]["text"], params["viber"]["text"], sms_alphaname, time_pause_minutes, viberttl, smsttl)
        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
        mes_data = dabrab_connecter.send_responce_formatter(hub_resp)

        internal_func.printer_texter({:input => mes_data, :procedure => "Mhub_2.get_send_message_mass_2"}, log_level)

        mes_data_answ = mes_data_answ + mes_data[:body][:mess_to_recip][:messages]

      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": 200, "result": "Data processed", "body": {"answer": {"bulkId": "00000000-0000-0000-0000-000000000000", "messages": mes_data_answ}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}}

  rescue
    output_params = {"code": 500, "result": "MhubFunctions_2.get_send_message_2: Unknown SDK error", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}}
    telegram_connector.telegram_message(output_params)
  end

  internal_func.printer_texter({:input => input_params, :output => output_params, :hub_resp => {}, :procedure => "Mhub_2.get_send_message"}, log_level)
  output_params

end
rec_deliv_report_2(params, ip_src, ip_real, ip_vip, crm_slice_num=2) click to toggle source

for bank dabrabyt

# File lib/imperituroard/projects/mhub.rb, line 212
def rec_deliv_report_2(params, ip_src, ip_real, ip_vip, crm_slice_num=2)
  internal_func.printer_texter({:mess => 'started function rec_deliv_report_2'}, log_level)
  input_params = {:params => params, :ip_src => ip_src, :ip_real => ip_real, :ip_vip => ip_vip}
  output_params = {}
  hub_resp = {}
  result = {}

  internal_func.printer_texter({:mess => 'rec_deliv_report_2 step1'}, log_level)
  begin
    mes_report = dabrab_connecter.delivery_report_transform(params)[:body][:report_to_recip]
    internal_func.printer_texter({:mess => 'rec_deliv_report_2 step2'}, log_level)

    begin
      internal_func.printer_texter({:mess => 'rec_deliv_report_2 step2.1'}, log_level)
      result = crm_connector.crm_status_2(mes_report, crm_slice_num)
      internal_func.printer_texter({:mess => 'rec_deliv_report_2 step2.2'}, log_level)
    rescue
      result = {:code => 505505, :result => 'Error', :body => {:res_body => 'Error communication with crm'}}
    end

    internal_func.printer_texter({:mess => 'rec_deliv_report_2 step3'}, log_level)
    if result[:body][:res_body] == ''
      internal_func.printer_texter({:mess => 'rec_deliv_report_2 step4'}, log_level)
      output_params = {'code': 200, 'result': 'Data processed', 'body': {'answer': {'code': 200, 'status': 'Success'}, 'sender': {'ip_src': ip_src, 'ip_real': ip_real, 'ip_vip': ip_vip}}}
      internal_func.printer_texter({:mess => 'rec_deliv_report_2 step5'}, log_level)
    elsif result[:code] == 505505
      internal_func.printer_texter({:mess => 'rec_deliv_report_2 step5.1'}, log_level)
      output_params = {'code': 505, 'result': 'Data processed', 'body': {'answer': {'code': 505, 'status': 'Error communicate with dabrabyt'}, 'sender': {'ip_src': ip_src, 'ip_real': ip_real, 'ip_vip': ip_vip}}}
      internal_func.printer_texter({:mess => 'rec_deliv_report_2 step5.2'}, log_level)
    else
      internal_func.printer_texter({:mess => 'rec_deliv_report_2 step6'}, log_level)
      output_params = {'code': 202, 'result': "CRM returned error #{result[:body][:res_body]['GetReportsResult'].to_s}", 'body': {'answer': {'code': 200, 'status': 'Success'}, 'sender': {'ip_src': ip_src, 'ip_real': ip_real, 'ip_vip': ip_vip}}}
      internal_func.printer_texter({:mess => 'rec_deliv_report_2 step7'}, log_level)
    end
  rescue
    output_params = {'code': 500, 'result': 'MhubFunctions_2.rec_deliv_report_2: Unknown SDK error', 'body': {'answer': {}, 'sender': {'ip_src': ip_src, 'ip_real': ip_real, 'ip_vip': ip_vip}}}
    telegram_connector.telegram_message(output_params)
  end
  internal_func.printer_texter({:input => input_params, :output => output_params, :hub_resp => hub_resp, :procedure => 'Mhub_2.recieve_delivery_report'}, log_level)
  output_params
end