Module: Wayback::Default

Defined in:
lib/wayback/default.rb

Constant Summary collapse

ENDPOINT =
'http://web.archive.org'
ENDPOINT_PATH =
'/web'
CONNECTION_OPTIONS =
{
  :headers  => {:user_agent => "Wayback Ruby Gem #{Wayback::Version}"},
  :request  => {:open_timeout => 5, :timeout => 10},
  :ssl      => {:verify => false},
}
IDENTITY_MAP =
false
MIDDLEWARE =
Faraday::Builder.new do |builder|
  # Convert request params to "www-form-urlencoded"
  builder.use Faraday::Request::UrlEncoded
  # Follow redirects
  builder.use FaradayMiddleware::FollowRedirects
  # Handle 4xx server responses
  builder.use Wayback::Response::RaiseError, Wayback::Error::ClientError
  # Handle 5xx server responses
  builder.use Wayback::Response::RaiseError, Wayback::Error::ServerError
  # Parse memento page
  builder.use Wayback::Response::ParseMementoPage
  # Parse link-format with custom memento parser
  builder.use Wayback::Response::ParseMemento
  # Set Faraday's HTTP adapter
  builder.adapter Faraday.default_adapter
end

Class Method Summary collapse

Class Method Details

.connection_optionsObject



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

def connection_options
  CONNECTION_OPTIONS
end

.endpointString

Note:

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

Returns:

  • (String)


47
48
49
# File 'lib/wayback/default.rb', line 47

def endpoint
  ENDPOINT
end

.endpoint_pathObject



51
52
53
# File 'lib/wayback/default.rb', line 51

def endpoint_path
  ENDPOINT_PATH
end

.identity_mapObject



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

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.



67
68
69
# File 'lib/wayback/default.rb', line 67

def middleware
  MIDDLEWARE
end

.optionsHash

Returns:

  • (Hash)


41
42
43
# File 'lib/wayback/default.rb', line 41

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