Class: Courrier::Email::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/courrier/email/provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(provider: nil, api_key: nil, options: {}, provider_options: {}, context_options: {}) ⇒ Provider

Returns a new instance of Provider.



19
20
21
22
23
24
25
# File 'lib/courrier/email/provider.rb', line 19

def initialize(provider: nil, api_key: nil, options: {}, provider_options: {}, context_options: {})
  @provider = provider
  @api_key = api_key
  @options = options
  @provider_options = provider_options
  @context_options = context_options
end

Instance Method Details

#deliverObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/courrier/email/provider.rb', line 27

def deliver
  raise Courrier::ConfigurationError, "`provider` and `api_key` must be configured for production environment" if configuration_missing_in_production?
  raise Courrier::ConfigurationError, "Unknown provider. Choose one of `#{comma_separated_providers}` or provide your own." if @provider.empty? || @provider.nil?

  provider_class.new(
    api_key: @api_key,
    options: @options,
    provider_options: @provider_options,
    context_options: @context_options
  ).deliver
end