wayback 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,7 @@ module Wayback
23
23
  # @raise [Wayback::Error::Unauthorized] Error raised when supplied user credentials are not valid.
24
24
  # @return [Wayback::Page]
25
25
  # @param url [String] The page URI that of which was archived.
26
- # @param date [String, Symbol, Time, Fixnum, Integer] A date or symbol to describe which dated archive page. Symbols include :first and :last. Strings are converted to integer timestamps.
26
+ # @param date [String, Symbol, Date, DateTime, Time, Fixnum, Integer, Float] A date or symbol to describe which dated archive page. Symbols include :first and :last. Strings are converted to integer timestamps.
27
27
  # @param options [Hash] A customizable set of options.
28
28
  # @example Return the HTML archive for the page.
29
29
  # Wayback.page('http://gleu.ch')
@@ -32,10 +32,27 @@ module Wayback
32
32
  # Wayback.page('http://gleu.ch', :first)
33
33
  # Wayback.page('http://gleu.ch', :last)
34
34
  def page(url, date=0, options={})
35
- date = 0 if date == :first
36
- date = Time.now if date == :last
37
- date = Time.parse(date).to_i unless [Fixnum,Time,Integer].include?(date.class)
38
- object_from_response(Wayback::Page, :get, "/#{date.to_i}/#{url}", options)
35
+ archive_date = case date.class.to_s
36
+ when 'Time'
37
+ date
38
+ when 'Date', 'DateTime'
39
+ date.to_time
40
+ when 'Symbol'
41
+ (date == :first ? 0 : Time.now)
42
+ when 'String'
43
+ Time.parse(date).strftime('%Y%m%d%H%M%S')
44
+ when 'Fixnum', 'Integer', 'Float'
45
+ # Epoch vs date string as number
46
+ (date.to_i <= Time.now.to_i ? Time.at(date.to_i) : Time.parse(date.to_i.to_s))
47
+ else
48
+ raise Wayback::Error::ClientError
49
+ end
50
+
51
+ # Format accordingly
52
+ archive_date = archive_date.strftime('%Y%m%d%H%M%S') if archive_date.class == Time
53
+
54
+ # Get it
55
+ object_from_response(Wayback::Page, :get, "/#{archive_date}/#{url}", options)
39
56
  end
40
57
 
41
58
  end
@@ -19,7 +19,7 @@ module Wayback
19
19
  k, v = a.gsub(/^([A-Z0-9\-]+)(=.*)$/i, '\1'), a.gsub(/^([A-Z0-9\-]+)(=(\'|\"))(.*)(\'|\")(,)?$/i, '\4')
20
20
  case k
21
21
  when 'datetime'
22
- datetime, date = v, Time.parse(v).to_i
22
+ datetime, date = v, Time.parse(v).utc.strftime('%Y%m%d%H%M%S').to_i
23
23
  when 'rel'
24
24
  rels = v.split(' ')
25
25
  when 'from'
@@ -2,7 +2,7 @@ module Wayback
2
2
  class Version
3
3
  MAJOR = 0 unless defined? Wayback::Version::MAJOR
4
4
  MINOR = 2 unless defined? Wayback::Version::MINOR
5
- PATCH = 0 unless defined? Wayback::Version::PATCH
5
+ PATCH = 1 unless defined? Wayback::Version::PATCH
6
6
  PRE = nil unless defined? Wayback::Version::PRE
7
7
 
8
8
  class << self
@@ -20,7 +20,7 @@ describe Wayback::API::Archive do
20
20
  timemap = @client.list('gleu.ch')
21
21
  expect(timemap).to be_a Wayback::Archive
22
22
  expect(timemap.id).to eq ('http://gleu.ch')
23
- expect(timemap.first_date).to eq (1303064571)
23
+ expect(timemap.first_date).to eq(20110417182251)
24
24
  expect(timemap.first_date?).to be_true
25
25
  end
26
26
  end
@@ -29,45 +29,87 @@ describe Wayback::API::Archive do
29
29
  before do
30
30
  stub_get("/20130129170322/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
31
31
  end
32
+
32
33
  it "requests the correct resource" do
33
34
  @client.page('gleu.ch', 20130129170322)
34
35
  expect(a_get("/20130129170322/gleu.ch")).to have_been_made
35
36
  end
37
+
36
38
  it "returns the desired page on date" do
39
+ stub_get("/20130129170322/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
40
+
37
41
  page = @client.page('gleu.ch', 20130129170322)
38
42
  expect(page).to be_a Wayback::Page
39
43
  expect(page.html).to match /^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im
40
44
  end
45
+
41
46
  it "returns the first desired page" do
42
47
  stub_get("/0/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
48
+
43
49
  page = @client.page('gleu.ch', :first)
44
50
  expect(page).to be_a Wayback::Page
45
51
  expect(page.html).to match /^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im
46
52
  end
53
+
47
54
  it "returns the last desired page" do
48
- stub_get("/#{Time.now.to_i}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
55
+ stub_get("/#{Time.now.strftime('%Y%m%d%H%M%S')}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
56
+
49
57
  page = @client.page('gleu.ch', :last)
50
58
  expect(page).to be_a Wayback::Page
51
59
  expect(page.html).to match(/^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im)
52
60
  end
61
+
53
62
  it "returns the desired page for Time" do
54
- stub_get("/#{Time.now.to_i}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
63
+ stub_get("/#{Time.now.strftime('%Y%m%d%H%M%S')}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
64
+
55
65
  page = @client.page('gleu.ch', Time.now)
56
66
  expect(page).to be_a Wayback::Page
57
67
  expect(page.html).to match(/^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im)
58
68
  end
59
- it "returns the desired page for Time string" do
60
- stub_get("/#{Time.now.to_i}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
69
+
70
+ it "returns the desired page for Date" do
71
+ stub_get("/#{Time.parse(Date.today.to_s).strftime('%Y%m%d%H%M%S')}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
72
+
73
+ page = @client.page('gleu.ch', Date.today)
74
+ expect(page).to be_a Wayback::Page
75
+ expect(page.html).to match(/^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im)
76
+ end
77
+
78
+ it "returns the desired page for DateTime" do
79
+ stub_get("/#{Time.parse(DateTime.new(2013,1,1).to_s).strftime('%Y%m%d%H%M%S')}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
80
+
81
+ page = @client.page('gleu.ch', DateTime.new(2013,1,1))
82
+ expect(page).to be_a Wayback::Page
83
+ expect(page.html).to match(/^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im)
84
+ end
85
+
86
+ it "returns the desired page for String" do
87
+ stub_get("/#{Time.now.strftime('%Y%m%d%H%M%S')}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
88
+
61
89
  page = @client.page('gleu.ch', Time.now.to_s)
62
90
  expect(page).to be_a Wayback::Page
63
91
  expect(page.html).to match(/^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im)
64
92
  end
65
- # it "handles when error exists" do
66
- # stub_get("/#{Time.now.to_i}/gleu.ch").to_return(:status => 204, :body => '', :headers => {:content_type => "text/xml"})
67
- # page = @client.page('gleu.ch', Time.now.to_s)
68
- # expect(page).to be_a Wayback::Page
69
- # expect(page.html).to match(/^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im)
70
- # end
93
+
94
+ it "returns the desired page for Fixnum" do
95
+ stub_get("/#{Time.now.strftime('%Y%m%d%H%M%S')}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
96
+ page = @client.page('gleu.ch', Time.now.to_i)
97
+ expect(page).to be_a Wayback::Page
98
+ expect(page.html).to match(/^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im)
99
+ end
100
+
101
+ it "returns the desired page for Float" do
102
+ stub_get("/#{Time.now.strftime('%Y%m%d%H%M%S')}/gleu.ch").to_return(:body => fixture("page.html"), :headers => {:content_type => "text/html"})
103
+ page = @client.page('gleu.ch', Time.now.to_f)
104
+ expect(page).to be_a Wayback::Page
105
+ expect(page.html).to match(/^\<\!DOCTYPE html\>.*http\:\/\/gleu\.ch.*\<\/html\>/im)
106
+ end
107
+
108
+ [[0], {:a => 'b'}, File].each do |t|
109
+ it "returns error for #{t.class}" do
110
+ expect{page = @client.page('gleu.ch', t)}.to raise_error(Wayback::Error::ClientError)
111
+ end
112
+ end
71
113
  end
72
114
 
73
115
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wayback
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-19 00:00:00.000000000 Z
12
+ date: 2013-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday