dor-services-client 1.8.0 → 1.9.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 -4
- data/dor-services-client.gemspec +1 -0
- data/lib/dor/services/client/object.rb +13 -63
- data/lib/dor/services/client/object_version.rb +119 -0
- data/lib/dor/services/client/version.rb +1 -1
- data/lib/dor/services/client.rb +21 -8
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86fea009a88a5fd765b3777f475a259d821988c26dfd9b5c25e9d041768f9280
|
4
|
+
data.tar.gz: f58cd9c866860b514e098966daf09b0606c43b4b980f2a169a983a434d0b65c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bde6be34744ecfc81a254e1e386130a7e1b6ba999cfed8189ad97d7652f407230b5e08299914c2118a59e10e42662099cb59cac28f48409b1352ddc647a4484
|
7
|
+
data.tar.gz: 803356f6b3acf1564014f305a1fcd696d2a9e6cb8763a4a6f2c5d4b9e174bf30a5405e32bab13ec969530501f1f124e8448851f46f9553924b02ba0a04c7630f
|
data/README.md
CHANGED
@@ -62,11 +62,14 @@ object_client.publish
|
|
62
62
|
# Copy metadata from Symphony into descMetadata
|
63
63
|
object_client.refresh_metadata
|
64
64
|
object_client.notify_goobi
|
65
|
-
object_client.
|
66
|
-
object_client.
|
67
|
-
object_client.
|
68
|
-
|
65
|
+
object_client.version.current
|
66
|
+
object_client.version.openeable?(**params)
|
67
|
+
object_client.version.open(**params)
|
68
|
+
object_client.version.close(**params)
|
69
|
+
# Get the Dublin Core XML representation
|
69
70
|
object_client.metadata.dublin_core
|
71
|
+
# Get the public descriptive XML representation
|
72
|
+
object_client.metadata.descriptive
|
70
73
|
object_client.files.retrieve(filename: filename_string)
|
71
74
|
object_client.files.preserved_content(filename: filename_string, version: version_string)
|
72
75
|
object_client.files.list
|
data/dor-services-client.gemspec
CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
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'
|
30
|
+
spec.add_dependency 'zeitwerk', '~> 2.1'
|
30
31
|
|
31
32
|
spec.add_development_dependency 'bundler'
|
32
33
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -1,17 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'dor/services/client/release_tags'
|
5
|
-
require 'dor/services/client/sdr'
|
6
|
-
require 'dor/services/client/workflow'
|
7
|
-
require 'dor/services/client/workspace'
|
8
|
-
require 'dor/services/client/metadata'
|
3
|
+
require 'deprecation'
|
9
4
|
|
10
5
|
module Dor
|
11
6
|
module Services
|
12
7
|
class Client
|
13
8
|
# API calls that are about a repository object
|
14
9
|
class Object < VersionedService
|
10
|
+
extend Deprecation
|
11
|
+
|
15
12
|
attr_reader :object_identifier
|
16
13
|
|
17
14
|
# @param object_identifier [String] the pid for the object
|
@@ -46,6 +43,10 @@ module Dor
|
|
46
43
|
@release_tags ||= ReleaseTags.new(connection: connection, version: api_version, object_identifier: object_identifier)
|
47
44
|
end
|
48
45
|
|
46
|
+
def version
|
47
|
+
@version ||= ObjectVersion.new(connection: connection, version: api_version, object_identifier: object_identifier)
|
48
|
+
end
|
49
|
+
|
49
50
|
# Publish a new object
|
50
51
|
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
51
52
|
# @raise [UnexpectedResponse] when the response is not successful.
|
@@ -98,47 +99,20 @@ module Dor
|
|
98
99
|
raise_exception_based_on_response!(resp)
|
99
100
|
end
|
100
101
|
|
101
|
-
# Get the current_version for a DOR object. This comes from Dor::VersionMetadataDS
|
102
|
-
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
103
|
-
# @raise [UnexpectedResponse] when the response is not successful.
|
104
|
-
# @return [String] the version identifier
|
105
102
|
def current_version
|
106
|
-
|
107
|
-
req.url "#{object_path}/versions/current"
|
108
|
-
end
|
109
|
-
return resp.body if resp.success?
|
110
|
-
|
111
|
-
raise_exception_based_on_response!(resp)
|
103
|
+
version.current
|
112
104
|
end
|
105
|
+
deprecation_deprecate current_version: 'use version.current instead'
|
113
106
|
|
114
|
-
# Open new version for an object
|
115
|
-
# @param params [Hash] optional params (see dor-services-app)
|
116
|
-
# @raise [MalformedResponse] when the response is not parseable.
|
117
|
-
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
118
|
-
# @raise [UnexpectedResponse] when the response is not successful.
|
119
|
-
# @return [String] the current version
|
120
107
|
def open_new_version(**params)
|
121
|
-
version
|
122
|
-
raise MalformedResponse, "Version of #{object_identifier} is empty" if version.empty?
|
123
|
-
|
124
|
-
version
|
108
|
+
version.open(**params)
|
125
109
|
end
|
110
|
+
deprecation_deprecate open_new_version: 'use version.open instead'
|
126
111
|
|
127
|
-
# Close current version for an object
|
128
|
-
# @param params [Hash] optional params (see dor-services-app)
|
129
|
-
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
130
|
-
# @raise [UnexpectedResponse] when the response is not successful.
|
131
|
-
# @return [String] a message confirming successful closing
|
132
112
|
def close_version(**params)
|
133
|
-
|
134
|
-
req.url close_version_path
|
135
|
-
req.headers['Content-Type'] = 'application/json'
|
136
|
-
req.body = params.to_json if params.any?
|
137
|
-
end
|
138
|
-
return resp.body if resp.success?
|
139
|
-
|
140
|
-
raise_exception_based_on_response!(resp)
|
113
|
+
version.close(**params)
|
141
114
|
end
|
115
|
+
deprecation_deprecate close_version: 'use version.close instead'
|
142
116
|
|
143
117
|
private
|
144
118
|
|
@@ -150,30 +124,6 @@ module Dor
|
|
150
124
|
raise (response.status == 404 ? NotFoundResponse : UnexpectedResponse),
|
151
125
|
"#{response.reason_phrase}: #{response.status} (#{response.body})"
|
152
126
|
end
|
153
|
-
|
154
|
-
# Make request to server to open a new version
|
155
|
-
# @param params [Hash] optional params (see dor-services-app)
|
156
|
-
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
157
|
-
# @raises [UnexpectedResponse] on an unsuccessful response from the server
|
158
|
-
# @returns [String] the plain text from the server
|
159
|
-
def open_new_version_response(**params)
|
160
|
-
resp = connection.post do |req|
|
161
|
-
req.url open_new_version_path
|
162
|
-
req.headers['Content-Type'] = 'application/json'
|
163
|
-
req.body = params.to_json if params.any?
|
164
|
-
end
|
165
|
-
return resp.body if resp.success?
|
166
|
-
|
167
|
-
raise_exception_based_on_response!(resp)
|
168
|
-
end
|
169
|
-
|
170
|
-
def open_new_version_path
|
171
|
-
"#{object_path}/versions"
|
172
|
-
end
|
173
|
-
|
174
|
-
def close_version_path
|
175
|
-
"#{object_path}/versions/current/close"
|
176
|
-
end
|
177
127
|
end
|
178
128
|
end
|
179
129
|
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dor
|
4
|
+
module Services
|
5
|
+
class Client
|
6
|
+
# API calls that are about versions
|
7
|
+
class ObjectVersion < VersionedService
|
8
|
+
# @param object_identifier [String] the pid for the object
|
9
|
+
def initialize(connection:, version:, object_identifier:)
|
10
|
+
super(connection: connection, version: version)
|
11
|
+
@object_identifier = object_identifier
|
12
|
+
end
|
13
|
+
|
14
|
+
# Get the current version for a DOR object. This comes from Dor::VersionMetadataDS
|
15
|
+
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
16
|
+
# @raise [UnexpectedResponse] when the response is not successful.
|
17
|
+
# @return [String] the version identifier
|
18
|
+
def current
|
19
|
+
resp = connection.get do |req|
|
20
|
+
req.url "#{object_path}/versions/current"
|
21
|
+
end
|
22
|
+
return resp.body if resp.success?
|
23
|
+
|
24
|
+
raise_exception_based_on_response!(resp)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Determines if a new version can be opened for a DOR object.
|
28
|
+
# @param params [Hash] optional params (see dor-services-app)
|
29
|
+
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
30
|
+
# @raise [UnexpectedResponse] when the response is not successful.
|
31
|
+
# @return [Boolean] true if a new version can be opened
|
32
|
+
# rubocop:disable Metrics/MethodLength
|
33
|
+
def openeable?(**params)
|
34
|
+
resp = connection.get do |req|
|
35
|
+
req.url "#{object_path}/versions/openeable"
|
36
|
+
req.params = params
|
37
|
+
end
|
38
|
+
|
39
|
+
raise_exception_based_on_response!(resp) unless resp.success?
|
40
|
+
|
41
|
+
if resp.body == 'true'
|
42
|
+
true
|
43
|
+
elsif resp.body == 'false'
|
44
|
+
false
|
45
|
+
else
|
46
|
+
raise MalformedResponse, "Expected true or false, not #{resp.body}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
# rubocop:enable Metrics/MethodLength
|
50
|
+
|
51
|
+
# Open new version for an object
|
52
|
+
# @param params [Hash] optional params (see dor-services-app)
|
53
|
+
# @raise [MalformedResponse] when the response is not parseable.
|
54
|
+
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
55
|
+
# @raise [UnexpectedResponse] when the response is not successful.
|
56
|
+
# @return [String] the current version
|
57
|
+
def open(**params)
|
58
|
+
version = open_new_version_response(**params)
|
59
|
+
raise MalformedResponse, "Version of #{object_identifier} is empty" if version.empty?
|
60
|
+
|
61
|
+
version
|
62
|
+
end
|
63
|
+
|
64
|
+
# Close current version for an object
|
65
|
+
# @param params [Hash] optional params (see dor-services-app)
|
66
|
+
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
67
|
+
# @raise [UnexpectedResponse] when the response is not successful.
|
68
|
+
# @return [String] a message confirming successful closing
|
69
|
+
def close(**params)
|
70
|
+
resp = connection.post do |req|
|
71
|
+
req.url close_version_path
|
72
|
+
req.headers['Content-Type'] = 'application/json'
|
73
|
+
req.body = params.to_json if params.any?
|
74
|
+
end
|
75
|
+
return resp.body if resp.success?
|
76
|
+
|
77
|
+
raise_exception_based_on_response!(resp)
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
attr_reader :object_identifier
|
83
|
+
|
84
|
+
def object_path
|
85
|
+
"#{api_version}/objects/#{object_identifier}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def raise_exception_based_on_response!(response)
|
89
|
+
raise (response.status == 404 ? NotFoundResponse : UnexpectedResponse),
|
90
|
+
"#{response.reason_phrase}: #{response.status} (#{response.body})"
|
91
|
+
end
|
92
|
+
|
93
|
+
# Make request to server to open a new version
|
94
|
+
# @param params [Hash] optional params (see dor-services-app)
|
95
|
+
# @raise [NotFoundResponse] when the response is a 404 (object not found)
|
96
|
+
# @raises [UnexpectedResponse] on an unsuccessful response from the server
|
97
|
+
# @returns [String] the plain text from the server
|
98
|
+
def open_new_version_response(**params)
|
99
|
+
resp = connection.post do |req|
|
100
|
+
req.url open_new_version_path
|
101
|
+
req.headers['Content-Type'] = 'application/json'
|
102
|
+
req.body = params.to_json if params.any?
|
103
|
+
end
|
104
|
+
return resp.body if resp.success?
|
105
|
+
|
106
|
+
raise_exception_based_on_response!(resp)
|
107
|
+
end
|
108
|
+
|
109
|
+
def open_new_version_path
|
110
|
+
"#{object_path}/versions"
|
111
|
+
end
|
112
|
+
|
113
|
+
def close_version_path
|
114
|
+
"#{object_path}/versions/current/close"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/lib/dor/services/client.rb
CHANGED
@@ -1,15 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'dor/services/client/version'
|
4
|
-
require 'singleton'
|
5
|
-
require 'faraday'
|
6
3
|
require 'active_support/core_ext/hash/indifferent_access'
|
7
4
|
require 'active_support/core_ext/module/delegation'
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
|
12
|
-
|
5
|
+
require 'faraday'
|
6
|
+
require 'singleton'
|
7
|
+
require 'zeitwerk'
|
8
|
+
|
9
|
+
class DorServicesClientInflector < Zeitwerk::Inflector
|
10
|
+
def camelize(basename, _abspath)
|
11
|
+
case basename
|
12
|
+
when 'sdr'
|
13
|
+
'SDR'
|
14
|
+
else
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
loader = Zeitwerk::Loader.new
|
21
|
+
loader.inflector = DorServicesClientInflector.new
|
22
|
+
loader.push_dir('lib')
|
23
|
+
loader.setup
|
13
24
|
|
14
25
|
module Dor
|
15
26
|
module Services
|
@@ -88,6 +99,7 @@ module Dor
|
|
88
99
|
@url || raise(Error, 'url has not yet been configured')
|
89
100
|
end
|
90
101
|
|
102
|
+
# rubocop:disable Metrics/AbcSize
|
91
103
|
def connection
|
92
104
|
@connection ||= Faraday.new(url) do |conn|
|
93
105
|
conn.use ErrorFaradayMiddleware
|
@@ -101,6 +113,7 @@ module Dor
|
|
101
113
|
conn.headers[token_header] = "Bearer #{token}" if token
|
102
114
|
end
|
103
115
|
end
|
116
|
+
# rubocop:enable Metrics/AbcSize
|
104
117
|
|
105
118
|
def user_agent
|
106
119
|
"dor-services-client #{Dor::Services::Client::VERSION}"
|
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: 1.
|
4
|
+
version: 1.9.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-05-
|
12
|
+
date: 2019-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -87,6 +87,20 @@ dependencies:
|
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '1.8'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: zeitwerk
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.1'
|
97
|
+
type: :runtime
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.1'
|
90
104
|
- !ruby/object:Gem::Dependency
|
91
105
|
name: bundler
|
92
106
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,6 +196,7 @@ files:
|
|
182
196
|
- lib/dor/services/client/files.rb
|
183
197
|
- lib/dor/services/client/metadata.rb
|
184
198
|
- lib/dor/services/client/object.rb
|
199
|
+
- lib/dor/services/client/object_version.rb
|
185
200
|
- lib/dor/services/client/objects.rb
|
186
201
|
- lib/dor/services/client/release_tags.rb
|
187
202
|
- lib/dor/services/client/sdr.rb
|