Class: ActionSmser::DeliveryMethods::Nexmo
- Inherits:
-
SimpleHttp
- Object
- SimpleHttp
- ActionSmser::DeliveryMethods::Nexmo
- Defined in:
- lib/action_smser/delivery_methods/nexmo.rb
Overview
Very simple implementation of http request to gateway. Options used are server, use_ssl, username, password overwrite deliver_path(sms, options) with your own if you have different type of path
Class Method Summary collapse
- .deliver(sms) ⇒ Object
- .deliver_path(sms, to, options) ⇒ Object
-
.process_delivery_report(params) ⇒ Object
Callback message status handling This has to return array of hashes.
Methods inherited from SimpleHttp
Class Method Details
.deliver(sms) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/action_smser/delivery_methods/nexmo.rb', line 11 def self.deliver(sms) = sms.[:nexmo] || {} = .dup [:server] = 'rest.nexmo.com' [:use_ssl] = true [:status_report_req] ||= sms.[:save_delivery_reports] sms.delivery_info = [] sms.to_numbers_array.each do |to| deliver_path = self.deliver_path(sms, to, ) response = self.deliver_http_request(sms, , deliver_path) logger.info "Nexmo delivery http ||| #{deliver_path} ||| #{response.inspect}" logger.info response.body if !response.blank? sms.delivery_info.push(response) result = JSON.parse(response.body)["messages"].first # Results include sms_id or error code in each line if sms.[:save_delivery_reports] dr = ActionSmser::DeliveryReport.build_from_sms(sms, to, result["message-id"]) if result["status"].to_i > 0 dr.status = "SENT_ERROR_#{result["status"]}" dr.log += "nexmo_error: #{result["error-text"]}" end dr.save sms.delivery_reports.push(dr) end end sms.[:save_delivery_reports] ? sms.delivery_reports : sms.delivery_info end |
.deliver_path(sms, to, options) ⇒ Object
47 48 49 |
# File 'lib/action_smser/delivery_methods/nexmo.rb', line 47 def self.deliver_path(sms, to, ) "/sms/json?username=#{[:username]}&password=#{[:password]}&ttl=#{sms.ttl_to_i*1000}&status-report-req=#{[:status_report_req]}&from=#{sms.from_encoded}&to=#{to}&text=#{sms.body_escaped}" end |
.process_delivery_report(params) ⇒ Object
Callback message status handling This has to return array of hashes. In hash msg_id is the key and other params are updated to db
53 54 55 56 57 58 59 |
# File 'lib/action_smser/delivery_methods/nexmo.rb', line 53 def self.process_delivery_report(params) processable_array = [] if msg_id = params["messageId"] processable_array << {'msg_id' => params["messageId"], 'status' => params['status']} end return processable_array end |