Class: Cellular::Backends::LinkMobility
- Defined in:
- lib/cellular/backends/link_mobility.rb
Overview
LinkMobility backend (www.linkmobility.com)
Constant Summary collapse
- BASE_URL =
Documentation: www.linkmobility.com/developers/
'https://wsx.sp247.net/'.freeze
- HTTP_HEADERS =
{ 'Content-Type' => 'application/json; charset=utf-8', }.freeze
Class Method Summary collapse
- .deliver(options = {}) ⇒ Object
- .link_mobility_config ⇒ Object
- .parse_response(response) ⇒ Object
- .payload(options) ⇒ Object
- .recipients_batch(options) ⇒ Object
- .sms_url ⇒ Object
Methods inherited from Backend
Class Method Details
.deliver(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cellular/backends/link_mobility.rb', line 14 def self.deliver( = {}) request_queue = {} recipients_batch().each_with_index do |recipient, index| [:batch] = recipient request = HTTParty.post( sms_url, body: payload(), basic_auth: link_mobility_config, headers: HTTP_HEADERS ) request_queue[index] = { recipient: [:batch], response: parse_response(request) } end # return first response for now request_queue[0][:response] end |
.link_mobility_config ⇒ Object
46 47 48 49 50 51 |
# File 'lib/cellular/backends/link_mobility.rb', line 46 def self.link_mobility_config { username: Cellular.config.username, password: Cellular.config.password } end |
.parse_response(response) ⇒ Object
36 37 38 39 40 |
# File 'lib/cellular/backends/link_mobility.rb', line 36 def self.parse_response(response) [ response['description'] ] end |
.payload(options) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/cellular/backends/link_mobility.rb', line 53 def self.payload() { source: [:sender], destination: [:batch], userData: [:message], platformId: 'COMMON_API', platformPartnerId: Cellular.config.partner_id, }.to_json end |
.recipients_batch(options) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/cellular/backends/link_mobility.rb', line 63 def self.recipients_batch() if [:recipients].blank? [[:recipient]] else [:recipients] end end |
.sms_url ⇒ Object
42 43 44 |
# File 'lib/cellular/backends/link_mobility.rb', line 42 def self.sms_url "#{BASE_URL}sms/send" end |