Module: Echowrap::Default

Defined in:
lib/echowrap/default.rb

Constant Summary collapse

ENDPOINT =
'http://developer.echonest.com'
CONNECTION_OPTIONS =
{
  :headers => {
    :accept => 'application/json',
    :user_agent => "Echowrap Ruby Gem #{Echowrap::Version}",
  },
  :request => {
    :open_timeout => 5,
    :timeout => 10,
    :params_encoder => Faraday::FlatParamsEncoder
  },
  :ssl => {
    :verify => false
  },
}
IDENTITY_MAP =
false
MIDDLEWARE =
Faraday::RackBuilder.new do |builder|
  # Convert file uploads to Faraday::UploadIO objects
  builder.use Echowrap::Request::MultipartWithFile
  # 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 Echowrap::Response::RaiseError, Echowrap::Error::ClientError
  # Parse JSON response bodies using MultiJson
  builder.use Echowrap::Response::ParseJson
  # Handle 5xx server responses
  builder.use Echowrap::Response::RaiseError, Echowrap::Error::ServerError
  # Set Faraday's HTTP adapter
  builder.adapter Faraday.default_adapter
end

Class Method Summary collapse

Class Method Details

.api_keyString

Returns:

  • (String)


54
55
56
# File 'lib/echowrap/default.rb', line 54

def api_key
  ENV['ECHONEST_API_KEY']
end

.connection_optionsObject



74
75
76
# File 'lib/echowrap/default.rb', line 74

def connection_options
  CONNECTION_OPTIONS
end

.consumer_keyString

Returns:

  • (String)


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

def consumer_key
  ENV['ECHONEST_CONSUMER_KEY']
end

.endpointString

Note:

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

Returns:

  • (String)


70
71
72
# File 'lib/echowrap/default.rb', line 70

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.



82
83
84
# File 'lib/echowrap/default.rb', line 82

def middleware
  MIDDLEWARE
end

.optionsHash

Returns:

  • (Hash)


49
50
51
# File 'lib/echowrap/default.rb', line 49

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

.shared_secretString

Returns:

  • (String)


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

def shared_secret
  ENV['ECHONEST_SHARED_SECRET']
end