Class: ActionSms::ConnectionAdapters::SMSGlobalAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/action_sms/connection_adapters/sms_global_adapter.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_URL =
"http://smsglobal.com.au/http-api.php"

Instance Method Summary collapse

Methods inherited from AbstractAdapter

#authenticate, #authentication_key, #authentication_key=, #configuration, #configuration=, #initialize, #use_ssl, #use_ssl=

Constructor Details

This class inherits a constructor from ActionSms::ConnectionAdapters::AbstractAdapter

Instance Method Details

#deliver(sms, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/action_sms/connection_adapters/sms_global_adapter.rb', line 27

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

#delivery_request_successful?(gateway_response) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/action_sms/connection_adapters/sms_global_adapter.rb', line 43

def delivery_request_successful?(gateway_response)
  gateway_response =~ /^OK/
end

#message_id(data) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/action_sms/connection_adapters/sms_global_adapter.rb', line 47

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}\s*(\d+)/.match(data)
    sms_global_message_id_prefix + $1 if $1
  end
end

#message_text(params) ⇒ Object



58
59
60
# File 'lib/action_sms/connection_adapters/sms_global_adapter.rb', line 58

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

#sender(params) ⇒ Object



62
63
64
# File 'lib/action_sms/connection_adapters/sms_global_adapter.rb', line 62

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

#service_urlObject



66
67
68
# File 'lib/action_sms/connection_adapters/sms_global_adapter.rb', line 66

def service_url
  super(SERVICE_URL)
end

#status(delivery_receipt) ⇒ Object



70
71
72
# File 'lib/action_sms/connection_adapters/sms_global_adapter.rb', line 70

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