Sha256: 2438dc56682d2b58e144b1c97310bdc2004e87c48c6f6390825ef01a2dbe8cbe

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

require 'capgun/version'

module Capgun

  # Defines constants and methods related to configuration
  module Config

    # The HTTP connection adapter that will be used to connect if none is set
    DEFAULT_ADAPTER = :net_http

    # The Faraday connection options if none is set
    DEFAULT_CONNECTION_OPTIONS = {}

    # API endpoint
    DEFAULT_ENDPOINT = 'https://api.capgun.io'

    # The gateway server if none is set
    DEFAULT_GATEWAY = nil

    # The auth token if none is set
    DEFAULT_AUTH_TOKEN = ""

    # The value sent in the 'User-Agent' header if none is set
    DEFAULT_USER_AGENT = "Capgun.io Ruby Gem #{Capgun::Version}"

    # The proxy server if none is set
    DEFAULT_PROXY = nil

    # An array of valid keys in the options hash when configuring a {Capgun::Client}
    VALID_OPTIONS_KEYS = [
      :adapter,
      :connection_options,
      :endpoint,
      :gateway,
      :auth_token,
      :user_agent,
      :proxy,
    ]

    #ORDER_OPTIONS = Struct.new(:id, :url, :notify, :cost, :viewport, :packages, :images, :asset_urls, :options, :job)

    attr_accessor *VALID_OPTIONS_KEYS

    # When this module is extended, set all configuration options to their default values
    def self.extended(base)
      base.reset
    end

    # Convenience method to allow configuration options to be set in a block
    def configure
      yield self
      self
    end

    # Create a hash of options and their values
    def options
      options = {}
      VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
      options
    end

    # Reset all configuration options to defaults
    def reset
      self.adapter            = DEFAULT_ADAPTER
      self.connection_options = DEFAULT_CONNECTION_OPTIONS
      self.endpoint           = DEFAULT_ENDPOINT
      self.gateway            = DEFAULT_GATEWAY
      self.auth_token         = DEFAULT_AUTH_TOKEN
      self.user_agent         = DEFAULT_USER_AGENT
      self.proxy              = DEFAULT_PROXY
      self
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capgun-0.1.0 lib/capgun/config.rb