ezid-client 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e7662a25f1a8f0b0c027298428ed9ee5714137c
4
- data.tar.gz: ae70777a70f7ffb50fb00e49e3c86c305e0721d0
3
+ metadata.gz: fea39a10be4faa6f53fc90a1e47912aac563852b
4
+ data.tar.gz: 7812a50e289a44f48d2f7da5d160e87178f5aad2
5
5
  SHA512:
6
- metadata.gz: 68d2a8953cdf238fb34fbb861129b2a34a1e42e1aded1f3a56e3ed720507a67f4313ca67ed6ffe5e59567769c5556fedcf52ebdd69a9e500c0fb1e0893db9bf2
7
- data.tar.gz: 8a0763e0ff8922e9ae2b0c946acf16c8da5f9b64296235efc9f5a5aac2204bd234cf897cecb3af4d87a363f7aba2d95571ce8f15f7557f6ef21d02eed49aaba9
6
+ metadata.gz: 31a187c0ba4f9352093a87e1f86d963ea6d2204a564a81ccef9f4e63990afd709e479c72003a305db1db62c8fe224abea4ce8b335f431cf81e130d257a0e0761
7
+ data.tar.gz: 473bc07ee2231bf9d538097898796e11867162844024f494fddc33add670a44822b4be1ced89c60987328cf1deb1c30bbed4974919c92733ce9f893b74edbba9
@@ -1,6 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 2.3.1
4
5
  - 2.2
5
6
  - 2.1
6
7
  - 2.0.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.0
1
+ 1.6.0
@@ -40,6 +40,7 @@ module Ezid
40
40
 
41
41
  # Parameters
42
42
  property :format, required: true # {anvl|csv|xml}
43
+ property :compression # {gzip|zip}
43
44
  property :column # repeatable
44
45
  property :notify # repeatable
45
46
  property :convertTimestamps # {yes|no}
@@ -87,36 +88,45 @@ module Ezid
87
88
  path ||= Dir.getwd
88
89
  fullpath = File.directory?(path) ? File.join(path, download_filename) : path
89
90
  tries = 0
90
- begin
91
- tries += 1
92
- download = Net::HTTP.get_response(download_uri)
93
- download.value
94
- rescue Net::HTTPServerException => e
95
- if download.is_a?(Net::HTTPNotFound)
96
- if tries < MAX_DOWNLOAD_TRIES
97
- print "Download file not yet available (attempt #{tries} of #{MAX_DOWNLOAD_TRIES})."
98
- puts " Trying again in #{DOWNLOAD_RETRY_INTERVAL} second(s) ..."
99
- sleep DOWNLOAD_RETRY_INTERVAL
100
- retry
101
- else
102
- raise BatchDownloadError,
103
- "Maximum download attempts (#{MAX_DOWNLOAD_TRIES}) reached unsuccessfully."
91
+ ready = false
92
+
93
+ print "Checking for download "
94
+ Net::HTTP.start(download_uri.host, download_uri.port) do |http|
95
+ while tries < MAX_DOWNLOAD_TRIES
96
+ tries += 1
97
+ sleep DOWNLOAD_RETRY_INTERVAL
98
+ print "."
99
+ response = http.head(download_uri.path)
100
+ if response.code == '200'
101
+ ready = true
102
+ break
104
103
  end
105
- else
106
- raise
107
104
  end
108
- else
109
- File.open(fullpath, "wb") do |f|
110
- f.write(download.body)
105
+ end
106
+ puts
107
+
108
+ unless ready
109
+ raise BatchDownloadError,
110
+ "Download not ready after checking #{MAX_DOWNLOAD_TRIES} times."
111
+ end
112
+
113
+ File.open(fullpath, "wb") do |f|
114
+ Net::HTTP.start(download_uri.host, download_uri.port) do |http|
115
+ http.request_get(download_uri.path) do |response|
116
+ response.read_body do |chunk|
117
+ f.write(chunk)
118
+ end
119
+ end
111
120
  end
112
- puts "File successfully download to #{fullpath}."
113
121
  end
122
+
123
+ fullpath
114
124
  end
115
125
 
116
126
  private
117
127
 
118
128
  def download_uri
119
- URI(download_url)
129
+ @download_uri ||= URI(download_url)
120
130
  end
121
131
 
122
132
  def download_filename
@@ -0,0 +1,42 @@
1
+ module Ezid
2
+ class BatchEnumerator
3
+ include Enumerable
4
+
5
+ attr_reader :format, :batch_file
6
+
7
+ def initialize(format, batch_file)
8
+ @format = format
9
+ @batch_file = batch_file
10
+ end
11
+
12
+ def each(&block)
13
+ case format
14
+ when :anvl
15
+ each_anvl(&block)
16
+ when :xml
17
+ each_xml(&block)
18
+ when :csv
19
+ each_csv(&block)
20
+ end
21
+ end
22
+
23
+ def each_anvl(&block)
24
+ File.open(batch_file, "rb") do |f|
25
+ while record = f.gets("")
26
+ head, metadata = record.split(/\n/, 2)
27
+ id = head.sub(/\A::/, "").strip
28
+ yield Ezid::Identifier.new(id, metadata: metadata)
29
+ end
30
+ end
31
+ end
32
+
33
+ def each_xml
34
+ raise NotImplementedError
35
+ end
36
+
37
+ def each_csv
38
+ raise NotImplementedError
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ :: ark:/99999/fk4086hs23
2
+ _updated: 1488227717
3
+ _target: http://example.com
4
+ _profile: erc
5
+ _ownergroup: apitest
6
+ _owner: apitest
7
+ _export: yes
8
+ _created: 1488227717
9
+ _status: public
10
+
11
+ :: ark:/99999/fk4086hs23/123
12
+ _updated: 1488227718
13
+ _target: http://ezid.cdlib.org/id/ark:/99999/fk4086hs23/123
14
+ _profile: erc
15
+ _ownergroup: apitest
16
+ _owner: apitest
17
+ _export: yes
18
+ _created: 1488227718
19
+ _status: public
20
+
21
+ :: ark:/99999/fk40p1bb85
22
+ _updated: 1488303565
23
+ _target: http://ezid.cdlib.org/id/ark:/99999/fk40p1bb85
24
+ _profile: erc
25
+ _ownergroup: apitest
26
+ _owner: apitest
27
+ _export: yes
28
+ _created: 1488303565
29
+ _status: public
30
+
31
+ :: ark:/99999/fk40z7fh7x
32
+ _updated: 1488232856
33
+ _target: http://ezid.cdlib.org/id/ark:/99999/fk40z7fh7x
34
+ _profile: erc
35
+ _ownergroup: apitest
36
+ _owner: apitest
37
+ _export: yes
38
+ _created: 1488232856
39
+ _status: public
@@ -0,0 +1,21 @@
1
+ require 'tempfile'
2
+
3
+ module Ezid
4
+ RSpec.describe BatchDownload do
5
+
6
+ subject do
7
+ a_week_ago = (Time.now - (7*24*60*60)).to_i
8
+ described_class.new(:anvl, compression: "zip", permanence: "test", status: "public", createdAfter: a_week_ago)
9
+ end
10
+
11
+ its(:download_url) { is_expected.to match(/\Ahttp:\/\/ezid\.cdlib\.org\/download\/\w+\.zip\z/) }
12
+
13
+ specify {
14
+ Dir.mktmpdir do |tmpdir|
15
+ expect(subject.download_file(path: tmpdir))
16
+ .to match(/\A#{tmpdir}\/\w+\.zip\z/)
17
+ end
18
+ }
19
+
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ require 'ezid/batch_enumerator'
2
+
3
+ module Ezid
4
+ RSpec.describe BatchEnumerator do
5
+
6
+ let(:batch_file) { File.expand_path("../../fixtures/anvl_batch.txt", __FILE__) }
7
+
8
+ subject { described_class.new(:anvl, batch_file) }
9
+
10
+ its(:count) { is_expected.to eq 4 }
11
+
12
+ specify {
13
+ subject.each do |id|
14
+ expect(id).to be_a(Identifier)
15
+ end
16
+ }
17
+
18
+ specify {
19
+ batch_array = subject.to_a
20
+ expect(batch_array.length).to eq 4
21
+ }
22
+
23
+ specify {
24
+ ids = subject.map(&:id)
25
+ expect(ids).to eq ["ark:/99999/fk4086hs23", "ark:/99999/fk4086hs23/123", "ark:/99999/fk40p1bb85", "ark:/99999/fk40z7fh7x"]
26
+ }
27
+
28
+ specify {
29
+ id = subject.first
30
+ expect(id.target).to eq "http://example.com"
31
+ }
32
+
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezid-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-24 00:00:00.000000000 Z
11
+ date: 2017-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -104,6 +104,7 @@ files:
104
104
  - ezid-client.gemspec
105
105
  - lib/ezid-client.rb
106
106
  - lib/ezid/batch_download.rb
107
+ - lib/ezid/batch_enumerator.rb
107
108
  - lib/ezid/client.rb
108
109
  - lib/ezid/configuration.rb
109
110
  - lib/ezid/error.rb
@@ -137,11 +138,13 @@ files:
137
138
  - lib/ezid/session.rb
138
139
  - lib/ezid/status.rb
139
140
  - lib/ezid/test_helper.rb
141
+ - spec/fixtures/anvl_batch.txt
142
+ - spec/integration/batch_download_spec.rb
140
143
  - spec/integration/client_spec.rb
141
144
  - spec/integration/identifier_spec.rb
142
145
  - spec/spec_helper.rb
143
146
  - spec/unit/batch_download_request_spec.rb
144
- - spec/unit/batch_download_spec.rb
147
+ - spec/unit/batch_enumerator_spec.rb
145
148
  - spec/unit/client_spec.rb
146
149
  - spec/unit/identifier_spec.rb
147
150
  - spec/unit/metadata_spec.rb
@@ -166,16 +169,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
169
  version: '0'
167
170
  requirements: []
168
171
  rubyforge_project:
169
- rubygems_version: 2.4.3
172
+ rubygems_version: 2.6.8
170
173
  signing_key:
171
174
  specification_version: 4
172
175
  summary: Ruby client for EZID API Version 2
173
176
  test_files:
177
+ - spec/fixtures/anvl_batch.txt
178
+ - spec/integration/batch_download_spec.rb
174
179
  - spec/integration/client_spec.rb
175
180
  - spec/integration/identifier_spec.rb
176
181
  - spec/spec_helper.rb
177
182
  - spec/unit/batch_download_request_spec.rb
178
- - spec/unit/batch_download_spec.rb
183
+ - spec/unit/batch_enumerator_spec.rb
179
184
  - spec/unit/client_spec.rb
180
185
  - spec/unit/identifier_spec.rb
181
186
  - spec/unit/metadata_spec.rb
@@ -1,5 +0,0 @@
1
- module Ezid
2
- RSpec.describe BatchDownload do
3
- # TODO
4
- end
5
- end