Sha256: ceb2fae8d76ff08b04a7041d4c4fe4ecf074910b668691fb871956e3a399623c

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

# -*- encoding: utf-8 -*-

module Fixer
  module Configuration

    VALID_OPTIONS_KEYS = [
      :client_id,
      :client_secret,
      :adapter,
      :endpoint,
      :user_agent
    ].freeze

    # Adapters are whatever Faraday supports - I like excon alot, so I'm defaulting it
    DEFAULT_ADAPTER = :excon

    # The api endpoint to get REST
    DEFAULT_ENDPOINT = 'http://fixer.prx.dev/api/'.freeze

    # The value sent in the http header for 'User-Agent' if none is set
    DEFAULT_USER_AGENT = "Fixer Ruby Gem #{Fixer::VERSION}".freeze

    attr_accessor *VALID_OPTIONS_KEYS

    # Convenience method to allow for global setting of configuration options
    def configure
      yield self
    end

    def self.extended(base)
      base.reset!
    end

    class << self
      def keys
        VALID_OPTIONS_KEYS
      end
    end

    def options
      options = {}
      VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
      options
    end

    # Reset configuration options to their defaults
    def reset!
      self.client_id     = ENV['FIXER_CLIENT_ID']
      self.client_secret = ENV['FIXER_CLIENT_SECRET']
      self.adapter       = DEFAULT_ADAPTER
      self.endpoint      = ENV['FIXER_ENDPOINT'] || DEFAULT_ENDPOINT
      self.user_agent    = DEFAULT_USER_AGENT
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fixer_client-0.1.0 lib/fixer/configuration.rb