dor-services-client 6.1.0 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/lib/dor/services/client/connection_wrapper.rb +22 -0
- data/lib/dor/services/client/version.rb +1 -1
- data/lib/dor/services/client.rb +14 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bfa9e7819d9794826fb95861eb36bcaa9f426280dd96267b2739f4693606c1f
|
4
|
+
data.tar.gz: df0c3d033e30d17ecafed72c66406dc33ae6f8f682434e43feb8a47f9b97358f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4edbf5f3ee992ed4accae4225e16d294c9b5aeb8d9c7507164afd2242933040cbf4067b79388c254dfab6263a224d8d6b85655a07a5cf22f4236f41318d5297a
|
7
|
+
data.tar.gz: d52a6f01e86def397871069447cda06886fd1fc5e94f9af98c651d6d8b7e88e8b170530e89bbf35b89d764aa0ad82a743eb9a1434723db45af920df7a7a4d34e
|
data/README.md
CHANGED
@@ -40,11 +40,16 @@ private
|
|
40
40
|
|
41
41
|
def client
|
42
42
|
@client ||= Dor::Services::Client.configure(url: Settings.dor_services.url,
|
43
|
-
token: Settings.dor_services.token
|
43
|
+
token: Settings.dor_services.token,
|
44
|
+
enable_get_retries: true)
|
44
45
|
end
|
45
46
|
```
|
46
47
|
|
47
|
-
Note
|
48
|
+
Note:
|
49
|
+
* The client may **not** be used without first having been configured
|
50
|
+
* The `url` keyword is **required**.
|
51
|
+
* The `token` argument is optional (though when using the client with staging and production servers, you will always need to supply it in practice). For more about dor-services-app's token-based authentication, see [its README](https://github.com/sul-dlss/dor-services-app#authentication).
|
52
|
+
* The `enable_get_retries` argument is optional. When enabled, it will perform retries of `GET` requests only. This should only be used in situations in which blocking is not an issue, e.g., an asynchronous job.
|
48
53
|
|
49
54
|
## API Coverage
|
50
55
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dor
|
4
|
+
module Services
|
5
|
+
class Client
|
6
|
+
# Wraps connections to allow GET requests to be retriable.
|
7
|
+
class ConnectionWrapper
|
8
|
+
delegate :get, to: :get_connection
|
9
|
+
delegate :post, :delete, :put, :patch, to: :connection
|
10
|
+
|
11
|
+
def initialize(connection:, get_connection:)
|
12
|
+
@connection = connection
|
13
|
+
@get_connection = get_connection
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :connection, :get_connection
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/dor/services/client.rb
CHANGED
@@ -79,9 +79,11 @@ module Dor
|
|
79
79
|
class << self
|
80
80
|
# @param [String] url the base url of the endpoint the client should connect to (required)
|
81
81
|
# @param [String] token a bearer token for HTTP authentication (required)
|
82
|
-
|
82
|
+
# @param [Boolean] enable_get_retries retries get requests on errors
|
83
|
+
def configure(url:, token:, enable_get_retries: false)
|
83
84
|
instance.url = url
|
84
85
|
instance.token = token
|
86
|
+
instance.enable_get_retries = enable_get_retries
|
85
87
|
|
86
88
|
# Force connection to be re-established when `.configure` is called
|
87
89
|
instance.connection = nil
|
@@ -92,18 +94,22 @@ module Dor
|
|
92
94
|
delegate :background_job_results, :marcxml, :objects, :object, :virtual_objects, to: :instance
|
93
95
|
end
|
94
96
|
|
95
|
-
attr_writer :url, :token, :connection
|
97
|
+
attr_writer :url, :token, :connection, :enable_get_retries
|
96
98
|
|
97
99
|
private
|
98
100
|
|
99
|
-
attr_reader :token
|
101
|
+
attr_reader :token, :enable_get_retries
|
100
102
|
|
101
103
|
def url
|
102
104
|
@url || raise(Error, 'url has not yet been configured')
|
103
105
|
end
|
104
106
|
|
105
107
|
def connection
|
106
|
-
@connection ||=
|
108
|
+
@connection ||= ConnectionWrapper.new(connection: build_connection, get_connection: build_connection(with_retries: enable_get_retries))
|
109
|
+
end
|
110
|
+
|
111
|
+
def build_connection(with_retries: false)
|
112
|
+
Faraday.new(url) do |builder|
|
107
113
|
builder.use ErrorFaradayMiddleware
|
108
114
|
builder.use Faraday::Request::UrlEncoded
|
109
115
|
|
@@ -113,6 +119,10 @@ module Dor
|
|
113
119
|
builder.adapter Faraday.default_adapter
|
114
120
|
builder.headers[:user_agent] = user_agent
|
115
121
|
builder.headers[TOKEN_HEADER] = "Bearer #{token}"
|
122
|
+
if with_retries
|
123
|
+
builder.request :retry, max: 4, interval: 1,
|
124
|
+
backoff_factor: 2, exceptions: ['Faraday::Error', 'Timeout::Error']
|
125
|
+
end
|
116
126
|
end
|
117
127
|
end
|
118
128
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dor-services-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -232,6 +232,7 @@ files:
|
|
232
232
|
- lib/dor/services/client/async_result.rb
|
233
233
|
- lib/dor/services/client/background_job_results.rb
|
234
234
|
- lib/dor/services/client/collections.rb
|
235
|
+
- lib/dor/services/client/connection_wrapper.rb
|
235
236
|
- lib/dor/services/client/embargo.rb
|
236
237
|
- lib/dor/services/client/error_faraday_middleware.rb
|
237
238
|
- lib/dor/services/client/events.rb
|