Sha256: 9353e47c2ba2e8d7d9c3d5a1e440c3c12335fc4959a7aebfe688773de01927b7

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

require 'faraday'
require 'reshape/version'

module Reshape
  module Configuration
    VALID_OPTIONS_KEYS = [
      :adapter,
      :api_version,
      :api_endpoint,
      :web_endpoint,
      :proxy,
      :consumer_token,
      :consumer_secret,
      :consumer_options,
      :oauth_token,
      :oauth_secret,
      :response_format,
      :user_agent].freeze

    DEFAULT_ADAPTER = Faraday.default_adapter
    DEFAULT_API_VERSION = 'v1'
    DEFAULT_API_ENDPOINT = 'http://api.shapeways.com/'
    DEFAULT_WEB_ENDPOINT = 'http://www.shapeways.com/'
    DEFAULT_USER_AGENT = "Reshape Rubygem #{Reshape::VERSION}".freeze
    DEFAULT_RESPONSE_FORMAT = 'json'

    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 api_endpoint=(value)
      @api_endpoint = File.join(value, "")
    end

    def web_endpoint=(value)
      @web_endpoint = File.join(value, "")
    end

    def reset
      self.adapter = DEFAULT_ADAPTER
      self.api_version = DEFAULT_API_VERSION
      self.api_endpoint = DEFAULT_API_ENDPOINT
      self.web_endpoint = DEFAULT_WEB_ENDPOINT
      self.proxy = nil
      self.consumer_token = nil
      self.consumer_secret = nil
      self.oauth_token = nil
      self.oauth_secret = nil
      self.response_format = DEFAULT_RESPONSE_FORMAT
      self.user_agent = DEFAULT_USER_AGENT
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reshape-0.2 lib/reshape/configuration.rb
reshape-0.1.1 lib/reshape/configuration.rb
reshape-0.1 lib/reshape/configuration.rb