lib/imperituroard/projects/mhub/sk.rb in imperituroard-0.5.7 vs lib/imperituroard/projects/mhub/sk.rb in imperituroard-0.5.8

- old
+ new

@@ -1,18 +1,20 @@ require 'imperituroard/projects/iot/internal_functions' +require 'imperituroard/projects/mhub/subs/dabrab/dabrab_proced' class Sksk_2 - attr_accessor :sk_url, :sk_url_broadcast, :sk_login, :sk_password, :internal_func, :telegram_connector + attr_accessor :sk_url, :sk_url_broadcast, :sk_login, :sk_password, :internal_func, :telegram_connector, :dabrab_add_func def initialize(sk_url, sk_login, sk_password, sk_url_broadcast, telegram_api_url, telegram_chat_id) @sk_url = sk_url @sk_login = sk_login @sk_password = sk_password @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 sk_send_sms_one(msisdn, callback_url, text, alphaname) @@ -80,54 +82,53 @@ 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 - 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'}) - 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.basic_auth sk_login, sk_password + req["Content-Type"] = "application/json" + req["Accept"] = "application/json" - 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)}} - 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": { - "text": text, - "ttl": 60, - # "img": "http://olddogs.org/logo.png", - # "caption": "Old Dogs need you!", - # "action": "http://olddogs.org", - }, - } - } - 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 @@ -147,58 +148,59 @@ begin thr_sk_send_viber_sms_one = Thread.new do - uri = URI(sk_url) - #8 - client id + viber_mess_ans = dabrab_add_func.dabrabyt_text_field_parse(viber_txt) - 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'}) + if viber_mess_ans[:code] == 200 + uri = URI(sk_url) + #8 - client id - req.basic_auth sk_login, sk_password + 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 - 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": { - "text": viber_txt, - "ttl": 60, - # "img": "http://olddogs.org/logo.png", - # "caption": "Old Dogs need you!", - # "action": "http://olddogs.org", - }, - } - } + req["Content-Type"] = "application/json" + req["Accept"] = "application/json" - req.body = request_message.to_json - res = https.request(req) + 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] + } + } - 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)}} + 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 @@ -279,48 +281,53 @@ request_message = {} begin thr_sk_send_viber_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'}) + viber_mess_ans = dabrab_add_func.dabrabyt_text_field_parse(text) - req["Content-Type"] = "application/json" - req["Accept"] = "application/json" + if viber_mess_ans[:code] == 200 + uri = URI(sk_url_broadcast) + #8 - client id - req.basic_auth sk_login, sk_password + 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" - # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] - request_message = { - "recipients": msisdn_list, - "callback_url": callback_url, - "tag": "Dabrab_custom_api_1", - "channels": [ - "viber" - ], - "channel_options": { - "viber": { - "text": text, - "ttl": 60 - } - } - } + req.basic_auth sk_login, sk_password - 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)}} + # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] + request_message = { + "recipients": msisdn_list, + "callback_url": callback_url, + "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) @@ -335,53 +342,60 @@ output_params = {} request_message = {} begin thr_sk_send_viber_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'}) + viber_mess_ans = dabrab_add_func.dabrabyt_text_field_parse(viber_text) - req.basic_auth sk_login, sk_password + if viber_mess_ans[:code] == 200 + uri = URI(sk_url_broadcast) + #8 - client id - req["Content-Type"] = "application/json" - req["Accept"] = "application/json" + 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'}) - # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] - request_message = { - "recipients": msisdn_list, - "callback_url": callback_url, - "tag": "Dabrab_custom_api_1", - "channels": [ - "viber", - "sms" - ], - "channel_options": { - "sms": { - "alpha_name": alphaname, - "text": sms_text, - "ttl": 60 - }, - "viber": { - "text": viber_text, - "ttl": 60 - } - } - } + req.basic_auth sk_login, sk_password - 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)}} + req["Content-Type"] = "application/json" + req["Accept"] = "application/json" + + # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] + request_message = { + "recipients": msisdn_list, + "callback_url": callback_url, + "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 \ No newline at end of file