dor-services-client 0.7.0 → 0.8.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 +14 -13
- data/dor-services-client.gemspec +1 -0
- data/lib/dor/services/client.rb +10 -1
- data/lib/dor/services/client/object.rb +63 -0
- data/lib/dor/services/client/objects.rb +10 -38
- data/lib/dor/services/client/sdr.rb +45 -0
- data/lib/dor/services/client/version.rb +1 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe6441b14958a78f3b20690780ee260abaecaf92341ce8775c8735e311b9a1f
|
4
|
+
data.tar.gz: 73d11d588c9ab1274415229f2d051f2dda45c4f3a900a4428d564a7d1fc38dd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee530c3203266a71c5f0e6fc0bf2563f46b03fae774cf29595378dc324e4e8d2ef86116eb72126908639620716e8b15cbe52408c062ed5db284f87867cc090d6
|
7
|
+
data.tar.gz: 3e90b21e6be05de21faf18b68836c7592b9e8bc3575c4f8cb75397945ea1158392561e51ca89ba3950f008e55817c7aee2dc75433e829a6f8d3ad9b325167f8e
|
data/README.md
CHANGED
@@ -25,27 +25,28 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
To configure the client,
|
28
|
+
To configure and use the client, here's an example:
|
29
29
|
|
30
30
|
```ruby
|
31
31
|
require 'dor/services/client'
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
Note that the client may not be used without first having been configured, and the `url` keyword is required. The `username` and `password` arguments are optional. (If you are working in a project where the credentials are embedded in the URL, that ought to work just fine as well.)
|
33
|
+
def do_the_thing
|
34
|
+
# This API endpoint returns JSON
|
35
|
+
response = client.register(params: { druid: 'druid:123' })
|
36
|
+
response[:pid] # => 'druid:123'
|
37
|
+
end
|
39
38
|
|
40
|
-
|
39
|
+
private
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
def client
|
42
|
+
@client ||= Dor::Services::Client.configure(url: Settings.DOR_SERVICES.URL,
|
43
|
+
username: Settings.DOR_SERVICES.USER,
|
44
|
+
password: Settings.DOR_SERVICES.PASS)
|
45
|
+
end
|
47
46
|
```
|
48
47
|
|
48
|
+
Note that the client may **not** be used without first having been configured, and the `url` keyword is **required**. The `username` and `password` arguments are optional. (If you are working in a project where the credentials are embedded in the URL, that ought to work just fine as well.)
|
49
|
+
|
49
50
|
## Development
|
50
51
|
|
51
52
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/dor-services-client.gemspec
CHANGED
data/lib/dor/services/client.rb
CHANGED
@@ -7,8 +7,10 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
7
7
|
require 'active_support/core_ext/module/delegation'
|
8
8
|
require 'dor/services/client/versioned_service'
|
9
9
|
require 'dor/services/client/files'
|
10
|
+
require 'dor/services/client/object'
|
10
11
|
require 'dor/services/client/objects'
|
11
12
|
require 'dor/services/client/release_tags'
|
13
|
+
require 'dor/services/client/sdr'
|
12
14
|
require 'dor/services/client/workflow'
|
13
15
|
require 'dor/services/client/workspace'
|
14
16
|
|
@@ -28,10 +30,18 @@ module Dor
|
|
28
30
|
|
29
31
|
include Singleton
|
30
32
|
|
33
|
+
def object(object)
|
34
|
+
Object.new(connection: connection, version: DEFAULT_VERSION, object: object)
|
35
|
+
end
|
36
|
+
|
31
37
|
def objects
|
32
38
|
@objects ||= Objects.new(connection: connection, version: DEFAULT_VERSION)
|
33
39
|
end
|
34
40
|
|
41
|
+
def sdr
|
42
|
+
@sdr ||= SDR.new(connection: connection, version: DEFAULT_VERSION)
|
43
|
+
end
|
44
|
+
|
35
45
|
def files
|
36
46
|
@files ||= Files.new(connection: connection, version: DEFAULT_VERSION)
|
37
47
|
end
|
@@ -123,7 +133,6 @@ module Dor
|
|
123
133
|
|
124
134
|
# Notify goobi system of a new object
|
125
135
|
delegate :notify_goobi, to: :objects
|
126
|
-
|
127
136
|
end
|
128
137
|
|
129
138
|
# Gets the current version number for the object
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'deprecation'
|
5
|
+
|
6
|
+
module Dor
|
7
|
+
module Services
|
8
|
+
class Client
|
9
|
+
# API calls that are about a repository object
|
10
|
+
class Object < VersionedService
|
11
|
+
# @param object [String] the pid for the object
|
12
|
+
def initialize(connection:, version:, object:)
|
13
|
+
super(connection: connection, version: version)
|
14
|
+
@object = object
|
15
|
+
end
|
16
|
+
|
17
|
+
# Publish a new object
|
18
|
+
# @raise [UnexpectedResponse] when the response is not successful.
|
19
|
+
# @return [boolean] true on success
|
20
|
+
def publish
|
21
|
+
resp = connection.post do |req|
|
22
|
+
req.url "#{api_version}/objects/#{object}/publish"
|
23
|
+
end
|
24
|
+
raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
|
25
|
+
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
# Notify the external Goobi system for a new object that was registered in DOR
|
30
|
+
# @raise [UnexpectedResponse] when the response is not successful.
|
31
|
+
# @return [boolean] true on success
|
32
|
+
def notify_goobi
|
33
|
+
resp = connection.post do |req|
|
34
|
+
req.url "#{object_path}/notify_goobi"
|
35
|
+
end
|
36
|
+
raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
|
37
|
+
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
# Get the current_version for a DOR object. This comes from Dor::VersionMetadataDS
|
42
|
+
# @raise [UnexpectedResponse] when the response is not successful.
|
43
|
+
# @return [String] the version identifier
|
44
|
+
def current_version
|
45
|
+
resp = connection.get do |req|
|
46
|
+
req.url "#{object_path}/versions/current"
|
47
|
+
end
|
48
|
+
raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
|
49
|
+
|
50
|
+
resp.body
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
attr_reader :object
|
56
|
+
|
57
|
+
def object_path
|
58
|
+
"#{api_version}/objects/#{object}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'nokogiri'
|
4
|
+
require 'deprecation'
|
4
5
|
|
5
6
|
module Dor
|
6
7
|
module Services
|
7
8
|
class Client
|
8
|
-
# API calls that are about a repository
|
9
|
+
# API calls that are about a repository objects
|
9
10
|
class Objects < VersionedService
|
11
|
+
extend Deprecation
|
12
|
+
|
10
13
|
# Creates a new object in DOR
|
11
14
|
# @return [HashWithIndifferentAccess] the response, which includes a :pid
|
12
15
|
def register(params:)
|
@@ -19,26 +22,18 @@ module Dor
|
|
19
22
|
# @raise [UnexpectedResponse] when the response is not successful.
|
20
23
|
# @return [boolean] true on success
|
21
24
|
def publish(object:)
|
22
|
-
|
23
|
-
req.url "#{api_version}/objects/#{object}/publish"
|
24
|
-
end
|
25
|
-
raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
|
26
|
-
|
27
|
-
true
|
25
|
+
Object.new(connection: connection, version: api_version, object: object).publish
|
28
26
|
end
|
27
|
+
deprecation_deprecate publish: 'Use Dor::Client.object(obj).publish instead'
|
29
28
|
|
30
29
|
# Notify the external Goobi system for a new object that was registered in DOR
|
31
30
|
# @param object [String] the pid for the object
|
32
31
|
# @raise [UnexpectedResponse] when the response is not successful.
|
33
32
|
# @return [boolean] true on success
|
34
33
|
def notify_goobi(object:)
|
35
|
-
|
36
|
-
req.url "#{api_version}/objects/#{object}/notify_goobi"
|
37
|
-
end
|
38
|
-
raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
|
39
|
-
|
40
|
-
true
|
34
|
+
Object.new(connection: connection, version: api_version, object: object).notify_goobi
|
41
35
|
end
|
36
|
+
deprecation_deprecate notify_goobi: 'Use Dor::Client.object(obj).notify_goobi instead'
|
42
37
|
|
43
38
|
# Gets the current version number for the object
|
44
39
|
# @param object [String] the pid for the object
|
@@ -46,16 +41,9 @@ module Dor
|
|
46
41
|
# @raise [MalformedResponse] when the response is not parseable.
|
47
42
|
# @return [Integer] the current version
|
48
43
|
def current_version(object:)
|
49
|
-
|
50
|
-
begin
|
51
|
-
doc = Nokogiri::XML xml
|
52
|
-
raise if doc.root.name != 'currentVersion'
|
53
|
-
|
54
|
-
return Integer(doc.text)
|
55
|
-
rescue StandardError
|
56
|
-
raise MalformedResponse, "Unable to parse XML from current_version API call: #{xml}"
|
57
|
-
end
|
44
|
+
SDR.new(connection: connection, version: api_version).current_version(object: object)
|
58
45
|
end
|
46
|
+
deprecation_deprecate current_version: 'Use Dor::Client.sdr.current_version instead'
|
59
47
|
|
60
48
|
private
|
61
49
|
|
@@ -74,22 +62,6 @@ module Dor
|
|
74
62
|
|
75
63
|
raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})"
|
76
64
|
end
|
77
|
-
|
78
|
-
# make the request to the server for the currentVersion xml
|
79
|
-
# @raises [UnexpectedResponse] on an unsuccessful response from the server
|
80
|
-
# @returns [String] the raw xml from the server
|
81
|
-
def current_version_response(object:)
|
82
|
-
resp = connection.get do |req|
|
83
|
-
req.url current_version_path(object: object)
|
84
|
-
end
|
85
|
-
return resp.body if resp.success?
|
86
|
-
|
87
|
-
raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body}) for #{object}"
|
88
|
-
end
|
89
|
-
|
90
|
-
def current_version_path(object:)
|
91
|
-
"#{api_version}/sdr/objects/#{object}/current_version"
|
92
|
-
end
|
93
65
|
end
|
94
66
|
end
|
95
67
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dor
|
4
|
+
module Services
|
5
|
+
class Client
|
6
|
+
# API calls that are about preserved objects
|
7
|
+
class SDR < VersionedService
|
8
|
+
# Gets the current version number for the object
|
9
|
+
# @param object [String] the pid for the object
|
10
|
+
# @raise [UnexpectedResponse] when the response is not successful.
|
11
|
+
# @raise [MalformedResponse] when the response is not parseable.
|
12
|
+
# @return [Integer] the current version
|
13
|
+
def current_version(object:)
|
14
|
+
xml = current_version_response(object: object)
|
15
|
+
begin
|
16
|
+
doc = Nokogiri::XML xml
|
17
|
+
raise if doc.root.name != 'currentVersion'
|
18
|
+
|
19
|
+
return Integer(doc.text)
|
20
|
+
rescue StandardError
|
21
|
+
raise MalformedResponse, "Unable to parse XML from current_version API call: #{xml}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# make the request to the server for the currentVersion xml
|
28
|
+
# @raises [UnexpectedResponse] on an unsuccessful response from the server
|
29
|
+
# @returns [String] the raw xml from the server
|
30
|
+
def current_version_response(object:)
|
31
|
+
resp = connection.get do |req|
|
32
|
+
req.url current_version_path(object: object)
|
33
|
+
end
|
34
|
+
return resp.body if resp.success?
|
35
|
+
|
36
|
+
raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body}) for #{object}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def current_version_path(object:)
|
40
|
+
"#{api_version}/sdr/objects/#{object}/current_version"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
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: 0.
|
4
|
+
version: 0.8.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:
|
12
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -31,6 +31,20 @@ dependencies:
|
|
31
31
|
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '6'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: deprecation
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
34
48
|
- !ruby/object:Gem::Dependency
|
35
49
|
name: faraday
|
36
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,8 +165,10 @@ files:
|
|
151
165
|
- dor-services-client.gemspec
|
152
166
|
- lib/dor/services/client.rb
|
153
167
|
- lib/dor/services/client/files.rb
|
168
|
+
- lib/dor/services/client/object.rb
|
154
169
|
- lib/dor/services/client/objects.rb
|
155
170
|
- lib/dor/services/client/release_tags.rb
|
171
|
+
- lib/dor/services/client/sdr.rb
|
156
172
|
- lib/dor/services/client/version.rb
|
157
173
|
- lib/dor/services/client/versioned_service.rb
|
158
174
|
- lib/dor/services/client/workflow.rb
|
@@ -176,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
192
|
version: '0'
|
177
193
|
requirements: []
|
178
194
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.7.
|
195
|
+
rubygems_version: 2.7.6
|
180
196
|
signing_key:
|
181
197
|
specification_version: 4
|
182
198
|
summary: A client for dor-services-app
|