Class: Cellular::Backends::LinkMobility

Inherits:
Backend
  • Object
show all
Defined in:
lib/cellular/backends/link_mobility.rb

Overview

LinkMobility backend (www.linkmobility.com)

Constant Summary collapse

BASE_URL =
'https://wsx.sp247.net/'.freeze
HTTP_HEADERS =
{
  'Content-Type' => 'application/json; charset=utf-8',
}.freeze

Class Method Summary collapse

Methods inherited from Backend

receive

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(options = {})
  request_queue = {}
  recipients_batch(options).each_with_index do |recipient, index|
    options[:batch] = recipient

    request = HTTParty.post(
      sms_url,
      body: payload(options),
      basic_auth: link_mobility_config,
      headers: HTTP_HEADERS
    )

    request_queue[index] = {
      recipient: options[:batch],
      response: parse_response(request)
    }
  end

  # return first response for now
  request_queue[0][:response]
end


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(options)
  {
    source: options[:sender],
    destination: options[:batch],
    userData: options[: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(options)
  if options[:recipients].blank?
    [options[:recipient]]
  else
    options[:recipients]
  end
end

.sms_urlObject



42
43
44
# File 'lib/cellular/backends/link_mobility.rb', line 42

def self.sms_url
  "#{BASE_URL}sms/send"
end