Sha256: 86a943a6282c17df31fb1a16de572833c9a1aeeaf2c59eb26f79c3f116568eb4

Contents?: true

Size: 893 Bytes

Versions: 6

Compression:

Stored size: 893 Bytes

Contents

require 'singleton'
require 'howitzer/mailgun_api/client'
require 'howitzer/exceptions'

module Howitzer
  module MailgunApi
    # This class represent connector to Mailgun service
    class Connector
      include Singleton

      attr_reader :api_key
      attr_accessor :domain

      # Assigns default value for a domain

      def initialize
        self.domain = Howitzer.mailgun_domain
      end

      # @return [Client] a mailgun client
      # @raise [InvalidApiKeyError] if api_key is blank

      def client(api_key = Howitzer.mailgun_key)
        check_api_key(api_key)
        return @client if @api_key == api_key && @api_key

        @api_key = api_key
        @client = Client.new(api_key: @api_key)
      end

      private

      def check_api_key(api_key)
        raise Howitzer::InvalidApiKeyError, 'Api key can not be blank' if api_key.blank?
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
howitzer-2.6.1 lib/howitzer/mailgun_api/connector.rb
howitzer-2.6.0 lib/howitzer/mailgun_api/connector.rb
howitzer-2.5.0 lib/howitzer/mailgun_api/connector.rb
howitzer-2.4.0 lib/howitzer/mailgun_api/connector.rb
howitzer-2.3.0 lib/howitzer/mailgun_api/connector.rb
howitzer-2.2.0 lib/howitzer/mailgun_api/connector.rb