dor-services-client 2.3.0 → 2.4.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 +4 -4
- data/lib/dor/services/client/metadata.rb +6 -4
- data/lib/dor/services/client/object.rb +1 -1
- data/lib/dor/services/client/object_version.rb +3 -3
- data/lib/dor/services/client/objects.rb +3 -3
- data/lib/dor/services/client/release_tags.rb +2 -2
- data/lib/dor/services/client/response_error_formatter.rb +34 -0
- data/lib/dor/services/client/sdr.rb +10 -9
- data/lib/dor/services/client/version.rb +1 -1
- data/lib/dor/services/client/workspace.rb +4 -4
- data/lib/dor/services/client.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98ce334358d0f3233121f562d96610339aa762e7758d3805a78fce94af96ae15
|
4
|
+
data.tar.gz: 72ca530a50cb19d8f37c9923942bcc222b4a19367ce760c638e1c9635adafbfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 689c2c25b4409e7a84cd9dfe5ac956027e1c41acfd95abc6643da2f97256b714a89d48699a0a85f683eb01811c5b8f9a3f65e1a6dd9c75417213f77362562397
|
7
|
+
data.tar.gz: d40443664b067ce06f4050695746fc9e6f8099d756b3c9c664699b1474e61253169a31701bd54565c95aa5ead3c4463f8ee10b57ac816dcb913b06696eaf3c5f
|
@@ -11,7 +11,8 @@ module Dor
|
|
11
11
|
@object_identifier = object_identifier
|
12
12
|
end
|
13
13
|
|
14
|
-
# @return [String] The Dublin Core XML representation of the object
|
14
|
+
# @return [String, NilClass] The Dublin Core XML representation of the object or nil if response is 404
|
15
|
+
# @raise [UnexpectedResponse] on an unsuccessful response from the server
|
15
16
|
def dublin_core
|
16
17
|
resp = connection.get do |req|
|
17
18
|
req.url "#{base_path}/dublin_core"
|
@@ -19,10 +20,11 @@ module Dor
|
|
19
20
|
return resp.body if resp.success?
|
20
21
|
return if resp.status == 404
|
21
22
|
|
22
|
-
raise UnexpectedResponse,
|
23
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp, object_identifier: object_identifier)
|
23
24
|
end
|
24
25
|
|
25
|
-
# @return [String] The descriptive metadata XML representation of the object
|
26
|
+
# @return [String, NilClass] The descriptive metadata XML representation of the object or nil if response is 404
|
27
|
+
# @raise [UnexpectedResponse] on an unsuccessful response from the server
|
26
28
|
def descriptive
|
27
29
|
resp = connection.get do |req|
|
28
30
|
req.url "#{base_path}/descriptive"
|
@@ -30,7 +32,7 @@ module Dor
|
|
30
32
|
return resp.body if resp.success?
|
31
33
|
return if resp.status == 404
|
32
34
|
|
33
|
-
raise UnexpectedResponse,
|
35
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp, object_identifier: object_identifier)
|
34
36
|
end
|
35
37
|
|
36
38
|
private
|
@@ -111,7 +111,7 @@ module Dor
|
|
111
111
|
|
112
112
|
def raise_exception_based_on_response!(response)
|
113
113
|
raise (response.status == 404 ? NotFoundResponse : UnexpectedResponse),
|
114
|
-
|
114
|
+
ResponseErrorFormatter.format(response: response)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
@@ -87,14 +87,14 @@ module Dor
|
|
87
87
|
|
88
88
|
def raise_exception_based_on_response!(response)
|
89
89
|
raise (response.status == 404 ? NotFoundResponse : UnexpectedResponse),
|
90
|
-
|
90
|
+
ResponseErrorFormatter.format(response: response)
|
91
91
|
end
|
92
92
|
|
93
93
|
# Make request to server to open a new version
|
94
94
|
# @param params [Hash] optional params (see dor-services-app)
|
95
95
|
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
96
|
-
# @
|
97
|
-
# @
|
96
|
+
# @raise [UnexpectedResponse] on an unsuccessful response from the server
|
97
|
+
# @return [String] the plain text from the server
|
98
98
|
def open_new_version_response(**params)
|
99
99
|
resp = connection.post do |req|
|
100
100
|
req.url open_new_version_path
|
@@ -16,8 +16,8 @@ module Dor
|
|
16
16
|
|
17
17
|
# make the registration request to the server
|
18
18
|
# @param params [Hash] optional params (see dor-services-app)
|
19
|
-
# @
|
20
|
-
# @
|
19
|
+
# @raise [UnexpectedResponse] on an unsuccessful response from the server
|
20
|
+
# @return [String] the raw JSON from the server
|
21
21
|
def register_response(params:)
|
22
22
|
resp = connection.post do |req|
|
23
23
|
req.url "#{api_version}/objects"
|
@@ -28,7 +28,7 @@ module Dor
|
|
28
28
|
end
|
29
29
|
return resp.body if resp.success?
|
30
30
|
|
31
|
-
raise UnexpectedResponse,
|
31
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -16,7 +16,7 @@ module Dor
|
|
16
16
|
# @param what [String]
|
17
17
|
# @param to [String]
|
18
18
|
# @param who [String]
|
19
|
-
# @
|
19
|
+
# @raise [UnexpectedResponse] if the request is unsuccessful.
|
20
20
|
# @return [Boolean] true if successful
|
21
21
|
# rubocop:disable Metrics/MethodLength
|
22
22
|
def create(release:, what:, to:, who:)
|
@@ -31,7 +31,7 @@ module Dor
|
|
31
31
|
req.headers['Content-Type'] = 'application/json'
|
32
32
|
req.body = params.to_json
|
33
33
|
end
|
34
|
-
raise UnexpectedResponse,
|
34
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp) unless resp.success?
|
35
35
|
|
36
36
|
true
|
37
37
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dor
|
4
|
+
module Services
|
5
|
+
class Client
|
6
|
+
# Format HTTP response-related errors
|
7
|
+
class ResponseErrorFormatter
|
8
|
+
DEFAULT_BODY = 'Response from dor-services-app did not contain a body. \
|
9
|
+
Check honeybadger for dor-services-app for backtraces, \
|
10
|
+
and look into adding a `rescue_from` in dor-services-app \
|
11
|
+
to provide more details to the client in the future'
|
12
|
+
|
13
|
+
def self.format(response:, object_identifier: nil)
|
14
|
+
new(response: response, object_identifier: object_identifier).format
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :reason_phrase, :status, :body, :object_identifier
|
18
|
+
|
19
|
+
def initialize(response:, object_identifier: nil)
|
20
|
+
@reason_phrase = response.reason_phrase
|
21
|
+
@status = response.status
|
22
|
+
@body = response.body.present? ? response.body : DEFAULT_BODY
|
23
|
+
@object_identifier = object_identifier
|
24
|
+
end
|
25
|
+
|
26
|
+
def format
|
27
|
+
return "#{reason_phrase}: #{status} (#{body})" if object_identifier.nil?
|
28
|
+
|
29
|
+
"#{reason_phrase}: #{status} (#{body}) for #{object_identifier}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -34,7 +34,7 @@ module Dor
|
|
34
34
|
resp = signature_catalog_response
|
35
35
|
|
36
36
|
return Moab::SignatureCatalog.new(digital_object_id: object_identifier, version_id: 0) if resp.status == 404
|
37
|
-
raise UnexpectedResponse,
|
37
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp, object_identifier: object_identifier) unless resp.success?
|
38
38
|
|
39
39
|
Moab::SignatureCatalog.parse resp.body
|
40
40
|
end
|
@@ -54,7 +54,8 @@ module Dor
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# @param [String] datastream The identifier of the metadata datastream
|
57
|
-
# @return [String]
|
57
|
+
# @return [String, NilClass] datastream content from previous version of the object (from SDR storage), or nil if response status is 404
|
58
|
+
# @raise [UnexpectedResponse] on an unsuccessful, non-404 response from the server
|
58
59
|
def metadata(datastream:)
|
59
60
|
resp = connection.get do |req|
|
60
61
|
req.url "#{base_path}/metadata/#{datastream}.xml"
|
@@ -62,7 +63,7 @@ module Dor
|
|
62
63
|
return resp.body if resp.success?
|
63
64
|
return if resp.status == 404
|
64
65
|
|
65
|
-
raise UnexpectedResponse,
|
66
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp, object_identifier: object_identifier)
|
66
67
|
end
|
67
68
|
|
68
69
|
private
|
@@ -76,15 +77,15 @@ module Dor
|
|
76
77
|
end
|
77
78
|
|
78
79
|
# make the request to the server for the currentVersion xml
|
79
|
-
# @
|
80
|
-
# @
|
80
|
+
# @raise [UnexpectedResponse] on an unsuccessful response from the server
|
81
|
+
# @return [String] the raw xml from the server
|
81
82
|
def current_version_response
|
82
83
|
resp = connection.get do |req|
|
83
84
|
req.url current_version_path
|
84
85
|
end
|
85
86
|
return resp.body if resp.success?
|
86
87
|
|
87
|
-
raise UnexpectedResponse,
|
88
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp, object_identifier: object_identifier)
|
88
89
|
end
|
89
90
|
|
90
91
|
def current_version_path
|
@@ -92,15 +93,15 @@ module Dor
|
|
92
93
|
end
|
93
94
|
|
94
95
|
# make the request to the server for the content diff
|
95
|
-
# @
|
96
|
-
# @
|
96
|
+
# @raise [UnexpectedResponse] on an unsuccessful response from the server
|
97
|
+
# @return [String] the raw xml from the server
|
97
98
|
def content_diff_response(current_content:, subset:, version:)
|
98
99
|
resp = connection.post do |req|
|
99
100
|
req.url content_diff_path(subset: subset, version: version)
|
100
101
|
req.headers['Content-Type'] = 'application/xml'
|
101
102
|
req.body = current_content
|
102
103
|
end
|
103
|
-
raise UnexpectedResponse,
|
104
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp, object_identifier: object_identifier) unless resp.success?
|
104
105
|
|
105
106
|
resp.body
|
106
107
|
end
|
@@ -13,24 +13,24 @@ module Dor
|
|
13
13
|
|
14
14
|
# Initializes a new workspace
|
15
15
|
# @param source [String] the path to the object
|
16
|
-
# @
|
16
|
+
# @raise [UnexpectedResponse] if the request is unsuccessful.
|
17
17
|
# @return nil
|
18
18
|
def create(source:)
|
19
19
|
resp = connection.post do |req|
|
20
20
|
req.url workspace_path
|
21
21
|
req.params['source'] = source
|
22
22
|
end
|
23
|
-
raise UnexpectedResponse,
|
23
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp) unless resp.success?
|
24
24
|
end
|
25
25
|
|
26
26
|
# Cleans up a workspace
|
27
|
-
# @
|
27
|
+
# @raise [UnexpectedResponse] if the request is unsuccessful.
|
28
28
|
# @return nil
|
29
29
|
def cleanup
|
30
30
|
resp = connection.delete do |req|
|
31
31
|
req.url workspace_path
|
32
32
|
end
|
33
|
-
raise UnexpectedResponse,
|
33
|
+
raise UnexpectedResponse, ResponseErrorFormatter.format(response: resp) unless resp.success?
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
data/lib/dor/services/client.rb
CHANGED
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: 2.
|
4
|
+
version: 2.4.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-08-
|
12
|
+
date: 2019-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/dor/services/client/object_version.rb
|
186
186
|
- lib/dor/services/client/objects.rb
|
187
187
|
- lib/dor/services/client/release_tags.rb
|
188
|
+
- lib/dor/services/client/response_error_formatter.rb
|
188
189
|
- lib/dor/services/client/sdr.rb
|
189
190
|
- lib/dor/services/client/version.rb
|
190
191
|
- lib/dor/services/client/versioned_service.rb
|
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
209
|
version: '0'
|
209
210
|
requirements: []
|
210
211
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.7.
|
212
|
+
rubygems_version: 2.7.8
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
215
|
summary: A client for dor-services-app
|