Module: StartupStats::Default

Defined in:
lib/startupstats/default.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.access_tokenString

Returns:

  • (String)


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

def access_token
  ENV['FORMD_ACCESS_TOKEN']
end

.access_token_keyString

Returns:

  • (String)


50
51
52
# File 'lib/startupstats/default.rb', line 50

def access_token_key
  ENV['FORMD_ACCESS_TOKEN_KEY'] || "access_token"
end

.connection_optionsObject



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

def connection_options
  CONNECTION_OPTIONS
end

.endpointString

Note:

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



60
61
62
# File 'lib/startupstats/default.rb', line 60

def endpoint
  ENDPOINT
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.



72
73
74
# File 'lib/startupstats/default.rb', line 72

def middleware
  MIDDLEWARE
end

.optionsHash

Returns:



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

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