dor-services-client 6.1.0 → 6.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f324272fcd773616044c4ddc11f93664d52efa263f47cdcc21059dd07bee7562
4
- data.tar.gz: 1abbe32573c71a368d69a46ce1a18c6eb587a35a6e2ad7e2dead9670e9c276a5
3
+ metadata.gz: 89c1a897efc199c5f31da3d68f9c3fd2bdc4c09759579a30a339477651081ced
4
+ data.tar.gz: da3a34afb64f21ff964ddffdaeba44d1a8fa45fb15126d4cbb77b3e1f89f3cc5
5
5
  SHA512:
6
- metadata.gz: ece82eaa29c075d3e6b5c66d18e133f200984c7ef0ab5cdb810ed11e729de893fe8be0e5610a67452dd6fbc5cb0264e9aa6983f8d3d342926e04c9ad45a39b33
7
- data.tar.gz: 906962b8dabe3ebb34fab6a41ffa8dd52e5c1e68315587d3763a8897cf3d2fd182929d3cd3b1e9e58de6e988415ddd351071e44ee3bcaf42cafde272e1d35269
6
+ metadata.gz: 1fbd52e84678d731a29392b94b13fd68fba69e57fb70e0f4af906dc1838ef741ec02cd6e0b9adf9d0c4919d8d19b8c815d34c4933b14b9660fe05f79436f1f61
7
+ data.tar.gz: 36f45f7241b8de8900b6e93a2fbe39240e1a0280c2ff9dc78c9be1e14d2e3a41252d43b6799c22dd3e509b4e2a399db17bb359054226680ed89cff5737234852
@@ -1,4 +1,12 @@
1
1
  ## Why was this change made?
2
2
 
3
3
 
4
- ## Was the documentation (README, API, wiki, consul, etc.) updated?
4
+
5
+ ## How was this change tested?
6
+
7
+
8
+
9
+ ## Which documentation and/or configurations were updated?
10
+
11
+
12
+
@@ -32,5 +32,5 @@ Style/Documentation:
32
32
  # Cop supports --auto-correct.
33
33
  # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
34
34
  # URISchemes: http, https
35
- Layout/LineLength:
35
+ Metrics/LineLength:
36
36
  Max: 164
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 that the client may **not** be used without first having been configured, and the `url` keyword is **required**. 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).
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
 
@@ -164,6 +169,9 @@ object_client.workspace.reset
164
169
 
165
170
  # Update embargo
166
171
  object_client.embargo.update(embargo_date: date_string, requesting_user: username_string)
172
+
173
+ # Search for administrative tags:
174
+ Dor::Services::Client.administrative_tags.search(q: 'Project')
167
175
  ```
168
176
 
169
177
  ## Asynchronous results
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ['lib']
24
24
 
25
25
  spec.add_dependency 'activesupport', '>= 4.2', '< 7'
26
- spec.add_dependency 'cocina-models', '~> 0.32.0' # leave pinned to patch level until cocina-models hits 1.0
26
+ spec.add_dependency 'cocina-models', '~> 0.33.0' # leave pinned to patch level until cocina-models hits 1.0
27
27
  spec.add_dependency 'deprecation', '>= 0'
28
28
  spec.add_dependency 'faraday', '>= 0.15', '< 2'
29
29
  spec.add_dependency 'moab-versioning', '~> 4.0'
@@ -36,6 +36,9 @@ module Dor
36
36
  # Error that is raised when the remote server returns a 401 Unauthorized
37
37
  class UnauthorizedResponse < UnexpectedResponse; end
38
38
 
39
+ # Error that is raised when the remote server returns a 409 Conflict
40
+ class ConflictResponse < UnexpectedResponse; end
41
+
39
42
  # Error that is raised when the remote server returns some unparsable response
40
43
  class MalformedResponse < Error; end
41
44
 
@@ -56,6 +59,11 @@ module Dor
56
59
  @object = Object.new(connection: connection, version: DEFAULT_VERSION, object_identifier: object_identifier)
57
60
  end
58
61
 
62
+ # @return [Dor::Services::Client::AdministrativeTagSearch] an instance of the `Client::AdministrativeTagSearch` class
63
+ def administrative_tags
64
+ @administrative_tags ||= AdministrativeTagSearch.new(connection: connection, version: DEFAULT_VERSION)
65
+ end
66
+
59
67
  # @return [Dor::Services::Client::Objects] an instance of the `Client::Objects` class
60
68
  def objects
61
69
  @objects ||= Objects.new(connection: connection, version: DEFAULT_VERSION)
@@ -79,9 +87,11 @@ module Dor
79
87
  class << self
80
88
  # @param [String] url the base url of the endpoint the client should connect to (required)
81
89
  # @param [String] token a bearer token for HTTP authentication (required)
82
- def configure(url:, token:)
90
+ # @param [Boolean] enable_get_retries retries get requests on errors
91
+ def configure(url:, token:, enable_get_retries: false)
83
92
  instance.url = url
84
93
  instance.token = token
94
+ instance.enable_get_retries = enable_get_retries
85
95
 
86
96
  # Force connection to be re-established when `.configure` is called
87
97
  instance.connection = nil
@@ -89,21 +99,26 @@ module Dor
89
99
  self
90
100
  end
91
101
 
92
- delegate :background_job_results, :marcxml, :objects, :object, :virtual_objects, to: :instance
102
+ delegate :background_job_results, :marcxml, :objects, :object,
103
+ :virtual_objects, :administrative_tags, to: :instance
93
104
  end
94
105
 
95
- attr_writer :url, :token, :connection
106
+ attr_writer :url, :token, :connection, :enable_get_retries
96
107
 
97
108
  private
98
109
 
99
- attr_reader :token
110
+ attr_reader :token, :enable_get_retries
100
111
 
101
112
  def url
102
113
  @url || raise(Error, 'url has not yet been configured')
103
114
  end
104
115
 
105
116
  def connection
106
- @connection ||= Faraday.new(url) do |builder|
117
+ @connection ||= ConnectionWrapper.new(connection: build_connection, get_connection: build_connection(with_retries: enable_get_retries))
118
+ end
119
+
120
+ def build_connection(with_retries: false)
121
+ Faraday.new(url) do |builder|
107
122
  builder.use ErrorFaradayMiddleware
108
123
  builder.use Faraday::Request::UrlEncoded
109
124
 
@@ -113,6 +128,7 @@ module Dor
113
128
  builder.adapter Faraday.default_adapter
114
129
  builder.headers[:user_agent] = user_agent
115
130
  builder.headers[TOKEN_HEADER] = "Bearer #{token}"
131
+ builder.request :retry, max: 4, interval: 1, backoff_factor: 2 if with_retries
116
132
  end
117
133
  end
118
134
 
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/json' # required for serializing time as iso8601
4
+
5
+ module Dor
6
+ module Services
7
+ class Client
8
+ # API calls that are about searching AdministrativeTags
9
+ class AdministrativeTagSearch < VersionedService
10
+ # rubocop:disable Naming/UncommunicativeMethodParamName
11
+ def search(q:)
12
+ resp = connection.get do |req|
13
+ req.url "#{api_version}/administrative_tags/search?q=#{q}"
14
+ end
15
+
16
+ # Since argo is using this as a proxy, no need to parse the response.
17
+ return resp.body if resp.success?
18
+
19
+ raise_exception_based_on_response!(resp)
20
+ end
21
+ # rubocop:enable Naming/UncommunicativeMethodParamName
22
+ end
23
+ end
24
+ end
25
+ end
@@ -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
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Services
5
5
  class Client
6
- VERSION = '6.1.0'
6
+ VERSION = '6.5.0'
7
7
  end
8
8
  end
9
9
  end
@@ -19,18 +19,22 @@ module Dor
19
19
 
20
20
  attr_reader :connection, :api_version
21
21
 
22
+ # rubocop:disable Metrics/MethodLength
22
23
  def raise_exception_based_on_response!(response, object_identifier = nil)
23
24
  exception_class = case response.status
24
25
  when 404
25
26
  NotFoundResponse
26
27
  when 401
27
28
  UnauthorizedResponse
29
+ when 409
30
+ ConflictResponse
28
31
  else
29
32
  UnexpectedResponse
30
33
  end
31
34
  raise exception_class,
32
35
  ResponseErrorFormatter.format(response: response, object_identifier: object_identifier)
33
36
  end
37
+ # rubocop:enable Metrics/MethodLength
34
38
  end
35
39
  end
36
40
  end
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.1.0
4
+ version: 6.5.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-04-30 00:00:00.000000000 Z
12
+ date: 2020-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -37,14 +37,14 @@ dependencies:
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.32.0
40
+ version: 0.33.0
41
41
  type: :runtime
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.32.0
47
+ version: 0.33.0
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: deprecation
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -228,10 +228,12 @@ files:
228
228
  - dor-services-client.gemspec
229
229
  - lib/dor/services/client.rb
230
230
  - lib/dor/services/client/accession.rb
231
+ - lib/dor/services/client/administrative_tag_search.rb
231
232
  - lib/dor/services/client/administrative_tags.rb
232
233
  - lib/dor/services/client/async_result.rb
233
234
  - lib/dor/services/client/background_job_results.rb
234
235
  - lib/dor/services/client/collections.rb
236
+ - lib/dor/services/client/connection_wrapper.rb
235
237
  - lib/dor/services/client/embargo.rb
236
238
  - lib/dor/services/client/error_faraday_middleware.rb
237
239
  - lib/dor/services/client/events.rb