Class: ActionSms::ConnectionAdapters::SMSGlobalAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActionSms::ConnectionAdapters::SMSGlobalAdapter
- 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 Attribute Summary collapse
-
#service_url ⇒ Object
readonly
Returns the value of attribute service_url.
Instance Method Summary collapse
- #authenticate(params) ⇒ Object
- #deliver(sms) ⇒ Object
- #delivery_request_successful?(gateway_response) ⇒ Boolean
-
#initialize(config = {}) ⇒ SMSGlobalAdapter
constructor
:nodoc:.
- #message_id(data) ⇒ Object
- #message_text(params) ⇒ Object
- #sender(params) ⇒ Object
- #status(delivery_receipt) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ SMSGlobalAdapter
:nodoc:
31 32 33 34 35 36 |
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 31 def initialize(config = {}) #:nodoc: @config = config.dup service_uri = URI.join(SERVICE_HOST, SERVICE_PATH) service_uri.scheme = config[:use_ssl] ? "https" : "http" @service_url = service_uri.to_s end |
Instance Attribute Details
#service_url ⇒ Object (readonly)
Returns the value of attribute service_url.
29 30 31 |
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 29 def service_url @service_url end |
Instance Method Details
#authenticate(params) ⇒ Object
61 62 63 |
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 61 def authenticate(params) params.delete("userfield") == @config[:authentication_key] end |
#deliver(sms) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 69 def deliver(sms) 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 || "") } 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, params) end |
#delivery_request_successful?(gateway_response) ⇒ Boolean
65 66 67 |
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 65 def delivery_request_successful?(gateway_response) gateway_response =~ /^OK/ end |
#message_id(data) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 38 def (data) = "SMSGlobalMsgID:" if data.is_a?(Hash) = data["msgid"] + if elsif data.is_a?(String) match = /#{}\d+/.match(data) match[0] if match end end |
#message_text(params) ⇒ Object
53 54 55 |
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 53 def (params) params["msg"] end |
#sender(params) ⇒ Object
57 58 59 |
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 57 def sender(params) params["from"] end |
#status(delivery_receipt) ⇒ Object
49 50 51 |
# File 'lib/action_sms_gateways/connection_adapters/sms_global.rb', line 49 def status(delivery_receipt) delivery_receipt["dlrstatus"] end |