Class: BabySMS::Adapter
- Inherits:
-
Object
- Object
- BabySMS::Adapter
- Defined in:
- lib/babysms/adapter.rb
Direct Known Subclasses
BabySMS::Adapters::BandwidthAdapter, BabySMS::Adapters::NexmoAdapter, BabySMS::Adapters::PlivoAdapter, BabySMS::Adapters::SignalwireAdapter, BabySMS::Adapters::TestAdapter, BabySMS::Adapters::TwilioAdapter
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
Class Method Summary collapse
- .adapter_name ⇒ Object
- .for_adapter_id(adapter_id, pool: BabySMS.adapters) ⇒ Object
-
.for_number(number, pool: BabySMS.adapters) ⇒ Object
Locates an adapter instance associated with a phone number.
Instance Method Summary collapse
-
#adapter_id ⇒ Object
e.g., “15555555555@twilio”.
-
#adapter_name ⇒ Object
e.g., “twilio”.
-
#initialize(from:) ⇒ Adapter
constructor
A new instance of Adapter.
-
#web_hook ⇒ Object
Returns an instance of the web hook handler, if it exists.
- #web_hook? ⇒ Boolean
-
#web_hook_class ⇒ Object
if the adapter supports web hooks, it’ll have a nested class called “WebHook”.
Constructor Details
#initialize(from:) ⇒ Adapter
Returns a new instance of Adapter.
6 7 8 |
# File 'lib/babysms/adapter.rb', line 6 def initialize(from:) @from = Phony.normalize(from) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/babysms/adapter.rb', line 4 def client @client end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
3 4 5 |
# File 'lib/babysms/adapter.rb', line 3 def from @from end |
Class Method Details
.adapter_name ⇒ Object
20 21 22 23 |
# File 'lib/babysms/adapter.rb', line 20 def self.adapter_name = name.split('::').last .gsub(/Adapter\z/, '').downcase end |
.for_adapter_id(adapter_id, pool: BabySMS.adapters) ⇒ Object
16 17 18 |
# File 'lib/babysms/adapter.rb', line 16 def self.for_adapter_id(adapter_id, pool: BabySMS.adapters) pool.find { |adapter| adapter.adapter_id == adapter_id } end |
.for_number(number, pool: BabySMS.adapters) ⇒ Object
Locates an adapter instance associated with a phone number
11 12 13 14 |
# File 'lib/babysms/adapter.rb', line 11 def self.for_number(number, pool: BabySMS.adapters) number = Phony.normalize(number) pool.find { |adapter| adapter.from == number } end |
Instance Method Details
#adapter_id ⇒ Object
e.g., “15555555555@twilio”
31 32 33 |
# File 'lib/babysms/adapter.rb', line 31 def adapter_id "#{from}@#{adapter_name}" end |
#adapter_name ⇒ Object
e.g., “twilio”
26 27 28 |
# File 'lib/babysms/adapter.rb', line 26 def adapter_name self.class.adapter_name end |
#web_hook ⇒ Object
Returns an instance of the web hook handler, if it exists
46 47 48 49 50 51 52 53 54 |
# File 'lib/babysms/adapter.rb', line 46 def web_hook unless instance_variable_defined?(:@web_hook) @web_hook = if (cls = web_hook_class) cls.new(self) end end @web_hook end |
#web_hook? ⇒ Boolean
41 42 43 |
# File 'lib/babysms/adapter.rb', line 41 def web_hook? !!web_hook_class end |
#web_hook_class ⇒ Object
if the adapter supports web hooks, it’ll have a nested class called “WebHook”. This returns the class
37 38 39 |
# File 'lib/babysms/adapter.rb', line 37 def web_hook_class self.class.const_get(:WebHook) end |