resync-client 0.2.4 → 0.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8314c851c5631164009f9a2d88d0c3d403cc70ad
4
- data.tar.gz: 533203c8b735acb0c29063efa8112feb80921e45
3
+ metadata.gz: 6dc391cfdfcafd5a808a5a4736daf19a1e52d418
4
+ data.tar.gz: 2f983d3560d4bf3390faaeda241e5b6a570be8f9
5
5
  SHA512:
6
- metadata.gz: 2be76b5aaf5d2141a009ef77336ebb1d78877971d94a1069e369bb25e97251726b548898f3906e9852097e53cde6ec28f68638bebfd14c90f6c124bddbcd14d9
7
- data.tar.gz: 0071b77513fc26fee16832f7885e414801e65c4895df3911c4093b5fff0c187c478209605447db5cf9f27eb97a4ae5e457bb093f436eed3bf7cce0c03fe5439c
6
+ metadata.gz: 65e5d83731a97afab8e3d1d6cbcca7ef716f7acf2e3e7d1ef490763dff15c8daef6539591bd51069b11ddae2f530bcd005928e92b57fdd0805b092e66da7b961
7
+ data.tar.gz: 468e546e76abb8f29ca6f6a968efd17ab46f785fd082148f0b9b343fca139a69cc2f9dcbd0f491ad37834dab454d104fae35edca5f0e055fcbcba0f34558effc
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.2.5
2
+
3
+ - Added `#all_changes` to transparently download and flatten changes in `ChangeListIndex` and `ChangeDumpIndex` documents, with filtering by time and type
4
+
1
5
  # 0.2.4
2
6
 
3
7
  - Added `#all_resources` to transparently download and flatten lists in `ChangeListIndex` and `ResourceListIndex`
@@ -0,0 +1,37 @@
1
+ require 'resync'
2
+ require_relative 'resource_client_delegate'
3
+
4
+ module Resync
5
+ class Client
6
+ module Mixins
7
+ # A resource container whose resources are lists of changes.
8
+ module ChangeIndex
9
+ prepend ResourceClientDelegate
10
+
11
+ # Downloads and parses each resource list and returns a flattened enumeration
12
+ # of all changes in each contained list, filtering by date/time, change type,
13
+ # or both. (Each contained list is only downloaded as needed, and only downloaded
14
+ # once.) The lists of lists are filtered by +from_time+ and +until_time+, in
15
+ # non-strict mode (only excluding those lists provably not in the range, i.e.,
16
+ # including lists without +from_time+ or +until_time+); the individual changes
17
+ # are filtered by +modified_time+.
18
+ #
19
+ # @param of_type [Resync::Types::Change, nil] the change type
20
+ # @param in_range [Range<Time>, nil] the time range
21
+ # @return [Enumerator::Lazy<Resync::Resource>] the flattened enumeration of changes
22
+ def all_changes(of_type: nil, in_range: nil)
23
+ @change_lists ||= {}
24
+ lists = in_range ? change_lists(in_range: in_range, strict: false) : resources
25
+ lists.flat_map do |cl|
26
+ @change_lists[cl] ||= cl.get_and_parse
27
+ @change_lists[cl].changes(of_type: of_type, in_range: in_range)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ class BaseChangeIndex
35
+ prepend Client::Mixins::ChangeIndex
36
+ end
37
+ end
@@ -12,7 +12,6 @@ module Resync
12
12
  # it to a temporary file if necessary.
13
13
  # @return [Resync::Client::Zip::ZipPackage] the zipped contents of this resource
14
14
  def zip_package
15
- puts self
16
15
  @zip_package ||= Resync::Client::Zip::ZipPackage.new(download_to_temp_file)
17
16
  end
18
17
  end
@@ -1,6 +1,6 @@
1
1
  module Resync
2
2
  class Client
3
3
  # The version of this gem.
4
- VERSION = '0.2.4'
4
+ VERSION = '0.2.5'
5
5
  end
6
6
  end
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
3
+ xmlns:rs="http://www.openarchives.org/rs/terms/">
4
+ <rs:ln rel="up"
5
+ href="http://example.com/dataset1/capabilitylist.xml"/>
6
+ <rs:md capability="changelist"
7
+ from="2013-01-01T00:00:00Z"
8
+ until="2013-01-02T00:00:00Z"/>
9
+ <url>
10
+ <loc>http://example.com/res1</loc>
11
+ <lastmod>2013-01-01T01:00:00Z</lastmod>
12
+ <rs:md change="updated"
13
+ hash="md5:51b99b46c9980623b36b27e06a7e4a46"
14
+ length="446"
15
+ type="text/plain"/>
16
+ </url>
17
+ <url>
18
+ <loc>http://example.com/res2</loc>
19
+ <lastmod>2013-01-01T23:00:00Z</lastmod>
20
+ <rs:md change="updated"
21
+ hash="md5:6205d276e0c120eb4bac47c14a8297d8"
22
+ length="447"
23
+ type="text/plain"/>
24
+ </url>
25
+ </urlset>
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
3
+ xmlns:rs="http://www.openarchives.org/rs/terms/">
4
+ <rs:ln rel="up"
5
+ href="http://example.com/dataset1/capabilitylist.xml"/>
6
+ <rs:md capability="changelist"
7
+ from="2013-01-02T00:00:00Z"
8
+ until="2013-01-03T00:00:00Z"/>
9
+ <url>
10
+ <loc>http://example.com/res1</loc>
11
+ <lastmod>2013-01-02T01:00:00Z</lastmod>
12
+ <rs:md change="updated"
13
+ hash="md5:6205d276e0c120eb4bac47c14a8297d8"
14
+ length="447"
15
+ type="text/plain"/>
16
+ </url>
17
+ <url>
18
+ <loc>http://example.com/res2</loc>
19
+ <lastmod>2013-01-02T23:00:00Z</lastmod>
20
+ <rs:md change="updated"
21
+ hash="md5:51b99b46c9980623b36b27e06a7e4a46"
22
+ length="446"
23
+ type="text/plain"/>
24
+ </url>
25
+ </urlset>
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
3
+ xmlns:rs="http://www.openarchives.org/rs/terms/">
4
+ <rs:ln rel="up"
5
+ href="http://example.com/dataset1/capabilitylist.xml"/>
6
+ <rs:md capability="changelist"
7
+ from="2013-01-03T00:00:00Z"/>
8
+ <url>
9
+ <loc>http://example.com/res1</loc>
10
+ <lastmod>2013-01-03T01:00:00Z</lastmod>
11
+ <rs:md change="updated"
12
+ hash="md5:51b99b46c9980623b36b27e06a7e4a46"
13
+ length="446"
14
+ type="text/plain"/>
15
+ </url>
16
+ </urlset>
@@ -9,3 +9,25 @@ RSpec::Matchers.define :request_for do |h|
9
9
  end
10
10
  end
11
11
  end
12
+
13
+ RSpec::Matchers.define :be_time do |expected|
14
+
15
+ def to_string(time)
16
+ time.is_a?(Time) ? time.utc.round(2).iso8601(2) : time.to_s
17
+ end
18
+
19
+ match do |actual|
20
+ if expected
21
+ fail "Expected value #{expected} is not a Time" unless expected.is_a?(Time)
22
+ actual.is_a?(Time) && (to_string(expected) == to_string(actual))
23
+ else
24
+ return actual.nil?
25
+ end
26
+ end
27
+
28
+ failure_message do |actual|
29
+ expected_str = to_string(expected)
30
+ actual_str = to_string(actual)
31
+ "expected time:\n#{expected_str}\n\nbut was:\n#{actual_str}"
32
+ end
33
+ end
@@ -41,6 +41,74 @@ module Resync
41
41
  end
42
42
  end
43
43
 
44
+ describe BaseChangeIndex do
45
+ before(:each) do
46
+ @helper = instance_double(Client::HTTPHelper)
47
+ @client = Client.new(helper: @helper)
48
+ end
49
+
50
+ describe '#all_changes' do
51
+ it 'flattens the child changelists' do
52
+ change_index_uri = URI('http://example.com/dataset1/changelist.xml')
53
+ change_index_data = File.read('spec/data/examples/change-list-index.xml')
54
+ expect(@helper).to receive(:fetch).with(uri: change_index_uri).and_return(change_index_data)
55
+
56
+ list1_uri = URI('http://example.com/20130101-changelist.xml')
57
+ list1_data = File.read('spec/data/examples/change-list-1.xml')
58
+ expect(@helper).to receive(:fetch).with(uri: list1_uri).and_return(list1_data)
59
+
60
+ list2_uri = URI('http://example.com/20130102-changelist.xml')
61
+ list2_data = File.read('spec/data/examples/change-list-2.xml')
62
+ expect(@helper).to receive(:fetch).with(uri: list2_uri).and_return(list2_data)
63
+
64
+ list3_uri = URI('http://example.com/20130103-changelist.xml')
65
+ list3_data = File.read('spec/data/examples/change-list-3.xml')
66
+ expect(@helper).to receive(:fetch).with(uri: list3_uri).and_return(list3_data)
67
+
68
+ expected_mtimes = [
69
+ Time.utc(2013, 1, 1, 1),
70
+ Time.utc(2013, 1, 1, 23),
71
+ Time.utc(2013, 1, 2, 1),
72
+ Time.utc(2013, 1, 2, 23),
73
+ Time.utc(2013, 1, 3, 1)
74
+ ]
75
+
76
+ change_index = @client.get_and_parse(change_index_uri)
77
+ index = 0
78
+ change_index.all_changes(in_range: (Time.utc(0)..Time.new)).each do |c|
79
+ res = index.even? ? 1 : 2
80
+ expect(c.uri).to eq(URI("http://example.com/res#{res}"))
81
+ expect(c.modified_time).to be_time(expected_mtimes[index])
82
+ index += 1
83
+ end
84
+ expect(index).to eq(5)
85
+ end
86
+
87
+ it 'doesn\'t download unnecessary changelists' do
88
+ change_index_uri = URI('http://example.com/dataset1/changelist.xml')
89
+ change_index_data = File.read('spec/data/examples/change-list-index.xml')
90
+ expect(@helper).to receive(:fetch).with(uri: change_index_uri).and_return(change_index_data)
91
+
92
+ list2_uri = URI('http://example.com/20130102-changelist.xml')
93
+ list2_data = File.read('spec/data/examples/change-list-2.xml')
94
+ expect(@helper).to receive(:fetch).with(uri: list2_uri).and_return(list2_data)
95
+
96
+ list3_uri = URI('http://example.com/20130103-changelist.xml')
97
+ list3_data = File.read('spec/data/examples/change-list-3.xml')
98
+ expect(@helper).to receive(:fetch).with(uri: list3_uri).and_return(list3_data)
99
+
100
+ change_index = @client.get_and_parse(change_index_uri)
101
+ count = 0
102
+ change_index.all_changes(in_range: (Time.utc(2013, 1, 2, 12)..Time.utc(2013, 1, 3, 0, 30))).each do |c|
103
+ expect(c.modified_time).to be_time(Time.utc(2013, 1, 2, 23))
104
+ expect(c.uri).to eq(URI('http://example.com/res2'))
105
+ count += 1
106
+ end
107
+ expect(count).to eq(1)
108
+ end
109
+ end
110
+ end
111
+
44
112
  describe Augmented do
45
113
  it 'proxies all link client requests to its own client' do
46
114
  client = instance_double(Resync::Client)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resync-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
@@ -163,6 +163,7 @@ files:
163
163
  - lib/resync/client/http_helper.rb
164
164
  - lib/resync/client/mixins.rb
165
165
  - lib/resync/client/mixins/bitstream_resource.rb
166
+ - lib/resync/client/mixins/change_index.rb
166
167
  - lib/resync/client/mixins/client_delegator.rb
167
168
  - lib/resync/client/mixins/downloadable.rb
168
169
  - lib/resync/client/mixins/dump.rb
@@ -182,6 +183,9 @@ files:
182
183
  - spec/data/examples/capability-list.xml
183
184
  - spec/data/examples/change-dump-manifest.xml
184
185
  - spec/data/examples/change-dump.xml
186
+ - spec/data/examples/change-list-1.xml
187
+ - spec/data/examples/change-list-2.xml
188
+ - spec/data/examples/change-list-3.xml
185
189
  - spec/data/examples/change-list-index.xml
186
190
  - spec/data/examples/change-list.xml
187
191
  - spec/data/examples/resource-dump-manifest.xml
@@ -243,6 +247,9 @@ test_files:
243
247
  - spec/data/examples/capability-list.xml
244
248
  - spec/data/examples/change-dump-manifest.xml
245
249
  - spec/data/examples/change-dump.xml
250
+ - spec/data/examples/change-list-1.xml
251
+ - spec/data/examples/change-list-2.xml
252
+ - spec/data/examples/change-list-3.xml
246
253
  - spec/data/examples/change-list-index.xml
247
254
  - spec/data/examples/change-list.xml
248
255
  - spec/data/examples/resource-dump-manifest.xml