Class: SmsKit::Mobimex

Inherits:
Provider show all
Defined in:
lib/sms_kit/providers/mobimex.rb

Constant Summary collapse

ROUTE_AFRICA =
'AFRIKA'.freeze
HTTP_ENDPOINT =
'https://gate.quadra-mm.com/feed/http.asp'
RESPONSE_FORMATS =
{ text: 0, xml: 1, json: 2 }

Constants included from HTTP

HTTP::USER_AGENT

Instance Attribute Summary

Attributes inherited from Provider

#data, #error_code, #error_message

Instance Method Summary collapse

Methods inherited from Provider

deliver, #initialize

Methods included from HTTP

#connection, #get, #uri

Methods included from Config

included

Constructor Details

This class inherits a constructor from SmsKit::Provider

Instance Method Details

#deliverObject

response json looks like this: Feed”,“result”:1,“description”:“DONE: SMS is in the send queue.”



14
15
16
17
18
19
20
21
22
# File 'lib/sms_kit/providers/mobimex.rb', line 14

def deliver
  response = post params
  if response.body.length > 1
    json = JSON.parse(response.body)
    json['result'].to_i == 1
  else
    raise DeliveryError, "Delivery failed (#{response.body})"
  end
end

#paramsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sms_kit/providers/mobimex.rb', line 24

def params
  {
    user:        config.username,
    pass:        config.password,
    dlr:         data[:dlr_profile] || 0,
    xml:         response_format,
    from_number: data[:from] || config.sender,
    number:      data[:to],
    message:     data[:text],
    idd:         data[:idd] || 0,
    im:          data[:im] || 0,
    route:       data[:route] || config.route,
    type:        data[:type] || 'text'
  }.reject { |k, v| v.nil? }
end

#post(payload) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/sms_kit/providers/mobimex.rb', line 44

def post payload
  connection.post do |req|
    req.url uri.path
    req.headers['Content-Type'] = 'application/json'
    req.body = payload.to_json
  end
end

#response_formatObject



40
41
42
# File 'lib/sms_kit/providers/mobimex.rb', line 40

def response_format
  RESPONSE_FORMATS.fetch data[:format], :json
end