Module: Hackeroo::Default

Defined in:
lib/hackeroo/default.rb

Constant Summary collapse

ENDPOINT =
'http://api.hackeroo.io'
CONNECTION_OPTIONS =
{
  :headers => {
    :accept => 'application/json',
    :user_agent => "Hackeroo Ruby Gem #{Hackeroo::Version}",
  },
  :request => {
    :open_timeout => 5,
    :timeout => 10,
  },
}
IDENTITY_MAP =
false
MIDDLEWARE =
Faraday::Builder.new do |builder|
  # Convert request params to "www-form-urlencoded"
  builder.use Faraday::Request::UrlEncoded
  # Handle 4xx server responses
  builder.use Hackeroo::Response::RaiseError, Hackeroo::Error::ClientError
  # Parse JSON response bodies using MultiJson
  builder.use Hackeroo::Response::ParseJson
  # Handle 5xx server responses
  builder.use Hackeroo::Response::RaiseError, Hackeroo::Error::ServerError
  # Set Faraday's HTTP adapter
  builder.adapter Faraday.default_adapter
end

Class Method Summary collapse

Class Method Details

.clientkeyString

Returns:

  • (String)


45
46
47
# File 'lib/hackeroo/default.rb', line 45

def clientkey
  ENV['HACKEROO_CLIENTKEY']
end

.connection_optionsObject



59
60
61
# File 'lib/hackeroo/default.rb', line 59

def connection_options
  CONNECTION_OPTIONS
end

.endpointString

Note:

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



55
56
57
# File 'lib/hackeroo/default.rb', line 55

def endpoint
  ENDPOINT
end

.identity_mapObject



63
64
65
# File 'lib/hackeroo/default.rb', line 63

def identity_map
  IDENTITY_MAP
end

.middlewareFaraday::Builder

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.



71
72
73
# File 'lib/hackeroo/default.rb', line 71

def middleware
  MIDDLEWARE
end

.optionsHash

Returns:

  • (Hash)


40
41
42
# File 'lib/hackeroo/default.rb', line 40

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