dor-services-client 2.6.2 → 3.0.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 +8 -6
- data/dor-services-client.gemspec +1 -1
- data/lib/dor/services/client.rb +20 -15
- data/lib/dor/services/client/background_job_results.rb +36 -0
- data/lib/dor/services/client/object.rb +0 -13
- data/lib/dor/services/client/version.rb +1 -1
- data/lib/dor/services/client/virtual_objects.rb +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bed8dcd19dcbcd18cb303450debe16dc2f32060e66acc3506a547870789bae5e
|
4
|
+
data.tar.gz: a7c4880010e32aceedd6a3fdfd5e81a8501e50f0e01cdd1d79ef1b2d5f6695a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414ba947b6c25d3219f53538cea66f6f16d4c742a413dfea18800145eb083c72dcd6d45db4762ee7cf17b1cd1d1f68d125c118f7af138526d2ed9d58546e39ac
|
7
|
+
data.tar.gz: 5b6784ff405e9b96e29c9a2e74c4ec6cbc16ccb585dd9793d542bf340e60a792d163e6c076b9c9a18cb92b070c63c82661dd1d3097b366fb460a701a07452433
|
data/README.md
CHANGED
@@ -40,12 +40,11 @@ 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
|
44
|
-
token_header: Settings.dor_services.token_header)
|
43
|
+
token: Settings.dor_services.token)
|
45
44
|
end
|
46
45
|
```
|
47
46
|
|
48
|
-
Note that the client may **not** be used without first having been configured, and the `url` keyword is **required**. The `token`
|
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).
|
49
48
|
|
50
49
|
## API Coverage
|
51
50
|
|
@@ -64,6 +63,12 @@ virtual_objects_client = Dor::Services::Client.virtual_objects
|
|
64
63
|
# Create a batch of virtual objects
|
65
64
|
virtual_objects_client.create(virtual_objects: [{ parent_id: '', child_ids: [''] }])
|
66
65
|
|
66
|
+
# For getting background job results
|
67
|
+
background_jobs_client = Dor::Services::Client.background_job_results
|
68
|
+
|
69
|
+
# Show results of background job
|
70
|
+
background_jobs_client.show(job_id: 123)
|
71
|
+
|
67
72
|
# For performing operations on a known, registered object
|
68
73
|
object_client = Dor::Services::Client.object(object_identifier)
|
69
74
|
|
@@ -76,9 +81,6 @@ object_client.update_marc_record
|
|
76
81
|
# Copy metadata from Symphony into descMetadata
|
77
82
|
object_client.refresh_metadata
|
78
83
|
|
79
|
-
# Add constituents to an object (virtual-merge)
|
80
|
-
object_client.add_constituents(child_druids:)
|
81
|
-
|
82
84
|
# Send a notification to goobi
|
83
85
|
object_client.notify_goobi
|
84
86
|
|
data/dor-services-client.gemspec
CHANGED
@@ -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.
|
26
|
+
spec.add_dependency 'cocina-models', '~> 0.4.0'
|
27
27
|
spec.add_dependency 'faraday', '~> 0.15'
|
28
28
|
spec.add_dependency 'moab-versioning', '~> 4.0'
|
29
29
|
spec.add_dependency 'nokogiri', '~> 1.8'
|
data/lib/dor/services/client.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
require 'active_support/core_ext/hash/indifferent_access'
|
4
4
|
require 'active_support/core_ext/module/delegation'
|
5
5
|
require 'active_support/core_ext/object/blank'
|
6
|
+
require 'cocina/models'
|
6
7
|
require 'faraday'
|
7
8
|
require 'singleton'
|
8
9
|
require 'zeitwerk'
|
9
|
-
require 'cocina/models'
|
10
10
|
|
11
11
|
class DorServicesClientInflector < Zeitwerk::Inflector
|
12
12
|
def camelize(basename, _abspath)
|
@@ -29,6 +29,12 @@ loader.setup
|
|
29
29
|
module Dor
|
30
30
|
module Services
|
31
31
|
class Client
|
32
|
+
include Singleton
|
33
|
+
|
34
|
+
DEFAULT_VERSION = 'v1'
|
35
|
+
TOKEN_HEADER = 'Authorization'
|
36
|
+
|
37
|
+
# Base class for Dor::Services::Client exceptions
|
32
38
|
class Error < StandardError; end
|
33
39
|
|
34
40
|
# Error that is raised when the remote server returns a 404 Not Found
|
@@ -41,12 +47,9 @@ module Dor
|
|
41
47
|
# Error that is raised when the remote server returns some unparsable response
|
42
48
|
class MalformedResponse < Error; end
|
43
49
|
|
50
|
+
# Error that wraps Faraday connection exceptions
|
44
51
|
class ConnectionFailed < Error; end
|
45
52
|
|
46
|
-
DEFAULT_VERSION = 'v1'
|
47
|
-
|
48
|
-
include Singleton
|
49
|
-
|
50
53
|
# @param object_identifier [String] the pid for the object
|
51
54
|
# @raise [ArgumentError] when `object_identifier` is `nil`
|
52
55
|
# @return [Dor::Services::Client::Object] an instance of the `Client::Object` class
|
@@ -71,15 +74,17 @@ module Dor
|
|
71
74
|
@virtual_objects ||= VirtualObjects.new(connection: connection, version: DEFAULT_VERSION)
|
72
75
|
end
|
73
76
|
|
77
|
+
# @return [Dor::Services::Client::BackgroundJobResults] an instance of the `Client::BackgroundJobResults` class
|
78
|
+
def background_job_results
|
79
|
+
@background_job_results ||= BackgroundJobResults.new(connection: connection, version: DEFAULT_VERSION)
|
80
|
+
end
|
81
|
+
|
74
82
|
class << self
|
75
|
-
# @param [String] url
|
76
|
-
# @param [String] token a bearer token for HTTP
|
77
|
-
|
78
|
-
# basic auth, or the headers will collide
|
79
|
-
def configure(url:, token: nil, token_header: 'Authorization')
|
83
|
+
# @param [String] url the base url of the endpoint the client should connect to (required)
|
84
|
+
# @param [String] token a bearer token for HTTP authentication (required)
|
85
|
+
def configure(url:, token:)
|
80
86
|
instance.url = url
|
81
87
|
instance.token = token
|
82
|
-
instance.token_header = token_header
|
83
88
|
|
84
89
|
# Force connection to be re-established when `.configure` is called
|
85
90
|
instance.connection = nil
|
@@ -87,14 +92,14 @@ module Dor
|
|
87
92
|
self
|
88
93
|
end
|
89
94
|
|
90
|
-
delegate :objects, :object, :virtual_objects, to: :instance
|
95
|
+
delegate :objects, :object, :virtual_objects, :background_job_results, to: :instance
|
91
96
|
end
|
92
97
|
|
93
|
-
attr_writer :url, :token, :
|
98
|
+
attr_writer :url, :token, :connection
|
94
99
|
|
95
100
|
private
|
96
101
|
|
97
|
-
attr_reader :token
|
102
|
+
attr_reader :token
|
98
103
|
|
99
104
|
def url
|
100
105
|
@url || raise(Error, 'url has not yet been configured')
|
@@ -110,7 +115,7 @@ module Dor
|
|
110
115
|
# causes the adapter not to be set. Thus, everything breaks.
|
111
116
|
builder.adapter Faraday.default_adapter
|
112
117
|
builder.headers[:user_agent] = user_agent
|
113
|
-
builder.headers[
|
118
|
+
builder.headers[TOKEN_HEADER] = "Bearer #{token}"
|
114
119
|
end
|
115
120
|
end
|
116
121
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Dor
|
6
|
+
module Services
|
7
|
+
class Client
|
8
|
+
# API calls around background job results from dor-services-app
|
9
|
+
class BackgroundJobResults < VersionedService
|
10
|
+
# Get status/result of a background job
|
11
|
+
# @param job_id [String] required string representing a job identifier
|
12
|
+
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
13
|
+
# @raise [UnexpectedResponse] on an unsuccessful response from the server
|
14
|
+
# @return [String] result of background job
|
15
|
+
def show(job_id:)
|
16
|
+
resp = connection.get do |req|
|
17
|
+
req.url "#{api_version}/background_job_results/#{job_id}"
|
18
|
+
req.headers['Accept'] = 'application/json'
|
19
|
+
end
|
20
|
+
# We expect this endpoint to semi-regularly return 422 responses, so do
|
21
|
+
# not bother raising the exception
|
22
|
+
return JSON.parse(resp.body).with_indifferent_access if resp.success? || resp.status == 422
|
23
|
+
|
24
|
+
raise_exception_based_on_response!(resp)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def raise_exception_based_on_response!(response)
|
30
|
+
raise (response.status == 404 ? NotFoundResponse : UnexpectedResponse),
|
31
|
+
ResponseErrorFormatter.format(response: response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -103,19 +103,6 @@ module Dor
|
|
103
103
|
raise_exception_based_on_response!(resp)
|
104
104
|
end
|
105
105
|
|
106
|
-
# TODO: Remove once Argo is using `VirtualObjects#create` instead.
|
107
|
-
# Does a virtual-merge of the children into the parent
|
108
|
-
# @param [Array<String>] child_druids the identifier of the children
|
109
|
-
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
110
|
-
# @raise [UnexpectedResponse] when the response is not successful.
|
111
|
-
# @return [boolean] true on success
|
112
|
-
def add_constituents(child_druids:)
|
113
|
-
resp = connection.put object_path, constituent_ids: child_druids
|
114
|
-
return true if resp.success?
|
115
|
-
|
116
|
-
raise_exception_based_on_response!(resp)
|
117
|
-
end
|
118
|
-
|
119
106
|
# Notify the external Goobi system for a new object that was registered in DOR
|
120
107
|
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
121
108
|
# @raise [UnexpectedResponse] when the response is not successful.
|
@@ -9,7 +9,7 @@ module Dor
|
|
9
9
|
# @param virtual_objects [Array] required array of virtual object params (see dor-services-app)
|
10
10
|
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
11
11
|
# @raise [UnexpectedResponse] on an unsuccessful response from the server
|
12
|
-
# @return [
|
12
|
+
# @return [String] URL from Location response header if no errors
|
13
13
|
def create(virtual_objects:)
|
14
14
|
resp = connection.post do |req|
|
15
15
|
req.url "#{api_version}/virtual_objects"
|
@@ -17,7 +17,7 @@ module Dor
|
|
17
17
|
req.headers['Accept'] = 'application/json'
|
18
18
|
req.body = { virtual_objects: virtual_objects }.to_json
|
19
19
|
end
|
20
|
-
return if resp.success?
|
20
|
+
return resp.headers['Location'] if resp.success?
|
21
21
|
|
22
22
|
raise_exception_based_on_response!(resp)
|
23
23
|
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:
|
4
|
+
version: 3.0.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: 2019-09-
|
12
|
+
date: 2019-09-20 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.
|
40
|
+
version: 0.4.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.
|
47
|
+
version: 0.4.0
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: faraday
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,6 +206,7 @@ files:
|
|
206
206
|
- bin/setup
|
207
207
|
- dor-services-client.gemspec
|
208
208
|
- lib/dor/services/client.rb
|
209
|
+
- lib/dor/services/client/background_job_results.rb
|
209
210
|
- lib/dor/services/client/collections.rb
|
210
211
|
- lib/dor/services/client/embargo.rb
|
211
212
|
- lib/dor/services/client/error_faraday_middleware.rb
|