ezid-client 1.5.0 → 1.9.0.rc1
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 +5 -5
- data/.github/workflows/ruby.yml +35 -0
- data/README.md +59 -13
- data/Rakefile +6 -6
- data/VERSION +1 -1
- data/ezid-client.gemspec +5 -3
- data/lib/ezid/batch.rb +42 -0
- data/lib/ezid/batch_download.rb +35 -21
- data/lib/ezid/client.rb +11 -10
- data/lib/ezid/configuration.rb +11 -4
- data/lib/ezid/error.rb +2 -0
- data/lib/ezid/identifier.rb +57 -20
- data/lib/ezid/metadata.rb +11 -1
- data/lib/ezid/metadata_transforms/datacite.rb +72 -0
- data/lib/ezid/requests/request.rb +22 -9
- data/lib/ezid/responses/response.rb +13 -0
- data/spec/fixtures/anvl_batch.txt +39 -0
- data/spec/fixtures/datacite_xml/empty.xml +1 -0
- data/spec/fixtures/datacite_xml/populated.xml +1 -0
- data/spec/integration/batch_download_spec.rb +21 -0
- data/spec/integration/client_spec.rb +1 -1
- data/spec/integration/identifier_spec.rb +3 -2
- data/spec/spec_helper.rb +4 -2
- data/spec/unit/batch_spec.rb +34 -0
- data/spec/unit/client_spec.rb +35 -3
- data/spec/unit/identifier_spec.rb +54 -15
- data/spec/unit/metadata_spec.rb +2 -0
- data/spec/unit/metadata_transform_datacite_spec.rb +169 -0
- metadata +60 -21
- data/.travis.yml +0 -9
- data/spec/unit/batch_download_spec.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 992d846692204d2ee3317ba756f1f70448a1194fb8e2d7cf129dd9b7f270919e
|
4
|
+
data.tar.gz: 3dba7c268214d865b85425cfb18ad3dd5f2e23d1b8a0c21ed14366b4aaae283c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 161c7c1037a3016c2399b24e3f6fb6addfd91988e3b97149da907bd5461a72b29eb9058d403067b9a166ba6eea40bd58fd7f291a11100a698b93e24a9d228159
|
7
|
+
data.tar.gz: 3538d1792458f2d53ee81868249c3217112994aea0da67e1023eda3526bc98246282b90d87a346287e12f7eadd24874a48f5d521f055ea5a34d1130844832b87
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ develop ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ develop ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.6', '2.7']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rspec ./spec/unit/
|
data/README.md
CHANGED
@@ -33,9 +33,11 @@ Or install it yourself as:
|
|
33
33
|
>> identifier = Ezid::Identifier.mint("ark:/99999/fk4")
|
34
34
|
I, [2016-03-01T22:20:08.505323 #35148] INFO -- : EZID MintIdentifier -- success: ark:/99999/fk4tq65d6k
|
35
35
|
=> #<Ezid::Identifier id=ark:/99999/fk4tq65d6k>
|
36
|
+
|
36
37
|
>> identifier.status
|
37
38
|
I, [2016-03-01T22:20:22.323650 #35148] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk4tq65d6k
|
38
39
|
=> "public"
|
40
|
+
|
39
41
|
>> identifier.target
|
40
42
|
=> "http://ezid.cdlib.org/id/ark:/99999/fk4tq65d6k"
|
41
43
|
```
|
@@ -87,11 +89,14 @@ I, [2014-12-04T15:07:00.648676 #86655] INFO -- : EZID GetIdentifierMetadata --
|
|
87
89
|
```
|
88
90
|
>> identifier.target
|
89
91
|
=> "http://ezid.cdlib.org/id/ark:/99999/fk43f4wd4v"
|
92
|
+
|
90
93
|
>> identifier.target = "http://example.com"
|
91
94
|
=> "http://example.com"
|
95
|
+
|
92
96
|
>> identifier.save
|
93
97
|
I, [2014-12-09T11:24:26.321801 #32279] INFO -- : EZID ModifyIdentifier -- success: ark:/99999/fk43f4wd4v
|
94
98
|
=> #<Ezid::Identifier id="ark:/99999/fk43f4wd4v">
|
99
|
+
|
95
100
|
>> identifier.target
|
96
101
|
I, [2014-12-09T11:24:27.039288 #32279] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk43f4wd4v
|
97
102
|
=> "http://example.com"
|
@@ -107,6 +112,7 @@ I, [2014-12-09T11:24:27.039288 #32279] INFO -- : EZID GetIdentifierMetadata --
|
|
107
112
|
>> identifier = Ezid::Identifier.mint("ark:/99999/fk4", status: "reserved")
|
108
113
|
I, [2016-03-01T22:26:08.645858 #36701] INFO -- : EZID MintIdentifier -- success: ark:/99999/fk4pz5fm1b
|
109
114
|
=> #<Ezid::Identifier id=ark:/99999/fk4pz5fm1b>
|
115
|
+
|
110
116
|
>> identifier.delete
|
111
117
|
I, [2016-03-01T22:26:14.829731 #36701] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk4pz5fm1b
|
112
118
|
I, [2016-03-01T22:26:15.711390 #36701] INFO -- : EZID DeleteIdentifier -- success: ark:/99999/fk4pz5fm1b
|
@@ -120,22 +126,57 @@ See http://ezid.cdlib.org/doc/apidoc.html#parameters. Repeated values should be
|
|
120
126
|
*Added in v1.3.0:* `Ezid::BatchDownload` class.
|
121
127
|
|
122
128
|
```
|
123
|
-
>>
|
129
|
+
>> batch_download = Ezid::BatchDownload.new(:csv)
|
124
130
|
=> #<Ezid::BatchDownload format=:csv>
|
125
|
-
|
131
|
+
|
132
|
+
>> batch_download.column = ["_id", "_target"]
|
126
133
|
=> ["_id", "_target"]
|
127
|
-
|
134
|
+
|
135
|
+
>> batch_download.createdAfter = Date.today.to_time
|
128
136
|
=> 2016-02-24 00:00:00 -0500
|
129
|
-
|
137
|
+
|
138
|
+
>> batch_download
|
130
139
|
=> #<Ezid::BatchDownload column=["_id", "_target"] createdAfter=1456290000 format=:csv>
|
131
|
-
|
140
|
+
|
141
|
+
>> batch_download.url
|
132
142
|
I, [2016-02-24T18:03:40.828005 #1084] INFO -- : EZID BatchDownload -- success: http://ezid.cdlib.org/download/4a63401e17.csv.gz
|
133
143
|
=> "http://ezid.cdlib.org/download/4a63401e17.csv.gz"
|
134
|
-
|
135
|
-
|
136
|
-
=>
|
144
|
+
|
145
|
+
>> batch_download.file
|
146
|
+
=> /current/working/directory/4a63401e17.csv.gz
|
137
147
|
```
|
138
148
|
|
149
|
+
## Batch
|
150
|
+
|
151
|
+
*Added in v1.6.0.* `Ezid::Batch` class.
|
152
|
+
|
153
|
+
**Version 1.7.0 upgrade note:** This class was originally named `Ezid::BatchEnumerator`, but it is not a Ruby enumerator. `Ezid::Batch` is the new name with the same API.
|
154
|
+
|
155
|
+
```
|
156
|
+
>> require 'ezid/batch'
|
157
|
+
=> true
|
158
|
+
|
159
|
+
>> batch = Ezid::Batch.new(:anvl, "spec/fixtures/anvl_batch.txt")
|
160
|
+
=> #<Ezid::Batch:0x007f87a8900308 @format=:anvl, @batch_file="spec/fixtures/anvl_batch.txt">
|
161
|
+
|
162
|
+
>> id = batch.first
|
163
|
+
=> #<Ezid::Identifier id=ark:/99999/fk4086hs23>
|
164
|
+
|
165
|
+
>> id.target
|
166
|
+
=> "http://example.com"
|
167
|
+
|
168
|
+
>> puts id.metadata
|
169
|
+
_updated: 1488227717
|
170
|
+
_target: http://example.com
|
171
|
+
_profile: erc
|
172
|
+
_ownergroup: apitest
|
173
|
+
_owner: apitest
|
174
|
+
_export: yes
|
175
|
+
_created: 1488227717
|
176
|
+
_status: public
|
177
|
+
=> nil
|
178
|
+
```
|
179
|
+
|
139
180
|
## Metadata handling
|
140
181
|
|
141
182
|
Accessors are provided to ease the use of EZID [reserved metadata elements](http://ezid.cdlib.org/doc/apidoc.html#internal-metadata) and [metadata profiles](http://ezid.cdlib.org/doc/apidoc.html#metadata-profiles):
|
@@ -145,6 +186,7 @@ Accessors are provided to ease the use of EZID [reserved metadata elements](http
|
|
145
186
|
```
|
146
187
|
>> identifier.status # reads "_status" element
|
147
188
|
=> "public"
|
189
|
+
|
148
190
|
>> identifier.status = "unavailable" # writes "_status" element
|
149
191
|
=> "unavailable"
|
150
192
|
```
|
@@ -159,6 +201,7 @@ Notes:
|
|
159
201
|
```
|
160
202
|
>> identifier.dc_type # reads "dc.type" element
|
161
203
|
=> "Collection"
|
204
|
+
|
162
205
|
>> identifier.dc_type = "Image" # writes "dc.type" element
|
163
206
|
=> "Image"
|
164
207
|
```
|
@@ -253,11 +296,10 @@ require "ezid/test_helper"
|
|
253
296
|
|
254
297
|
The module provides constants:
|
255
298
|
|
256
|
-
- `
|
257
|
-
- `
|
258
|
-
- `
|
259
|
-
- `
|
260
|
-
- `TEST_PORT` => 443
|
299
|
+
- `EZID_TEST_SHOULDER` => "doi:10.5072/FK2"
|
300
|
+
- `EZID_TEST_USER` => "apitest"
|
301
|
+
- `EZID_TEST_HOST` => "ezid.cdlib.org"
|
302
|
+
- `EZID_TEST_PORT` => 443
|
261
303
|
|
262
304
|
The test user password is not provided - contact EZID and configure as above - or use your own EZID credentials, since all accounts can mint/create on the test shoulders.
|
263
305
|
|
@@ -283,3 +325,7 @@ In order to run the integration tests successfully, you must supply the password
|
|
283
325
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
284
326
|
4. Push to the branch (`git push origin my-new-feature`)
|
285
327
|
5. Create a new Pull Request
|
328
|
+
|
329
|
+
## Acknowledgments
|
330
|
+
|
331
|
+
- Justin Gondron (jgondron) contributed Datacite compatibility code (added in v1.8.0).
|
data/Rakefile
CHANGED
@@ -5,18 +5,18 @@ desc "Run all specs in spec directory"
|
|
5
5
|
RSpec::Core::RakeTask.new(:spec)
|
6
6
|
|
7
7
|
desc "Run the ci build (no integration tests)"
|
8
|
-
|
9
|
-
|
8
|
+
RSpec::Core::RakeTask.new(:ci) do |t|
|
9
|
+
t.rspec_opts = "--tag '~deprecated' --tag '~ezid'"
|
10
10
|
end
|
11
11
|
|
12
12
|
desc "Run tests of deprecated functionality"
|
13
|
-
|
14
|
-
|
13
|
+
RSpec::Core::RakeTask.new(:deprecated) do |t|
|
14
|
+
t.rspec_opts = "--tag deprecated"
|
15
15
|
end
|
16
16
|
|
17
17
|
desc "Run the integration tests"
|
18
|
-
|
19
|
-
|
18
|
+
RSpec::Core::RakeTask.new(:integration) do |t|
|
19
|
+
t.rspec_opts = "--tag integration"
|
20
20
|
end
|
21
21
|
|
22
22
|
task default: :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.9.0.rc1
|
data/ezid-client.gemspec
CHANGED
@@ -17,12 +17,14 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.required_ruby_version = "~> 2.
|
20
|
+
spec.required_ruby_version = "~> 2.1"
|
21
21
|
|
22
22
|
spec.add_dependency "hashie", "~> 3.4", ">= 3.4.3"
|
23
|
+
spec.add_dependency "nokogiri"
|
23
24
|
|
24
|
-
spec.add_development_dependency "bundler"
|
25
|
-
spec.add_development_dependency "
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
spec.add_development_dependency "byebug"
|
27
|
+
spec.add_development_dependency "rake"
|
26
28
|
spec.add_development_dependency "rspec", "~> 3.4"
|
27
29
|
spec.add_development_dependency "rspec-its", "~> 1.2"
|
28
30
|
end
|
data/lib/ezid/batch.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Ezid
|
2
|
+
class Batch
|
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 Identifier.load(id, 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
|
data/lib/ezid/batch_download.rb
CHANGED
@@ -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}
|
@@ -83,40 +84,53 @@ module Ezid
|
|
83
84
|
get_response.download_url
|
84
85
|
end
|
85
86
|
|
87
|
+
alias_method :url, :download_url
|
88
|
+
|
86
89
|
def download_file(path: nil)
|
87
90
|
path ||= Dir.getwd
|
88
91
|
fullpath = File.directory?(path) ? File.join(path, download_filename) : path
|
89
92
|
tries = 0
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
raise BatchDownloadError,
|
103
|
-
"Maximum download attempts (#{MAX_DOWNLOAD_TRIES}) reached unsuccessfully."
|
93
|
+
ready = false
|
94
|
+
|
95
|
+
print "Checking for download "
|
96
|
+
Net::HTTP.start(download_uri.host, download_uri.port) do |http|
|
97
|
+
while tries < MAX_DOWNLOAD_TRIES
|
98
|
+
tries += 1
|
99
|
+
sleep DOWNLOAD_RETRY_INTERVAL
|
100
|
+
print "."
|
101
|
+
response = http.head(download_uri.path)
|
102
|
+
if response.code == '200'
|
103
|
+
ready = true
|
104
|
+
break
|
104
105
|
end
|
105
|
-
else
|
106
|
-
raise
|
107
106
|
end
|
108
|
-
|
109
|
-
|
110
|
-
|
107
|
+
end
|
108
|
+
puts
|
109
|
+
|
110
|
+
unless ready
|
111
|
+
raise BatchDownloadError,
|
112
|
+
"Download not ready after checking #{MAX_DOWNLOAD_TRIES} times."
|
113
|
+
end
|
114
|
+
|
115
|
+
File.open(fullpath, "wb") do |f|
|
116
|
+
Net::HTTP.start(download_uri.host, download_uri.port) do |http|
|
117
|
+
http.request_get(download_uri.path) do |response|
|
118
|
+
response.read_body do |chunk|
|
119
|
+
f.write(chunk)
|
120
|
+
end
|
121
|
+
end
|
111
122
|
end
|
112
|
-
puts "File successfully download to #{fullpath}."
|
113
123
|
end
|
124
|
+
|
125
|
+
fullpath
|
114
126
|
end
|
115
127
|
|
128
|
+
alias_method :file, :download_file
|
129
|
+
|
116
130
|
private
|
117
131
|
|
118
132
|
def download_uri
|
119
|
-
URI(download_url)
|
133
|
+
@download_uri ||= URI(download_url)
|
120
134
|
end
|
121
135
|
|
122
136
|
def download_filename
|
data/lib/ezid/client.rb
CHANGED
@@ -44,12 +44,11 @@ module Ezid
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
attr_reader :user, :password, :host, :port, :
|
47
|
+
attr_reader :user, :password, :host, :port, :timeout
|
48
48
|
|
49
49
|
def initialize(opts = {})
|
50
50
|
@host = opts[:host] || config.host
|
51
51
|
@port = (opts[:port] || config.port).to_i
|
52
|
-
@use_ssl = opts[:use_ssl] || config.use_ssl
|
53
52
|
@timeout = (opts[:timeout] || config.timeout).to_i
|
54
53
|
@user = opts[:user] || config.user
|
55
54
|
@password = opts[:password] || config.password
|
@@ -60,6 +59,12 @@ module Ezid
|
|
60
59
|
end
|
61
60
|
end
|
62
61
|
|
62
|
+
def use_ssl
|
63
|
+
warn "[DEPRECATION] `use_ssl` is deprecated and will be removed in ezid-client v2.0." \
|
64
|
+
" EZID requires SSL as of April 30, 2017."
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
63
68
|
def inspect
|
64
69
|
"#<#{self.class.name} connection=#{connection.inspect}, " \
|
65
70
|
"user=#{user.inspect}, session=#{logged_in? ? 'OPEN' : 'CLOSED'}>"
|
@@ -188,15 +193,11 @@ module Ezid
|
|
188
193
|
|
189
194
|
private
|
190
195
|
|
191
|
-
def use_ssl?
|
192
|
-
use_ssl || port == 443
|
193
|
-
end
|
194
|
-
|
195
196
|
def build_connection
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
197
|
+
Net::HTTP.new(host, port).tap do |conn|
|
198
|
+
conn.use_ssl = true
|
199
|
+
conn.read_timeout = timeout
|
200
|
+
end
|
200
201
|
end
|
201
202
|
|
202
203
|
def handle_response(response, request_name)
|
data/lib/ezid/configuration.rb
CHANGED
@@ -20,9 +20,6 @@ module Ezid
|
|
20
20
|
# EZID TCP/IP port
|
21
21
|
attr_accessor :port
|
22
22
|
|
23
|
-
# Use HTTPS?
|
24
|
-
attr_accessor :use_ssl
|
25
|
-
|
26
23
|
# HTTP read timeout (seconds)
|
27
24
|
attr_accessor :timeout
|
28
25
|
|
@@ -44,7 +41,6 @@ module Ezid
|
|
44
41
|
@password = ENV["EZID_PASSWORD"]
|
45
42
|
@host = ENV["EZID_HOST"] || HOST
|
46
43
|
@port = ENV["EZID_PORT"] || PORT
|
47
|
-
@use_ssl = true if ENV["EZID_USE_SSL"] == true.to_s
|
48
44
|
@timeout = ENV["EZID_TIMEOUT"] || TIMEOUT
|
49
45
|
@default_shoulder = ENV["EZID_DEFAULT_SHOULDER"]
|
50
46
|
end
|
@@ -67,5 +63,16 @@ module Ezid
|
|
67
63
|
Metadata
|
68
64
|
end
|
69
65
|
|
66
|
+
def use_ssl
|
67
|
+
warn "[DEPRECATION] `use_ssl` is deprecated and will be removed in ezid-client v2.0." \
|
68
|
+
" EZID requires SSL as of April 30, 2017."
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
def use_ssl=(*)
|
73
|
+
warn "[DEPRECATION] `use_ssl=` is deprecated and will be removed in ezid-client v2.0." \
|
74
|
+
" EZID requires SSL as of April 30, 2017."
|
75
|
+
end
|
76
|
+
|
70
77
|
end
|
71
78
|
end
|