Module: Wayback::Default

Defined in:
lib/wayback/default.rb

Constant Summary collapse

ENDPOINT =
'http://web.archive.org'
ENDPOINT_PATH =
'/web'
JSON_ENDPOINT =
'http://archive.org'
JSON_ENDPOINT_PATH =
'/wayback'
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 closest available JSON result
  builder.use Wayback::Response::ParseAvailablity
  # 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



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

def connection_options
  CONNECTION_OPTIONS
end

.endpointString

Note:

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

Returns:

  • (String)


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

def endpoint
  ENDPOINT
end

.endpoint_pathObject



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

def endpoint_path
  ENDPOINT_PATH
end

.identity_mapObject



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

def identity_map
  IDENTITY_MAP
end

.json_endpointObject



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

def json_endpoint
  JSON_ENDPOINT
end

.json_endpoint_pathObject



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

def json_endpoint_path
  JSON_ENDPOINT_PATH
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.



80
81
82
# File 'lib/wayback/default.rb', line 80

def middleware
  MIDDLEWARE
end

.optionsHash

Returns:

  • (Hash)


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

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