Module: Wayback::API::Archive
Instance Method Summary collapse
-
#available(url, date = 0, options = {}) ⇒ Wayback::Archive
Return a page's information from the closest known timestamp.
-
#list(url, options = {}) ⇒ Wayback::Archive
Return a list of archived pages.
-
#page(url, date = 0, options = {}) ⇒ Wayback::Page
Returns the HTML contents of an archive page, fetched by date.
Instance Method Details
#available(url, date = 0, options = {}) ⇒ Wayback::Archive
Return a page's information from the closest known timestamp
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, ={}) 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 [:url] = url [:timestamp] = archive_date object_from_response(Wayback::Availability, :json_get, "/available", ) end |
#list(url, options = {}) ⇒ Wayback::Archive
Return a list of archived pages
17 18 19 |
# File 'lib/wayback/api/archive.rb', line 17 def list(url, ={}) object_from_response(Wayback::Archive, :get, "/timemap/link/#{url}", ) end |
#page(url, date = 0, options = {}) ⇒ Wayback::Page
Returns the HTML contents of an archive page, fetched by date
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, ={}) 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}", ) end |