Class: ActionSms::ConnectionAdapters::TropoAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActionSms::ConnectionAdapters::TropoAdapter
- Defined in:
- lib/action_sms_gateways/connection_adapters/tropo.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://api.tropo.com/1.0"
- SERVICE_PATH =
"sessions"
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 = {}) ⇒ TropoAdapter
constructor
:nodoc:.
-
#message_id(data) ⇒ Object
message_id and status are for text message delivery receipts only Tropo does not yet send text message delivery receipts, so these two methods are here for testing purposes.
- #message_text(params) ⇒ Object
- #sender(params) ⇒ Object
- #status(delivery_receipt) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ TropoAdapter
:nodoc:
32 33 34 35 36 37 |
# File 'lib/action_sms_gateways/connection_adapters/tropo.rb', line 32 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.
27 28 29 |
# File 'lib/action_sms_gateways/connection_adapters/tropo.rb', line 27 def service_url @service_url end |
Instance Method Details
#authenticate(params) ⇒ Object
62 63 64 |
# File 'lib/action_sms_gateways/connection_adapters/tropo.rb', line 62 def authenticate(params) params.delete("authentication_key") == @config[:authentication_key] end |
#deliver(sms) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/action_sms_gateways/connection_adapters/tropo.rb', line 66 def deliver(sms) = Tropo::Message.new .to = sms.recipient .text = sms.body || "" .from = sms.from if sms.respond_to?(:from) .token = @config[:outgoing_token] send_http_request(@service_url, .request_xml) end |
#delivery_request_successful?(gateway_response) ⇒ Boolean
50 51 52 |
# File 'lib/action_sms_gateways/connection_adapters/tropo.rb', line 50 def delivery_request_successful?(gateway_response) gateway_response =~ /\<success\>true\<\/success\>/ end |
#message_id(data) ⇒ Object
message_id and status are for text message delivery receipts only Tropo does not yet send text message delivery receipts, so these two methods are here for testing purposes
42 43 44 |
# File 'lib/action_sms_gateways/connection_adapters/tropo.rb', line 42 def (data) data.is_a?(Hash) ? data["message_id"] : data end |
#message_text(params) ⇒ Object
54 55 56 |
# File 'lib/action_sms_gateways/connection_adapters/tropo.rb', line 54 def (params) session(params)["initial_text"] end |
#sender(params) ⇒ Object
58 59 60 |
# File 'lib/action_sms_gateways/connection_adapters/tropo.rb', line 58 def sender(params) session(params)["from"]["id"] end |
#status(delivery_receipt) ⇒ Object
46 47 48 |
# File 'lib/action_sms_gateways/connection_adapters/tropo.rb', line 46 def status(delivery_receipt) delivery_receipt["status"] end |