Module: Peerindex::Configuration

Included in:
Peerindex
Defined in:
lib/peerindex/configuration.rb

Overview

Defines constants and methods related to configuration

Constant Summary collapse

VALID_OPTIONS_KEYS =

An array of valid keys in the options hash when configuring a Twitter::API

[
:adapter,
:api_key,
:endpoint,
:format,
:gateway,
:proxy,
:user_agent,
:faraday_options].freeze
DEFAULT_ADAPTER =

The adapter that will be used to connect if none is set

:net_http
DEFAULT_API_KEY =

This is required

nil
DEFAULT_CONSUMER_SECRET =

By default, don't set an application secret

nil
DEFAULT_ENDPOINT =
Note:

Default endpoint

The endpoint that will be used to connect if none is set

'http://api.peerindex.net/'.freeze
DEFAULT_FORMAT =
Note:

JSON is preferred over XML because it is more concise and faster to parse.

The response format appended to the path and sent in the 'Accept' header if none is set

:json
DEFAULT_PROXY =

By default, don't use a proxy server

nil
DEFAULT_USER_AGENT =

The value sent in the 'User-Agent' header if none is set

"Peerindex Ruby Gem #{Peerindex::VERSION}".freeze
DEFAULT_GATEWAY =
nil
DEFAULT_FARADAY_OPTIONS =
{}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



51
52
53
# File 'lib/peerindex/configuration.rb', line 51

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



56
57
58
# File 'lib/peerindex/configuration.rb', line 56

def configure
  yield self
end

#optionsObject

Create a hash of options and their values



61
62
63
64
65
# File 'lib/peerindex/configuration.rb', line 61

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
  options
end

#resetObject

Reset all configuration options to defaults



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/peerindex/configuration.rb', line 68

def reset
  self.adapter            = DEFAULT_ADAPTER
  self.api_key            = DEFAULT_API_KEY
  self.endpoint           = DEFAULT_ENDPOINT
  self.format             = DEFAULT_FORMAT
  self.proxy              = DEFAULT_PROXY
  self.user_agent         = DEFAULT_USER_AGENT
  self.gateway            = DEFAULT_GATEWAY
  self.faraday_options    = DEFAULT_FARADAY_OPTIONS
  self
end