ezid-client 1.9.3 → 1.10.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
  SHA256:
3
- metadata.gz: 4923cc603a7be145dec5b0cef9680ebefb24914a1edbc7b4cce1e49bbb20a6cc
4
- data.tar.gz: 29e09adc2fa5b7444600ad0174267b673c98b67d32dbae9d4e88eb3fe140cb54
3
+ metadata.gz: '0238bbb49530de30773410dba606a4db95117b344d452bbab62e986e06a29df8'
4
+ data.tar.gz: 8d846a6821058d66a956635d8b1863a345f086b1586716aa0fb38e71518ca90f
5
5
  SHA512:
6
- metadata.gz: df3e067372950e605a4e42c85a808b9f4d4d925884fb177c1ef13fed584bf7579b9e54ad1053160e1959f549f5271a297d6dec8bba36b398b6ca0fa58ff53b93
7
- data.tar.gz: 8727ff8bb484708a3c2f8552e1208d8f664ce559718b04d0dac65226e95387eb0343fe4bc50483919851827d221c9c3e94ca6fa470f4e1bf8c7bc3b09e8342dc
6
+ metadata.gz: 8d37ad9714ab1403568642178f805b6b73e3c0c93df42e3202a262e35db3ad32522caa9aa4b53cc69924dc5732a798b606634b1d6a6c8cf8f25b40d28813fb9c
7
+ data.tar.gz: 536501b2cf78dbd6c276a8c010257df7ef1ad442786f4297d32c92191de17f92f165ca6ad9ae95fef606147f6791453ffbf3aa6fb584eb0e33bb647ab486339d
data/.dockerignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ .config
4
+ .dockerignore
5
+ .git
6
+ .github
7
+ .gitignore
8
+ Dockerfile
9
+ Gemfile.lock
@@ -19,7 +19,7 @@ jobs:
19
19
  runs-on: ubuntu-latest
20
20
  strategy:
21
21
  matrix:
22
- ruby-version: ['2.6', '2.7', '3.0']
22
+ ruby-version: ['3.0', '3.1', '3.2', '3.3']
23
23
 
24
24
  steps:
25
25
  - uses: actions/checkout@v2
data/Dockerfile ADDED
@@ -0,0 +1,13 @@
1
+ ARG ruby_version="latest"
2
+
3
+ FROM ruby:${ruby_version}
4
+
5
+ SHELL ["/bin/bash", "-c"]
6
+
7
+ WORKDIR /app
8
+
9
+ COPY VERSION Gemfile ezid-client.gemspec ./
10
+
11
+ RUN gem install bundler -v '~>2.0' && bundle install
12
+
13
+ COPY . .
data/README.md CHANGED
@@ -128,20 +128,20 @@ See http://ezid.cdlib.org/doc/apidoc.html#parameters. Repeated values should be
128
128
  ```
129
129
  >> batch_download = Ezid::BatchDownload.new(:csv)
130
130
  => #<Ezid::BatchDownload format=:csv>
131
-
131
+
132
132
  >> batch_download.column = ["_id", "_target"]
133
133
  => ["_id", "_target"]
134
-
134
+
135
135
  >> batch_download.createdAfter = Date.today.to_time
136
136
  => 2016-02-24 00:00:00 -0500
137
-
137
+
138
138
  >> batch_download
139
139
  => #<Ezid::BatchDownload column=["_id", "_target"] createdAfter=1456290000 format=:csv>
140
-
140
+
141
141
  >> batch_download.url
142
142
  I, [2016-02-24T18:03:40.828005 #1084] INFO -- : EZID BatchDownload -- success: http://ezid.cdlib.org/download/4a63401e17.csv.gz
143
143
  => "http://ezid.cdlib.org/download/4a63401e17.csv.gz"
144
-
144
+
145
145
  >> batch_download.file
146
146
  => /current/working/directory/4a63401e17.csv.gz
147
147
  ```
@@ -155,13 +155,13 @@ I, [2016-02-24T18:03:40.828005 #1084] INFO -- : EZID BatchDownload -- success:
155
155
  ```
156
156
  >> require 'ezid/batch'
157
157
  => true
158
-
158
+
159
159
  >> batch = Ezid::Batch.new(:anvl, "spec/fixtures/anvl_batch.txt")
160
160
  => #<Ezid::Batch:0x007f87a8900308 @format=:anvl, @batch_file="spec/fixtures/anvl_batch.txt">
161
-
161
+
162
162
  >> id = batch.first
163
163
  => #<Ezid::Identifier id=ark:/99999/fk4086hs23>
164
-
164
+
165
165
  >> id.target
166
166
  => "http://example.com"
167
167
 
@@ -318,6 +318,15 @@ See http://ezid.cdlib.org/doc/apidoc.html#testing-the-api.
318
318
 
319
319
  In order to run the integration tests successfully, you must supply the password for the test account "apitest" (contact EZID). To run the test suite without the integration tests, use the `rake ci` task.
320
320
 
321
+ ## Dockerfile
322
+
323
+ A basic Dockerfile is provided based on Docker official Ruby image tags.
324
+
325
+ An example building an image with the latest Ruby and running the unit tests:
326
+
327
+ $ docker build -t ezid-client .
328
+ $ docker run --rm -it ezid-client bundle exec rspec ./spec/unit/
329
+
321
330
  ## Contributing
322
331
 
323
332
  1. Fork it ( https://github.com/[my-github-username]/ezid-client/fork )
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.3
1
+ 1.10.0
data/lib/ezid/error.rb CHANGED
@@ -10,4 +10,6 @@ module Ezid
10
10
  class DeletionError < Error; end
11
11
 
12
12
  class UnexpectedResponseError < Error; end
13
+
14
+ class ServerError < Error; end
13
15
  end
@@ -22,6 +22,10 @@ module Ezid
22
22
  POST = Net::HTTP::Post
23
23
  DELETE = Net::HTTP::Delete
24
24
 
25
+ RETRIABLE_SERVER_ERRORS = %w[500 502 503 504].freeze
26
+
27
+ RETRIES = ENV.fetch('EZID_REQUEST_RETRIES', '2').to_i
28
+
25
29
  class << self
26
30
  attr_accessor :http_method, :path, :response_class
27
31
 
@@ -37,7 +41,7 @@ module Ezid
37
41
  end
38
42
 
39
43
  attr_reader :client
40
- def_delegators :client, :connection, :user, :password, :session
44
+ def_delegators :client, :connection, :user, :password, :session, :logger, :config
41
45
 
42
46
  # @param client [Ezid::Client] the client
43
47
  def initialize(client, *args)
@@ -50,12 +54,24 @@ module Ezid
50
54
  # @return [Ezid::Response] the response
51
55
  def execute
52
56
  retries = 0
57
+
53
58
  begin
54
- response_class.new(get_response_for_request)
55
- rescue Net::HTTPServerException, UnexpectedResponseError => e
56
- if retries < 2
57
- sleep client.config.retry_interval
59
+ http_response = get_response_for_request
60
+
61
+ if RETRIABLE_SERVER_ERRORS.include? http_response.code
62
+ raise ServerError, "#{http_response.code} #{http_response.msg}"
63
+ end
64
+
65
+ response_class.new(http_response)
66
+
67
+ rescue ServerError, UnexpectedResponseError => e
68
+ if retries < RETRIES
69
+ logger.error "EZID error: #{e}"
70
+
58
71
  retries += 1
72
+ logger.info "Retry (#{retries} of #{RETRIES}) of #{short_name} #{path} in #{config.retry_interval} seconds ..."
73
+ sleep config.retry_interval
74
+
59
75
  retry
60
76
  else
61
77
  raise
@@ -85,6 +101,10 @@ module Ezid
85
101
  # @return [String] the query string
86
102
  def query; end
87
103
 
104
+ def short_name
105
+ self.class.short_name
106
+ end
107
+
88
108
  def authentication_required?
89
109
  true
90
110
  end
@@ -15,8 +15,6 @@ module Ezid
15
15
  ERROR = "error".freeze
16
16
 
17
17
  def initialize(http_response)
18
- http_response.value # raises Net::HTTPServerException
19
-
20
18
  super
21
19
 
22
20
  unless status_line =~ /^(#{SUCCESS}|#{ERROR}): /
@@ -179,16 +179,6 @@ EOS
179
179
  allow(GetIdentifierMetadataRequest).to receive(:execute).with(subject, "invalid") { stub_response }
180
180
  end
181
181
 
182
- describe "HTTP error response" do
183
- before do
184
- allow(http_response).to receive(:value).and_raise(Net::HTTPServerException.new('Barf!', double))
185
- end
186
-
187
- it "raises an exception" do
188
- expect { subject.get_identifier_metadata("invalid") }.to raise_error(Net::HTTPServerException)
189
- end
190
- end
191
-
192
182
  describe "EZID API error response" do
193
183
  let(:body) { "error: bad request - no such identifier" }
194
184
 
@@ -220,11 +210,12 @@ EOS
220
210
 
221
211
  describe "retrying on certain errors" do
222
212
  before do
213
+ allow(subject.config).to receive(:retry_interval) { 1 }
223
214
  allow(GetIdentifierMetadataResponse).to receive(:new).and_raise(exception)
224
215
  end
225
216
 
226
- describe "HTTP error" do
227
- let(:exception) { Net::HTTPServerException.new('Barf!', double) }
217
+ describe "retriable server error" do
218
+ let(:exception) { ServerError.new('502 Bad Gateway') }
228
219
 
229
220
  it "retries twice" do
230
221
  begin
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.3
4
+ version: 1.10.0
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: 2022-11-17 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -121,9 +121,11 @@ executables: []
121
121
  extensions: []
122
122
  extra_rdoc_files: []
123
123
  files:
124
+ - ".dockerignore"
124
125
  - ".github/workflows/ruby.yml"
125
126
  - ".gitignore"
126
127
  - ".rspec"
128
+ - Dockerfile
127
129
  - Gemfile
128
130
  - LICENSE.txt
129
131
  - README.md
@@ -185,7 +187,7 @@ homepage: https://github.com/duke-libraries/ezid-client
185
187
  licenses:
186
188
  - BSD-3-Clause
187
189
  metadata: {}
188
- post_install_message:
190
+ post_install_message:
189
191
  rdoc_options: []
190
192
  require_paths:
191
193
  - lib
@@ -200,8 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
202
  - !ruby/object:Gem::Version
201
203
  version: '0'
202
204
  requirements: []
203
- rubygems_version: 3.0.3.1
204
- signing_key:
205
+ rubygems_version: 3.5.6
206
+ signing_key:
205
207
  specification_version: 4
206
208
  summary: Ruby client for EZID API Version 2
207
209
  test_files: