class Dabrab def num_formatter(infobip_msisdn, extra_id) #[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}] # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] converted_msisdn_list = [] for g in infobip_msisdn begin converted_msisdn_list.append({"phone_number": g["to"]["phoneNumber"].to_i, "extra_id": extra_id}) rescue p "failed: #{g.to_s}" end end p converted_msisdn_list converted_msisdn_list end def send_responce_formatter(hub_answer) input = {:hub_answer => hub_answer} mess_to_recip = {} messages_sect = [] example = { "bulkId": "2034072219640523072", "messages": [{ "to": "41793026727", "status": { "groupId": 1, "groupName": "PENDING", "id": 26, "name": "MESSAGE_ACCEPTED", "description": "Message sent to next instance" }, "messageId": "2250be2d4219-3af1-78856-aabe-1362af1edfd2" } ] } p "send_responce_formatter(hub_answer)" p hub_answer for a in hub_answer[:body][:res_body]["messages"] s1 = {"to": {"phoneNumber": a["phone_number"]}, "status": {"groupId": 1, "groupName": "PENDING", "id": 26, "name": "MESSAGE_ACCEPTED", "description": "Message sent to next instance"}, "messageId": a["message_id"]} messages_sect.append(s1) end p messages_sect mess_to_recip = {"bulkId": "00000000-0000-0000-0000-000000000000", "messages": messages_sect} {:code => 200, :result => "Data processed", :body => {:mess_to_recip => mess_to_recip}} end def delivery_report_transform(hub_report) #{"number"=>"375297116638", "time"=>1588673492000, "status"=>2, "substatus"=>23, "msg_status"=>23033, "message_id"=>"486649ba-a573-4ee9-8f58-018ed20ca6fd", "extra_id"=>"444/0/ServiceModel/ScGetReports.svc/GetReports", "sent_via"=>"viber", "controller"=>"reports", "action"=>"delivery", "report"=>{"number"=>"375297116638", "time"=>1588673492000, "status"=>2, "substatus"=>23, "msg_status"=>23033, "message_id"=>"486649ba-a573-4ee9-8f58-018ed20ca6fd", "extra_id"=>"444/0/ServiceModel/ScGetReports.svc/GetReports", "sent_via"=>"viber"}} report_to_recip = { "results": [ { # "bulkId": "9a410cb0-091e-41cf-a640-5d37bee14d9a", "messageId": hub_report["report"]["message_id"], "to": hub_report["report"]["number"], # "sentAt": "2020-05-05T20:00:00.000+0000", # "doneAt": "2020-05-05T20:00:00.000+0000", "status": { "groupId": 3, "groupName": "DELIVERED", "id": 5, "name": "DELIVERED_TO_HANDSET", "description": "Message delivered to handset" }, "error": { "groupId": 0, "groupName": "Ok", "id": 0, "name": "NO_ERROR", "description": "No Error", "permanent": false } } ] } {:code => 200, :result => "Data processed", :body => {:report_to_recip => report_to_recip}} end end