Sha256: b10893a2e5a1cfd3aa69336643c8a100fa359d6f64f35e84794b86782469c552

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'addressable/uri'
require 'active_support/core_ext/hash/indifferent_access'

class Frenetic
  class Configuration

    @@defaults = {
      headers:   {
        accept:     'application/hal+json',
        user_agent: "Frenetic v#{Frenetic::VERSION}; #{Socket.gethostname}"
      }
    }

    def initialize( cfg = {} )
      @_cfg = cfg.symbolize_keys
    end

    def adapter
      @_cfg[:adapter] || :net_http
    end

    def api_token
      @_cfg[:api_token]
    end

    def attributes
      {
        adapter:   adapter,
        api_token: api_token,
        cache:     cache,
        headers:   headers,
        password:  password,
        url:       url,
        username:  username
      }
    end

    def cache
      if @_cfg[:cache] == :rack
        {
          metastore:     'file:tmp/rack/meta',
          entitystore:   'file:tmp/rack/body',
          ignore_headers: %w{Authorization Set-Cookie X-Content-Digest}
        }
      else
        {}
      end
    end

    def headers
      @@defaults[:headers].merge( @_cfg[:headers] || {} )
    end

    def password
      @_cfg[:password] || @_cfg[:api_key]
    end

    def url
      Addressable::URI.parse @_cfg[:url]
    end

    def username
      @_cfg[:username] || @_cfg[:app_id]
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frenetic-0.0.20.alpha.0 lib/frenetic/configuration.rb