Module: Wayback::API::Archive

Includes:
Utils
Included in:
Client
Defined in:
lib/wayback/api/archive.rb

Instance Method Summary collapse

Instance Method Details

#available(url, date = 0, options = {}) ⇒ Wayback::Archive

Return a page's information from the closest known timestamp

Examples:

Return the the closest timestamp information about a page.

Wayback.available('http://gleu.ch')

Parameters:

  • url (String)

    The page URI that of which was archived.

  • date (String, Symbol, Date, DateTime, Time, Fixnum, Integer, Float) (defaults to: 0)

    A date or symbol to describe which dated archive page. Symbols include :first and :last. Strings are converted to integer timestamps.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wayback/api/archive.rb', line 29

def available(url, date=0, options={})
  archive_date = case date.class.to_s
    when 'Time'
      date
    when 'Date', 'DateTime'
      date.to_time
    when 'Symbol'
      (date == :first ? 19690101000000 : Time.now)
    when 'String'
      Time.parse(date).strftime('%Y%m%d%H%M%S')
    when 'Fixnum', 'Integer', 'Float'
      # Epoch vs date string as number
      (date.to_i <= Time.now.to_i ? Time.at(date.to_i) : Time.parse(date.to_i.to_s))
    else
      raise Wayback::Error::ClientError
  end

  # Format accordingly
  archive_date = archive_date.strftime('%Y%m%d%H%M%S') if archive_date.class == Time

  options[:url] = url
  options[:timestamp] = archive_date

  object_from_response(Wayback::Availability, :json_get, "/available", options)
end

#list(url, options = {}) ⇒ Wayback::Archive

Return a list of archived pages

Examples:

Return the list of available archives for a web page.

Wayback.list('http://gleu.ch')

Parameters:

  • url (String)

    The page URI that of which was archived.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:



17
18
19
# File 'lib/wayback/api/archive.rb', line 17

def list(url, options={})
  object_from_response(Wayback::Archive, :get, "/timemap/link/#{url}", options)
end

#page(url, date = 0, options = {}) ⇒ Wayback::Page

Returns the HTML contents of an archive page, fetched by date

Examples:

Return the HTML archive for the page.

Wayback.page('http://gleu.ch')
Wayback.page('http://gleu.ch', 'Tue, 17 Jan 2012 07:33:06 GMT')
Wayback.page('http://gleu.ch', '20130113125339')
Wayback.page('http://gleu.ch', :first)
Wayback.page('http://gleu.ch', :last)

Parameters:

  • url (String)

    The page URI that of which was archived.

  • date (String, Symbol, Date, DateTime, Time, Fixnum, Integer, Float) (defaults to: 0)

    A date or symbol to describe which dated archive page. Symbols include :first and :last. Strings are converted to integer timestamps.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

Raises:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/wayback/api/archive.rb', line 68

def page(url, date=0, options={})
  archive_date = case date.class.to_s
    when 'Time'
      date
    when 'Date', 'DateTime'
      date.to_time
    when 'Symbol'
      (date == :first ? 0 : Time.now)
    when 'String'
      Time.parse(date).strftime('%Y%m%d%H%M%S')
    when 'Fixnum', 'Integer', 'Float'
      # Epoch vs date string as number
      (date.to_i <= Time.now.to_i ? Time.at(date.to_i) : Time.parse(date.to_i.to_s))
    else
      raise Wayback::Error::ClientError
  end

  # Format accordingly
  archive_date = archive_date.strftime('%Y%m%d%H%M%S') if archive_date.class == Time

  # Get it
  object_from_response(Wayback::Page, :get, "/#{archive_date}/#{url}", options)
end