Sha256: ce97639460633517b8c94064ad293098693e2b15bbda9ab9565a9e75aab90772

Contents?: true

Size: 705 Bytes

Versions: 3

Compression:

Stored size: 705 Bytes

Contents

require 'singleton'
require 'howitzer/mailgun/client'
require 'howitzer/exceptions'

module Mailgun
  class Connector
    include Singleton

    attr_reader :api_key

    def client(api_key=settings.mailgun_key)
      check_api_key(api_key)
      if @api_key == api_key && @api_key
        @client
      else
        @api_key = api_key
        @client = Mailgun::Client.new(@api_key)
      end
    end

    def domain
      @domain || change_domain
    end

    def change_domain(domain_name=settings.mailgun_domain)
      @domain = domain_name
    end

    private
    def check_api_key(api_key)
      log.error Howitzer::InvalidApiKeyError, "Api key can not be blank" if api_key.blank?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
howitzer-1.1.1 lib/howitzer/mailgun/connector.rb
howitzer-1.1.0 lib/howitzer/mailgun/connector.rb
howitzer-1.0.2 lib/howitzer/mailgun/connector.rb