ezid-client 1.9.0 → 1.9.2
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 +4 -4
- data/.github/workflows/ruby.yml +3 -3
- data/VERSION +1 -1
- data/ezid-client.gemspec +1 -1
- data/lib/ezid/configuration.rb +6 -0
- data/lib/ezid/requests/request.rb +1 -1
- data/lib/ezid/responses/response.rb +2 -5
- data/lib/ezid/test_helper.rb +1 -0
- data/spec/unit/client_spec.rb +93 -34
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 876241ea3672fa20c64c5628939237b83560ef2833334760b8c21b1eeafb23df
|
4
|
+
data.tar.gz: 9c9211dd5ca384485ab8d689d57e6f105b90fc7cf15c6b194bf0b9b322202e30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0df8164ae4f1398e01bdc39efee4839fdb5e063ca5b0069b1df93984f5038af93771e628c82e7ef03c23e02efdc08a94905559b0e8dcfddd9380850cf23b1bc2
|
7
|
+
data.tar.gz: 5584cca4d185f750fc860cd07ffc1d08bc1fb76683202c9805c63c2cbc6eab375a044cef5865af226ff0fd7034764db560a05fbc769d71d3eab9133faebf561f
|
data/.github/workflows/ruby.yml
CHANGED
@@ -9,9 +9,9 @@ name: Ruby
|
|
9
9
|
|
10
10
|
on:
|
11
11
|
push:
|
12
|
-
branches: [
|
12
|
+
branches: [ main ]
|
13
13
|
pull_request:
|
14
|
-
branches: [
|
14
|
+
branches: [ main ]
|
15
15
|
|
16
16
|
jobs:
|
17
17
|
test:
|
@@ -19,7 +19,7 @@ jobs:
|
|
19
19
|
runs-on: ubuntu-latest
|
20
20
|
strategy:
|
21
21
|
matrix:
|
22
|
-
ruby-version: ['2.6', '2.7']
|
22
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
23
23
|
|
24
24
|
steps:
|
25
25
|
- uses: actions/checkout@v2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.
|
1
|
+
1.9.2
|
data/ezid-client.gemspec
CHANGED
@@ -17,7 +17,7 @@ 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 = "
|
20
|
+
spec.required_ruby_version = ">= 2.1"
|
21
21
|
|
22
22
|
spec.add_dependency "hashie", "~> 3.4", ">= 3.4.3"
|
23
23
|
spec.add_dependency "nokogiri"
|
data/lib/ezid/configuration.rb
CHANGED
@@ -36,6 +36,11 @@ module Ezid
|
|
36
36
|
# @example "ark:/99999/fk4"
|
37
37
|
attr_accessor :default_shoulder
|
38
38
|
|
39
|
+
# Interval in seconds to wait between
|
40
|
+
# retries of failed requests
|
41
|
+
# @see Ezid::Request#execute.
|
42
|
+
attr_accessor :retry_interval
|
43
|
+
|
39
44
|
def initialize
|
40
45
|
@user = ENV["EZID_USER"]
|
41
46
|
@password = ENV["EZID_PASSWORD"]
|
@@ -43,6 +48,7 @@ module Ezid
|
|
43
48
|
@port = ENV["EZID_PORT"] || PORT
|
44
49
|
@timeout = ENV["EZID_TIMEOUT"] || TIMEOUT
|
45
50
|
@default_shoulder = ENV["EZID_DEFAULT_SHOULDER"]
|
51
|
+
@retry_interval = ( ENV["EZID_RETRY_INTERVAL"] || 15 ).to_i
|
46
52
|
end
|
47
53
|
|
48
54
|
def inspect
|
@@ -15,12 +15,9 @@ module Ezid
|
|
15
15
|
ERROR = "error".freeze
|
16
16
|
|
17
17
|
def initialize(http_response)
|
18
|
-
|
18
|
+
http_response.value # raises Net::HTTPServerException
|
19
19
|
|
20
|
-
|
21
|
-
raise Error, "HTTP response error: %s %s" %
|
22
|
-
[ __getobj__.code, __getobj__.message ]
|
23
|
-
end
|
20
|
+
super
|
24
21
|
|
25
22
|
unless status_line =~ /^(#{SUCCESS}|#{ERROR}): /
|
26
23
|
raise UnexpectedResponseError, __getobj__.body
|
data/lib/ezid/test_helper.rb
CHANGED
data/spec/unit/client_spec.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
module Ezid
|
2
2
|
RSpec.describe Client do
|
3
3
|
|
4
|
-
let(:http_response) { double }
|
5
|
-
|
6
|
-
|
7
|
-
allow(http_response).to receive(:value) { nil }
|
8
|
-
allow(http_response).to receive(:code) { '200' }
|
9
|
-
end
|
4
|
+
let(:http_response) { double(value: value, body: body) }
|
5
|
+
let(:value) { nil }
|
6
|
+
let(:body) { '' }
|
10
7
|
|
11
8
|
describe "initialization without a block" do
|
12
|
-
let(:http_response) { double }
|
13
9
|
it "should not login" do
|
14
10
|
expect_any_instance_of(described_class).not_to receive(:login)
|
15
11
|
described_class.new
|
@@ -18,12 +14,14 @@ module Ezid
|
|
18
14
|
|
19
15
|
describe "#create_identifier" do
|
20
16
|
let(:id) { "ark:/99999/fk4fn19h88" }
|
21
|
-
let(:
|
17
|
+
let(:body) { "success: ark:/99999/fk4fn19h88" }
|
22
18
|
let(:stub_response) { CreateIdentifierResponse.new(http_response) }
|
19
|
+
|
23
20
|
before do
|
24
21
|
allow(CreateIdentifierRequest).to receive(:execute).with(subject, id, nil) { stub_response }
|
25
22
|
end
|
26
|
-
|
23
|
+
|
24
|
+
it "is a success" do
|
27
25
|
response = subject.create_identifier(id)
|
28
26
|
expect(response).to be_success
|
29
27
|
expect(response.id).to eq(id)
|
@@ -32,19 +30,22 @@ module Ezid
|
|
32
30
|
|
33
31
|
describe "#mint_identifier" do
|
34
32
|
let(:stub_response) { MintIdentifierResponse.new(http_response) }
|
33
|
+
|
35
34
|
before do
|
36
35
|
allow(MintIdentifierRequest).to receive(:execute).with(subject, TEST_ARK_SHOULDER, nil) { stub_response }
|
37
36
|
end
|
37
|
+
|
38
38
|
describe "which is an ARK" do
|
39
|
-
let(:
|
39
|
+
let(:body) { "success: ark:/99999/fk4fn19h88" }
|
40
40
|
it "should be a success" do
|
41
41
|
response = subject.mint_identifier(TEST_ARK_SHOULDER)
|
42
42
|
expect(response).to be_success
|
43
43
|
expect(response.id).to eq("ark:/99999/fk4fn19h88")
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
46
47
|
describe "which is a DOI" do
|
47
|
-
let(:
|
48
|
+
let(:body) { "success: doi:10.5072/FK2TEST | ark:/99999/fk4fn19h88" }
|
48
49
|
let(:metadata) do
|
49
50
|
<<-EOS
|
50
51
|
datacite.title: Test
|
@@ -54,31 +55,38 @@ datacite.publicationyear: 2014
|
|
54
55
|
datacite.resourcetype: Other
|
55
56
|
EOS
|
56
57
|
end
|
58
|
+
|
57
59
|
before do
|
58
60
|
allow(MintIdentifierRequest).to receive(:execute).with(subject, TEST_DOI_SHOULDER, metadata) { stub_response }
|
59
61
|
end
|
60
|
-
|
62
|
+
|
63
|
+
it "is a success" do
|
61
64
|
response = subject.mint_identifier(TEST_DOI_SHOULDER, metadata)
|
62
65
|
expect(response).to be_success
|
63
66
|
expect(response.id).to eq("doi:10.5072/FK2TEST")
|
64
67
|
expect(response.shadow_ark).to eq("ark:/99999/fk4fn19h88")
|
65
68
|
end
|
66
69
|
end
|
70
|
+
|
67
71
|
describe "when a shoulder is not given" do
|
68
|
-
let(:
|
72
|
+
let(:body) { "success: ark:/99999/fk4fn19h88" }
|
73
|
+
|
69
74
|
context "and the :default_shoulder config option is set" do
|
70
75
|
before do
|
71
76
|
allow(MintIdentifierRequest).to receive(:execute).with(subject, TEST_ARK_SHOULDER, nil) { stub_response }
|
72
77
|
allow(Client.config).to receive(:default_shoulder) { TEST_ARK_SHOULDER }
|
73
78
|
end
|
74
|
-
|
79
|
+
|
80
|
+
it "uses the default shoulder" do
|
75
81
|
response = subject.mint_identifier
|
76
82
|
expect(response).to be_success
|
77
83
|
end
|
78
84
|
end
|
85
|
+
|
79
86
|
context "and the :default_shoulder config option is not set" do
|
80
87
|
before { allow(Client.config).to receive(:default_shoulder) { nil } }
|
81
|
-
|
88
|
+
|
89
|
+
it "raises an exception" do
|
82
90
|
expect { subject.mint_identifier }.to raise_error(Error)
|
83
91
|
end
|
84
92
|
end
|
@@ -87,8 +95,8 @@ EOS
|
|
87
95
|
|
88
96
|
describe "#get_identifier_metadata" do
|
89
97
|
let(:id) { "ark:/99999/fk4fn19h88" }
|
90
|
-
let(:
|
91
|
-
|
98
|
+
let(:body) do
|
99
|
+
<<-EOS
|
92
100
|
success: ark:/99999/fk4fn19h88
|
93
101
|
_updated: 1416507086
|
94
102
|
_target: http://ezid.cdlib.org/id/ark:/99999/fk4fn19h88
|
@@ -99,13 +107,15 @@ _export: yes
|
|
99
107
|
_created: 1416507086
|
100
108
|
_status: public
|
101
109
|
EOS
|
102
|
-
|
110
|
+
|
103
111
|
end
|
104
112
|
let(:stub_response) { GetIdentifierMetadataResponse.new(http_response) }
|
113
|
+
|
105
114
|
before do
|
106
115
|
allow(GetIdentifierMetadataRequest).to receive(:execute).with(subject, id) { stub_response }
|
107
116
|
end
|
108
|
-
|
117
|
+
|
118
|
+
it "retrieves the metadata" do
|
109
119
|
response = subject.get_identifier_metadata(id)
|
110
120
|
expect(response).to be_success
|
111
121
|
expect(response.metadata).to eq <<-EOS
|
@@ -123,18 +133,20 @@ EOS
|
|
123
133
|
|
124
134
|
describe "server status" do
|
125
135
|
let(:stub_response) { ServerStatusResponse.new(http_response) }
|
126
|
-
let(:
|
127
|
-
|
136
|
+
let(:body) do
|
137
|
+
<<-EOS
|
128
138
|
success: EZID is up
|
129
139
|
noid: up
|
130
140
|
ldap: up
|
131
141
|
EOS
|
132
|
-
|
142
|
+
|
133
143
|
end
|
144
|
+
|
134
145
|
before do
|
135
146
|
allow(ServerStatusRequest).to receive(:execute).with(subject, "*") { stub_response }
|
136
147
|
end
|
137
|
-
|
148
|
+
|
149
|
+
it "reports the status of EZID and subsystems" do
|
138
150
|
response = subject.server_status("*")
|
139
151
|
expect(response).to be_success
|
140
152
|
expect(response).to be_up
|
@@ -147,11 +159,13 @@ EOS
|
|
147
159
|
|
148
160
|
describe "batch download" do
|
149
161
|
let(:stub_response) { BatchDownloadResponse.new(http_response) }
|
150
|
-
let(:
|
162
|
+
let(:body) { "success: http://ezid.cdlib.org/download/da543b91a0.xml.gz" }
|
163
|
+
|
151
164
|
before do
|
152
165
|
allow(BatchDownloadRequest).to receive(:execute).with(subject, format: "xml") { stub_response }
|
153
166
|
end
|
154
|
-
|
167
|
+
|
168
|
+
it "returns the URL to download the batch" do
|
155
169
|
response = subject.batch_download(format: "xml")
|
156
170
|
expect(response).to be_success
|
157
171
|
expect(response.download_url).to eq("http://ezid.cdlib.org/download/da543b91a0.xml.gz")
|
@@ -160,33 +174,78 @@ EOS
|
|
160
174
|
|
161
175
|
describe "error handling" do
|
162
176
|
let(:stub_response) { GetIdentifierMetadataResponse.new(http_response) }
|
177
|
+
|
163
178
|
before do
|
164
179
|
allow(GetIdentifierMetadataRequest).to receive(:execute).with(subject, "invalid") { stub_response }
|
165
180
|
end
|
166
181
|
|
167
182
|
describe "HTTP error response" do
|
168
183
|
before do
|
169
|
-
allow(http_response).to receive(:
|
170
|
-
allow(http_response).to receive(:message) { 'Internal Server Error' }
|
184
|
+
allow(http_response).to receive(:value).and_raise(Net::HTTPServerException.new('Barf!', double))
|
171
185
|
end
|
172
|
-
|
173
|
-
|
186
|
+
|
187
|
+
it "raises an exception" do
|
188
|
+
expect { subject.get_identifier_metadata("invalid") }.to raise_error(Net::HTTPServerException)
|
174
189
|
end
|
175
190
|
end
|
176
191
|
|
177
192
|
describe "EZID API error response" do
|
178
|
-
let(:
|
179
|
-
|
193
|
+
let(:body) { "error: bad request - no such identifier" }
|
194
|
+
|
195
|
+
it "raises an exception" do
|
180
196
|
expect { subject.get_identifier_metadata("invalid") }.to raise_error(Error)
|
181
197
|
end
|
182
198
|
end
|
183
199
|
|
184
|
-
describe "Unexpected response" do
|
185
|
-
let(:
|
186
|
-
|
200
|
+
describe "Unexpected response (body)" do
|
201
|
+
let(:body) do
|
202
|
+
<<-EOS
|
203
|
+
<html>
|
204
|
+
<head>
|
205
|
+
<title>Ouch!</title>
|
206
|
+
</head>
|
207
|
+
<body>
|
208
|
+
Help!
|
209
|
+
</body>
|
210
|
+
</html>
|
211
|
+
EOS
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
it "raises an exception" do
|
187
216
|
expect { subject.get_identifier_metadata("invalid") }.to raise_error(UnexpectedResponseError)
|
188
217
|
end
|
189
218
|
end
|
190
219
|
end
|
220
|
+
|
221
|
+
describe "retrying on certain errors" do
|
222
|
+
before do
|
223
|
+
allow(GetIdentifierMetadataResponse).to receive(:new).and_raise(exception)
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "HTTP error" do
|
227
|
+
let(:exception) { Net::HTTPServerException.new('Barf!', double) }
|
228
|
+
|
229
|
+
it "retries twice" do
|
230
|
+
begin
|
231
|
+
subject.get_identifier_metadata("invalid")
|
232
|
+
rescue Exception => _
|
233
|
+
end
|
234
|
+
expect(GetIdentifierMetadataResponse).to have_received(:new).exactly(3).times
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
describe "Unexpected response" do
|
239
|
+
let(:exception) { UnexpectedResponseError.new("HTML?!") }
|
240
|
+
|
241
|
+
it "retries twice" do
|
242
|
+
begin
|
243
|
+
subject.get_identifier_metadata("invalid")
|
244
|
+
rescue Exception => _
|
245
|
+
end
|
246
|
+
expect(GetIdentifierMetadataResponse).to have_received(:new).exactly(3).times
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
191
250
|
end
|
192
251
|
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.9.
|
4
|
+
version: 1.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Chandek-Stark
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -185,13 +185,13 @@ homepage: https://github.com/duke-libraries/ezid-client
|
|
185
185
|
licenses:
|
186
186
|
- BSD-3-Clause
|
187
187
|
metadata: {}
|
188
|
-
post_install_message:
|
188
|
+
post_install_message:
|
189
189
|
rdoc_options: []
|
190
190
|
require_paths:
|
191
191
|
- lib
|
192
192
|
required_ruby_version: !ruby/object:Gem::Requirement
|
193
193
|
requirements:
|
194
|
-
- - "
|
194
|
+
- - ">="
|
195
195
|
- !ruby/object:Gem::Version
|
196
196
|
version: '2.1'
|
197
197
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -200,8 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
- !ruby/object:Gem::Version
|
201
201
|
version: '0'
|
202
202
|
requirements: []
|
203
|
-
rubygems_version: 3.0.
|
204
|
-
signing_key:
|
203
|
+
rubygems_version: 3.0.3.1
|
204
|
+
signing_key:
|
205
205
|
specification_version: 4
|
206
206
|
summary: Ruby client for EZID API Version 2
|
207
207
|
test_files:
|