Module: Fantasydata::Default

Defined in:
lib/fantasydata/default.rb

Constant Summary collapse

ENDPOINT =
'http://api.nfldata.apiphany.com'
CONNECTION_OPTIONS =
{
  :headers => {
    :accept => 'application/json',
    :user_agent => "FantasyData Ruby Gem #{Fantasydata::VERSION}"
  },
  :request => {
    :open_timeout => 10,
    :timeout => 30,
    :params_encoder => Faraday::FlatParamsEncoder
  },
  :ssl => {
    :verify => false
  },
}
IDENTITY_MAP =
false
MIDDLEWARE =
Faraday::RackBuilder.new do |builder|
  # Checks for files in the payload
  builder.use Faraday::Request::Multipart
  
  # Convert request params to "www-form-urlencoded"
  builder.use Faraday::Request::UrlEncoded
  
  # Handle 4xx server responses
  builder.use Fantasydata::Response::RaiseError, Fantasydata::Error::ClientError
  
  # Parse JSON response bodies using MultiJson
  builder.use Fantasydata::Response::ParseJson
  
  # Handle 5xx server responses
  builder.use Fantasydata::Response::RaiseError, Fantasydata::Error::ServerError
  
  # builder.use Faraday::Response::Logger

  # Set Faraday's HTTP adapter
  builder.adapter Faraday.default_adapter
end

Class Method Summary collapse

Class Method Details

.api_keyString

Returns:

  • (String)


58
59
60
# File 'lib/fantasydata/default.rb', line 58

def api_key
  ENV['FANTASYDATA_API_KEY']
end

.connection_optionsObject



68
69
70
# File 'lib/fantasydata/default.rb', line 68

def connection_options
  CONNECTION_OPTIONS
end

.endpointString

Note:

This is configurable in case you want to use a Fantasydata-compatible endpoint.

Returns:

  • (String)


64
65
66
# File 'lib/fantasydata/default.rb', line 64

def endpoint
  ENDPOINT
end

.middlewareFaraday::RackBuilder

Note:

Faraday’s middleware stack implementation is comparable to that of Rack middleware. The order of middleware is important: the first middleware on the list wraps all others, while the last middleware is the innermost one.



76
77
78
# File 'lib/fantasydata/default.rb', line 76

def middleware
  MIDDLEWARE
end

.optionsHash

Returns:

  • (Hash)


53
54
55
# File 'lib/fantasydata/default.rb', line 53

def options
  Hash[Fantasydata::Configurable.keys.map{|key| [key, send(key)]}]
end