Sha256: a14589046c8a3e652c4d821bfbc5bc5392c64bbfe2d9882059fffd98f54579eb

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'oi_api/version'

module OiApi

  module Configuration

    VALID_CONFIG_KEYS = [
      :username,
      :password,
      :api_endpoint,
      :user_agent,
      :format,
      :content_type,
      :debug_output
    ]

    DEFAULT_API_ENDPOINT = 'https://oiapi.com/v1/'.freeze
    DEFAULT_USER_AGENT   = "OiApiRuby Gem #{OiApi::VERSION}".freeze
    DEFAULT_FORMAT       = :json
    DEFAULT_CONTENT_TYPE = 'application/json'
    DEFAULT_DEBUG_OUTPUT = false # $stdout

    attr_accessor *VALID_CONFIG_KEYS

    def configure
      yield self
    end

    def self.extended(base)
      base.reset
    end

    def options
      Hash[ *VALID_CONFIG_KEYS.map { |key| [key, public_send(key)] }.flatten ]
    end

    def reset
      self.username      = nil
      self.password      = nil
      self.api_endpoint  = DEFAULT_API_ENDPOINT
      self.user_agent    = DEFAULT_USER_AGENT
      self.format        = DEFAULT_FORMAT
      self.content_type  = DEFAULT_CONTENT_TYPE
      self.debug_output  = DEFAULT_DEBUG_OUTPUT
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oi-api-ruby-0.1.5 lib/oi_api/configuration.rb
oi-api-ruby-0.1.4 lib/oi_api/configuration.rb
oi-api-ruby-0.1.3 lib/oi_api/configuration.rb