Class: WaybackArchiver::WaybackMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/wayback_archiver/adapters/wayback_machine.rb

Overview

WaybackMachine adapter

Constant Summary collapse

BASE_URL =

Wayback Machine base URL.

'https://web.archive.org/save/'.freeze

Class Method Summary collapse

Class Method Details

.call(url) ⇒ ArchiveResult

Send URL to Wayback Machine.

Examples:

Archive example.com, with default options

WaybackMachine.call('http://example.com')

Parameters:

  • url (String)

    to send.

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wayback_archiver/adapters/wayback_machine.rb', line 15

def self.call(url)
  request_url  = "#{BASE_URL}#{url}"
  response = Request.get(request_url, follow_redirects: false)
  WaybackArchiver.logger.info "Posted [#{response.code}, #{response.message}] #{url}"
  ArchiveResult.new(
    url,
    code: response.code,
    request_url: response.uri,
    response_error: response.error
  )
rescue Request::Error => e
  WaybackArchiver.logger.error "Failed to archive #{url}: #{e.class}, #{e.message}"
  ArchiveResult.new(url, error: e)
end