Class: ActionSms::ConnectionAdapters::SMSGlobalAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/action_sms_gateways/connection_adapters/sms_global.rb

Overview

All the concrete gateway adapters follow the interface laid down in this class. You can use this interface directly by borrowing the gateway connection from the Base with Base.connection.

Constant Summary collapse

SERVICE_HOST =
"http://smsglobal.com.au"
SERVICE_PATH =
"http-api.php"

Instance Method Summary collapse

Constructor Details

#initialize(logger = nil, config = {}) ⇒ SMSGlobalAdapter

:nodoc:



19
20
21
22
23
24
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 19

def initialize(logger = nil, config = {}) #:nodoc:
  super(logger)
  @config = config.dup
  @service_url = URI.join(SERVICE_HOST, SERVICE_PATH)
  @service_url.scheme = config[:use_ssl] ? "https" : "http"
end

Instance Method Details

#authenticate(params) ⇒ Object



49
50
51
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 49

def authenticate(params)
  params.delete("userfield") == @config[:authentication_key]
end

#deliver(sms) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 53

def deliver(sms)
  params = {
    :action   => 'sendsms',
    :user     => @config[:user],
    :password => @config[:password],
    :maxsplit => 3,
    :from => (sms.from || "reply2email"),
    :to       => sms.recipients,
    :text     => sms.body
  }
  if sms.respond_to?(:userfield)
    userfield = sms.userfield
  elsif @config[:authentication_key]
    userfield = @config[:authentication_key]
  end
  params.merge!(
    :userfield => userfield
  ) if userfield
  send_http_request(@service_url.to_s, params)
end

#message_id(data) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 26

def message_id(data)
  sms_global_message_id_prefix = "SMSGlobalMsgID:"
  if data.is_a?(Hash)
    message_id = data["msgid"]
    sms_global_message_id_prefix + message_id if message_id
  elsif data.is_a?(String)
    match = /#{sms_global_message_id_prefix}\d+/.match(data)
    match[0] if match
  end
end

#message_text(params) ⇒ Object



41
42
43
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 41

def message_text(params)
  params["msg"]
end

#sender(params) ⇒ Object



45
46
47
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 45

def sender(params)
  params["from"]
end

#status(delivery_receipt) ⇒ Object



37
38
39
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 37

def status(delivery_receipt)
  delivery_receipt["dlrstatus"]
end