require 'imperituroard/projects/iot/internal_functions' require 'imperituroard/projects/mhub/subs/dabrab/dabrab_proced' require 'date' class Sksk_2 attr_accessor :sk_url, :sk_url_broadcast, :sk_login, :sk_password, :internal_func, :telegram_connector, :dabrab_add_func, :log_level def initialize(sk_url, sk_login, sk_password, sk_url_broadcast, telegram_api_url, telegram_chat_id, log_level) @sk_url = sk_url @sk_login = sk_login @sk_password = sk_password @log_level = log_level @internal_func = InternalFunc.new @sk_url_broadcast = sk_url_broadcast @telegram_connector = Telegram_2.new(telegram_api_url, telegram_chat_id) @dabrab_add_func = Dabrab.new end def get_start_date(addit_min) date_b = Time.now (date_b + addit_min * 60).strftime("%Y-%m-%d %H:%M:%S") end def sk_send_sms_one(msisdn, callback_url, text, alphaname) input_params = {:msisdn => msisdn, :callback_url => callback_url, :text => text, :alphaname => alphaname} output_params = {} request_message = {} begin thr_sk_send_sms_one = Thread.new do uri = URI(sk_url) #8 - client id https = Net::HTTP.new(uri.host, uri.port) https.use_ssl=true https.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.path, initheader = {:"Content-Type" => 'application/json'}) req.basic_auth sk_login, sk_password req["Content-Type"] = "application/json" req["Accept"] = "application/json" request_message = { "phone_number": msisdn, #"extra_id": "4232j4h89932kjhs", "callback_url": callback_url, #"start_time": "2019-08-16 09:59:10", "tag": "Dabrab_custom_api_1", "channels": [ "sms" ], "channel_options": { "sms": { "text": text, "alpha_name": alphaname, "ttl": 600 } } } req.body = request_message.to_json res = https.request(req) output_params = {:code => 200, :result => "Sksk_2.sk_send_sms_one: Request processed", :body => {:request_message => request_message, :res_code => res.code, :res_body => JSON.parse(res.body.to_s)}} end thr_sk_send_sms_one.join rescue output_params = {:code => 500, :result => "Sksk_2.sk_send_sms_one: Something wrong", :body => {:request_message => request_message}} telegram_connector.telegram_message(output_params) end internal_func.printer_texter({:input => input_params, :output => output_params, :procedure => "Sksk_1.sk_send_sms_one"}, log_level) output_params end def sk_send_viber_one(msisdn, callback_url, text) input_params = {:msisdn => msisdn, :callback_url => callback_url, :text => text} output_params = {} request_message = {} begin thr_sk_send_viber_one = Thread.new do viber_mess_ans = dabrab_add_func.dabrabyt_text_field_parse(text) if viber_mess_ans[:code] == 200 uri = URI(sk_url) #8 - client id https = Net::HTTP.new(uri.host, uri.port) https.use_ssl=true https.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.path, initheader = {:"Content-Type" => 'application/json'}) req.basic_auth sk_login, sk_password req["Content-Type"] = "application/json" req["Accept"] = "application/json" request_message = { "phone_number": msisdn, #"extra_id": "4232j4h89932kjhs", "callback_url": callback_url, #"start_time": "2019-08-16 09:59:10", "tag": "Dabrab_custom_api_1", "channels": [ "viber" ], "channel_options": { "viber": viber_mess_ans[:body][:to_sk_format] } } req.body = request_message.to_json res = https.request(req) output_params = {:code => 200, :result => "Sksk_2.sk_send_viber_one: Request processed", :body => {:request_message => request_message, :res_code => res.code, :res_body => JSON.parse(res.body.to_s)}} else output_params = {:code => 508, :result => "Sksk_2.sk_send_viber_one: Something wrong with dabrabyt_text_field_parse"} end end thr_sk_send_viber_one.join rescue output_params = {:code => 500, :result => "Sksk_2.sk_send_viber_one: Something wrong"} telegram_connector.telegram_message(output_params) end internal_func.printer_texter({:input => input_params, :output => output_params, :procedure => "Sksk_2.sk_send_viber_one"}, log_level) output_params end def sk_send_viber_sms_one(msisdn, callback_url, sms_text, viber_txt, alphaname) input_params = {:msisdn => msisdn, :callback_url => callback_url, :sms_text => sms_text, :viber_txt => viber_txt, :alphaname => alphaname} output_params = {} request_message = {} begin thr_sk_send_viber_sms_one = Thread.new do viber_mess_ans = dabrab_add_func.dabrabyt_text_field_parse(viber_txt) if viber_mess_ans[:code] == 200 uri = URI(sk_url) #8 - client id https = Net::HTTP.new(uri.host, uri.port) https.use_ssl=true https.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.path, initheader = {:"Content-Type" => 'application/json'}) req.basic_auth sk_login, sk_password req["Content-Type"] = "application/json" req["Accept"] = "application/json" request_message = { "phone_number": msisdn, #"extra_id": "4232j4h89932kjhs", "callback_url": callback_url, #"start_time": "2019-08-16 09:59:10", "tag": "Dabrab_custom_api_1", "channels": [ "viber", "sms" ], "channel_options": { "sms": { "text": sms_text, "alpha_name": alphaname, "ttl": 600 }, "viber": viber_mess_ans[:body][:to_sk_format] } } req.body = request_message.to_json res = https.request(req) output_params = {:code => 200, :result => "Sksk_2.sk_send_viber_sms_one: Request processed", :body => {:request_message => request_message, :res_code => res.code, :res_body => JSON.parse(res.body.to_s)}} else output_params = {:code => 508, :result => "Sksk_2.sk_send_viber_sms_one: Something wrong with dabrabyt_text_field_parse"} end end thr_sk_send_viber_sms_one.join rescue output_params = {:code => 500, :result => "Sksk_2.sk_send_viber_sms_one: Something wrong"} telegram_connector.telegram_message(output_params) end internal_func.printer_texter({:input => input_params, :output => output_params, :procedure => "Sksk_2.sk_send_viber_sms_one"}, log_level) output_params end def sk_send_sms_list(msisdn_list, callback_url, text, alphaname, time_pause_minutes=1) input_params = {:msisdn_list => msisdn_list, :callback_url => callback_url, :text => text, :alphaname => alphaname} output_params = {} request_message = {} begin thr_sk_send_sms_list = Thread.new do uri = URI(sk_url_broadcast) #8 - client id https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.path, initheader = {:"Content-Type" => 'application/json'}) req.basic_auth sk_login, sk_password req["Content-Type"] = "application/json" req["Accept"] = "application/json" # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] request_message = { "recipients": msisdn_list, "callback_url": callback_url, "start_time": get_start_date(time_pause_minutes), "tag": "Dabrab_custom_api_1", "channels": [ "sms" ], "channel_options": { "sms": { "alpha_name": alphaname, "text": text, "ttl": 60 } } } req.body = request_message.to_json res = https.request(req) output_params = {:code => 200, :result => "Sksk_2.sk_send_sms_list: Request processed", :body => {:request_message => request_message, :res_code => res.code, :res_body => JSON.parse(res.body.to_s)}} end thr_sk_send_sms_list.join rescue output_params = {:code => 500, :result => "Sksk_2.sk_send_sms_list: Something wrong"} telegram_connector.telegram_message(output_params) end internal_func.printer_texter({:input => input_params, :output => output_params, :procedure => "Sksk_2.sk_send_sms_list"}, log_level) output_params end def sk_send_viber_list(msisdn_list, callback_url, text, time_pause_minutes) input_params = {:msisdn_list => msisdn_list, :callback_url => callback_url, :text => text} output_params = {} request_message = {} begin thr_sk_send_viber_list = Thread.new do viber_mess_ans = dabrab_add_func.dabrabyt_text_field_parse(text) if viber_mess_ans[:code] == 200 uri = URI(sk_url_broadcast) #8 - client id https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.path, initheader = {:"Content-Type" => 'application/json'}) req["Content-Type"] = "application/json" req["Accept"] = "application/json" req.basic_auth sk_login, sk_password # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] request_message = { "recipients": msisdn_list, "callback_url": callback_url, "start_time": get_start_date(time_pause_minutes), "tag": "Dabrab_custom_api_1", "channels": [ "viber" ], "channel_options": { "viber": viber_mess_ans[:body][:to_sk_format] } } req.body = request_message.to_json res = https.request(req) output_params = {:code => 200, :result => "Sksk_2.sk_send_viber_list: Request processed", :body => {:request_message => request_message, :res_code => res.code, :res_body => JSON.parse(res.body.to_s)}} else output_params = {:code => 508, :result => "Sksk_2.sk_send_viber_list: Something wrong with dabrabyt_text_field_parse"} end end thr_sk_send_viber_list.join rescue output_params = {:code => 500, :result => "Sksk_2.sk_send_viber_list: Something wrong"} telegram_connector.telegram_message(output_params) end internal_func.printer_texter({:input => input_params, :output => output_params, :procedure => "Sksk_2.sk_send_viber_list"}, log_level) output_params end def sk_send_viber_sms_list(msisdn_list, callback_url, sms_text, viber_text, alphaname, time_pause_minutes) input_params = {:msisdn_list => msisdn_list, :callback_url => callback_url, :sms_text => sms_text, :viber_text => viber_text, :alphaname => alphaname} output_params = {} request_message = {} begin thr_sk_send_viber_sms_list = Thread.new do viber_mess_ans = dabrab_add_func.dabrabyt_text_field_parse(viber_text) if viber_mess_ans[:code] == 200 uri = URI(sk_url_broadcast) #8 - client id https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true https.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.path, initheader = {:"Content-Type" => 'application/json'}) req.basic_auth sk_login, sk_password req["Content-Type"] = "application/json" req["Accept"] = "application/json" # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] request_message = { "recipients": msisdn_list, "callback_url": callback_url, "start_time": get_start_date(time_pause_minutes), "tag": "Dabrab_custom_api_1", "channels": [ "viber", "sms" ], "channel_options": { "sms": { "alpha_name": alphaname, "text": sms_text, "ttl": 60 }, "viber": viber_mess_ans[:body][:to_sk_format] } } req.body = request_message.to_json res = https.request(req) output_params = {:code => 200, :result => "Sksk_2.sk_send_viber_sms_list: Request processed", :body => {:request_message => request_message, :res_code => res.code, :res_body => JSON.parse(res.body.to_s)}} else output_params = {:code => 508, :result => "Sksk_2.sk_send_viber_sms_list: Something wrong with dabrabyt_text_field_parse"} end end thr_sk_send_viber_sms_list.join rescue output_params = {:code => 500, :result => "Sksk_2.sk_send_viber_sms_list: Something wrong"} telegram_connector.telegram_message(output_params) end internal_func.printer_texter({:input => input_params, :output => output_params, :procedure => "Sksk_2.sk_send_viber_sms_list"}, log_level) output_params end end