Class: ActionSms::Base
- Inherits:
-
Object
- Object
- ActionSms::Base
- Defined in:
- lib/action_sms/base.rb
Constant Summary collapse
- @@connection =
nil
Class Method Summary collapse
-
.connected? ⇒ Boolean
Returns true if a connection that’s accessible to this class has already been opened.
-
.connection ⇒ Object
Returns the connection currently associated with the class.
-
.connection=(spec) ⇒ Object
Set the gateway connection for the class.
-
.establish_connection(config) ⇒ Object
Establishes the connection to the SMS gateway.
Class Method Details
.connected? ⇒ Boolean
Returns true if a connection that’s accessible to this class has already been opened.
9 10 11 |
# File 'lib/action_sms/base.rb', line 9 def connected? return !@@connection.nil? end |
.connection ⇒ Object
Returns the connection currently associated with the class. This can also be used to “borrow” the connection to do work that is specific to a particular SMS gateway.
16 17 18 19 |
# File 'lib/action_sms/base.rb', line 16 def connection raise ConnectionNotEstablished unless @@connection return @@connection end |
.connection=(spec) ⇒ Object
Set the gateway connection for the class.
22 23 24 25 |
# File 'lib/action_sms/base.rb', line 22 def connection=(spec) #:nodoc: raise ConnectionNotEstablished unless spec @@connection = spec end |
.establish_connection(config) ⇒ Object
Establishes the connection to the SMS gateway. Accepts a hash as input where the :adapter key must be specified with the name of a gateway adapter (in lower-case)
ActionSms::Base.establish_connection(
:adapter => "clickatell",
:username => "myusername",
:password => "mypassword"
:api_id => "myapiid"
)
Also accepts keys as strings (for parsing from YAML, for example).
The exceptions AdapterNotSpecified, AdapterNotFound, and ArgumentError may be returned.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/action_sms/base.rb', line 42 def establish_connection(config) unless config.key?(:adapter) raise AdapterNotSpecified, "#{config} adapter is not configured" end adapter_method = "#{config[:adapter]}_connection" unless respond_to?(adapter_method) raise AdapterNotFound, "configuration specifies nonexistent #{config[:adapter]} adapter" end self.connection = self.send(adapter_method, config) end |