Sha256: 3f19495dd7712ac330f534676ca9c0c5adefbc929e03301d7db8eab1819f04ac

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

require 'faraday'
require 'open311/version'

module Open311
  module Configuration
    VALID_OPTIONS_KEYS = [
      :adapter,
      :api_key,
      :endpoint,
      :format,
      :jurisdiction,
      :proxy,
      :user_agent].freeze

    VALID_FORMATS = [
      :json,
      :xml].freeze

    DEFAULT_ADAPTER      = Faraday.default_adapter
    DEFAULT_API_KEY      = nil
    DEFAULT_ENDPOINT     = nil
    DEFAULT_FORMAT       = :xml
    DEFAULT_JURISDICTION = nil
    DEFAULT_PROXY        = nil
    DEFAULT_USER_AGENT   = "Open311 Ruby Gem #{Open311::VERSION}".freeze

    attr_accessor *VALID_OPTIONS_KEYS

    def self.extended(base)
      base.reset
    end

    def configure
      yield self
    end

    def options
      VALID_OPTIONS_KEYS.inject({}){|o,k| o.merge!(k => send(k)) }
    end

    def reset
      self.adapter      = DEFAULT_ADAPTER
      self.api_key      = DEFAULT_API_KEY
      self.endpoint     = DEFAULT_ENDPOINT
      self.format       = DEFAULT_FORMAT
      self.jurisdiction = DEFAULT_JURISDICTION
      self.proxy        = DEFAULT_PROXY
      self.user_agent   = DEFAULT_USER_AGENT
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
open311-0.2.3 lib/open311/configuration.rb
open311-0.2.2 lib/open311/configuration.rb
open311-0.2.1 lib/open311/configuration.rb
open311-0.2.0 lib/open311/configuration.rb
open311-0.1.2 lib/open311/configuration.rb