Class: Splat::Gateway
- Inherits:
-
Object
- Object
- Splat::Gateway
- Defined in:
- lib/splat/gateway.rb
Direct Known Subclasses
Constant Summary collapse
- @@vendor_implementations =
{}
- @@configuration =
nil
Instance Attribute Summary collapse
-
#vendor ⇒ Object
readonly
Returns the value of attribute vendor.
Class Method Summary collapse
Instance Method Summary collapse
- #config_option(option) ⇒ Object
- #configuration ⇒ Object
-
#initialize ⇒ Gateway
constructor
A new instance of Gateway.
- #required_config(options = []) ⇒ Object
-
#send_bulk_sms(message, numbers, options = {}) ⇒ Object
- Send bulk SMS message
-
The message.
- #send_bulk_sms_with_insertion(message, insertions = {}, options = {}) ⇒ Object
-
#send_sms(message, number, options = {}) ⇒ Object
Send an SMS.
Methods included from Utils
Methods included from Insertion
Constructor Details
Instance Attribute Details
#vendor ⇒ Object (readonly)
Returns the value of attribute vendor.
19 20 21 |
# File 'lib/splat/gateway.rb', line 19 def vendor @vendor end |
Class Method Details
.[](name) ⇒ Object
29 30 31 |
# File 'lib/splat/gateway.rb', line 29 def self.[](name) @@vendor_implementations[name.to_s] end |
.default_configuration ⇒ Object
33 34 35 |
# File 'lib/splat/gateway.rb', line 33 def self.default_configuration Configuration.instance.vendor end |
.inherited(subclass) ⇒ Object
25 26 27 |
# File 'lib/splat/gateway.rb', line 25 def self.inherited(subclass) @@vendor_implementations[subclass.name.downcase.split("::").last] = subclass end |
Instance Method Details
#config_option(option) ⇒ Object
41 42 43 |
# File 'lib/splat/gateway.rb', line 41 def config_option(option) Configuration.instance.vendor(@vendor)[option.to_s] end |
#configuration ⇒ Object
37 38 39 |
# File 'lib/splat/gateway.rb', line 37 def configuration Configuration.instance.vendor(@vendor) end |
#required_config(options = []) ⇒ Object
106 107 108 109 110 |
# File 'lib/splat/gateway.rb', line 106 def required_config( = []) .each do |option| raise SplatError.new("'#{option}' not define for '#{@vendor}' in config file") if self.configuration[option.to_s].blank? end end |
#send_bulk_sms(message, numbers, options = {}) ⇒ Object
Send bulk SMS
- message
-
The message. This will be automatically sanitized and url-encoded. This message can contain string insertions.
- number
-
Array of numbers in the Config::Splat.default_number_format
- options
-
The various options specified configure_options
In case the numbers do not match with string insertions, the default_insertion will be used. If use_default_insertion is set to false, then those numbers will be skipped.
Return Values
- Success
-
Return the id if the message was sent to the gateway. This not imply that the messages were delivered.
- Failure
-
Raise SplatGatewayError on failure with the relevant error message and error code.
Example: message => “Hello $1, hold on to your $2” numbers => [ ‘+91 9812345678’, ‘+1 4034832933’, ‘+44 123783218’] options =>
:insertions => { 1 => [ 'Smith', 'John Doe', 'Jane'],
2 => [ 'stocks', 'socks', 'skirt']
},
:default_insertion => { 1 => 'User', 2 => '' }
REVIEW:
:insertions => { '+91 981234565' => [ 'Smith', 'stocks'],
'+1 4034832933' => ['John Doe', 'socks'],
'+44 123783218' => ['Jane', 'skirt']
'+44 122342418' => ['Jane' ]
:default_insertion => { 1 => 'User', 2 => '' }
}
98 99 100 |
# File 'lib/splat/gateway.rb', line 98 def send_bulk_sms(, numbers, = {}) raise SplatGatewayImplError.new("Implement send_bulk_sms(message, numbers, options = {}) in #{self.class}") end |
#send_bulk_sms_with_insertion(message, insertions = {}, options = {}) ⇒ Object
102 103 104 |
# File 'lib/splat/gateway.rb', line 102 def send_bulk_sms_with_insertion(, insertions ={}, = {}) raise SplatGatewayImplError.new("Implement send_bulk_sms_with_insertion(message, insertions ={}, options = {}) in #{self.class}") end |
#send_sms(message, number, options = {}) ⇒ Object
Send an SMS.
- message
-
The message. This will be automatically sanitized and url-encoded.
- number
-
The number in Config::Splat.default_number_format
- options
-
The various options specified configure_options
Return Values
- Success
-
Return the id if the message was sent to the gateway. This not imply that the messages were delivered.
- Failure
-
Raise SplatGatewayError on failure with the relevant error message and error code.
Example: message => “Hello Smith, welcome to splat” number => ‘+91 9812345678’
This returns and id, for which you can track the status.
62 63 64 |
# File 'lib/splat/gateway.rb', line 62 def send_sms(, number, = {}) raise SplatGatewayImplError.new("Implement send_sms(message, number, options = {}) method in #{self.class}") end |