Class: Hermes::Provider
- Inherits:
-
Object
- Object
- Hermes::Provider
- Includes:
- Extractors
- Defined in:
- lib/providers/provider.rb
Direct Known Subclasses
MailgunProvider, OutboundWebhookProvider, PlivoProvider, SendgridProvider, TwilioProvider, TwitterProvider
Class Attribute Summary collapse
-
._required_credentials ⇒ Object
Returns the value of attribute _required_credentials.
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#deliverer ⇒ Object
readonly
Returns the value of attribute deliverer.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(deliverer, options = {}) ⇒ Provider
constructor
A new instance of Provider.
- #message_failure(rails_message, exception) ⇒ Object
- #message_success(rails_message) ⇒ Object
- #provider_name ⇒ Object
- #send_message(rails_message) ⇒ Object
Methods included from Extractors
#complex_extract, #extract_from, #extract_html, #extract_text, #extract_to
Constructor Details
#initialize(deliverer, options = {}) ⇒ Provider
Returns a new instance of Provider.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/providers/provider.rb', line 15 def initialize(deliverer, = {}) .symbolize_keys! @deliverer = deliverer @defaults = [:defaults] @credentials = ([:credentials] || {}).symbolize_keys @weight = [:weight].to_i if self.class._required_credentials.try(:any?) # provider defines required credentials, let's make sure to check we have everything we need if !((@credentials.keys & self.class._required_credentials) == self.class._required_credentials) # we're missing something, raise here for hard failure raise(InsufficientCredentialsError, "Credentials passed:#{@credentials.keys} do not satisfy all required:#{self.class._required_credentials}") end end unless @weight >= 0 # provider weights need to be 0 (disabled), or greater than 0 to show as active raise(InvalidWeightError, "Provider name:#{provider_name} has invalid weight:#{@weight}") end end |
Class Attribute Details
._required_credentials ⇒ Object
Returns the value of attribute _required_credentials.
6 7 8 |
# File 'lib/providers/provider.rb', line 6 def _required_credentials @_required_credentials end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
13 14 15 |
# File 'lib/providers/provider.rb', line 13 def credentials @credentials end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
13 14 15 |
# File 'lib/providers/provider.rb', line 13 def defaults @defaults end |
#deliverer ⇒ Object (readonly)
Returns the value of attribute deliverer.
13 14 15 |
# File 'lib/providers/provider.rb', line 13 def deliverer @deliverer end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
13 14 15 |
# File 'lib/providers/provider.rb', line 13 def weight @weight end |
Class Method Details
.required_credentials(*args) ⇒ Object
8 9 10 |
# File 'lib/providers/provider.rb', line 8 def required_credentials(*args) self._required_credentials = args.to_a end |
Instance Method Details
#message_failure(rails_message, exception) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/providers/provider.rb', line 50 def (, exception) Utils.log_and_puts "--- MESSAGE SEND FAILURE ---" Utils.log_and_puts exception. Utils.log_and_puts exception.backtrace.join("\n") Utils.log_and_puts "--- MESSAGE SEND FAILURE ---" self.deliverer.handle_failure(self.class) end |
#message_success(rails_message) ⇒ Object
45 46 47 48 |
# File 'lib/providers/provider.rb', line 45 def () ActionMailer::Base.deliveries << if self.deliverer.test_mode? self.deliverer.handle_success(self.class.name) end |
#provider_name ⇒ Object
37 38 39 |
# File 'lib/providers/provider.rb', line 37 def provider_name self.class.name.demodulize.underscore.gsub('_provider', '') end |
#send_message(rails_message) ⇒ Object
41 42 43 |
# File 'lib/providers/provider.rb', line 41 def () raise "this is an abstract method and must be defined in the subclass" end |