dor-services-client 0.10.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9eed92163307c689ed61735f07b910d9dd37821a8f77b744ffc5c1ff37956284
4
- data.tar.gz: 7f7be3de30b2c121f0fd8fbdf7103d8aadff50d89a2c3cf30f0e741c98d2d6c9
3
+ metadata.gz: 9d232d7cef9804e67fe55c361e33de98c052ee850aded786cf3cacd57868cbb5
4
+ data.tar.gz: 153b8235501ab55780248c1f55dd3e96d3074b1ac61f337e33e073f6965530dc
5
5
  SHA512:
6
- metadata.gz: 47b70505a9c21255bdfcfb4ac6c523e33ef39cbec3838f794242b1704c607f209e3b572586bb790cf07f4a6f22dc729f8adfb4265fdaac0c9ccd872a7d76ef74
7
- data.tar.gz: c3fcb06b5fba157bee9a5e7692b377f64d289fb3a5d4f476342783aec5e84f66bd583a5c2d78d9d8ecf7fe6a2b5d387abc8204d83329fcb3882d874ce28aab2c
6
+ metadata.gz: 00d3c92d8055e29dce098854e4fd0f68753adeddaa5499802dfc2867847d604f9602cc0072a03b12d1a0f9758cacc4cb21561faf1f0ae00bdb38b20f05c777e7
7
+ data.tar.gz: 1e7a5d3cb8b9a561800b4296fbae8310c0999257a34bb8c305b7a08fa7167aa9d0045eed6eba4cffdaec189dd1e163cfe76f631ff44c4243d81d33ddfdac891d
@@ -1,3 +1,8 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+
2
3
  AllCops:
3
4
  TargetRubyVersion: 2.3
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - 'spec/**/*'
@@ -6,12 +6,6 @@
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 3
10
- # Configuration parameters: CountComments, ExcludedMethods.
11
- # ExcludedMethods: refine
12
- Metrics/BlockLength:
13
- Max: 151
14
-
15
9
  # Offense count: 1
16
10
  Style/Documentation:
17
11
  Exclude:
@@ -19,8 +13,8 @@ Style/Documentation:
19
13
  - 'test/**/*'
20
14
  - 'lib/dor/services/client.rb'
21
15
 
22
- # Offense count: 10
16
+ # Offense count: 17
23
17
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
24
18
  # URISchemes: http, https
25
19
  Metrics/LineLength:
26
- Max: 115
20
+ Max: 140
data/README.md CHANGED
@@ -32,21 +32,46 @@ require 'dor/services/client'
32
32
 
33
33
  def do_the_thing
34
34
  # This API endpoint returns JSON
35
- response = client.register(params: { druid: 'druid:123' })
35
+ response = client.objects.register(params: { druid: 'druid:123' })
36
36
  response[:pid] # => 'druid:123'
37
37
  end
38
38
 
39
39
  private
40
40
 
41
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)
42
+ @client ||= Dor::Services::Client.configure(url: Settings.dor_services.url,
43
+ username: Settings.dor_services.user,
44
+ password: Settings.dor_services.pass)
45
45
  end
46
46
  ```
47
47
 
48
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
+ ## API Coverage
51
+
52
+ Dor::Services:Client provides a number of methods to simplify connecting to the RESTful HTTP API of dor-services-app. In this section we list all of the available methods, reflecting how much of the API the client covers:
53
+
54
+ ```ruby
55
+ # For registering a non-existent object
56
+ objects_client = Dor::Services::Client.objects
57
+ objects_client.register(params: {})
58
+
59
+ # For performing operations on a known, registered object
60
+ object_client = Dor::Services::Client.object(object_identifier)
61
+ object_client.publish
62
+ object_client.notify_goobi
63
+ object_client.current_version
64
+ object_client.open_new_version(**params)
65
+ object_client.close_version(**params)
66
+ object_client.files.retrieve(filename: filename_string)
67
+ object_client.files.preserved_content(filename: filename_string, version: version_string)
68
+ object_client.files.list
69
+ object_client.release_tags.create(release: release, what: what, to: to, who: who)
70
+ object_client.sdr.current_version
71
+ object_client.workflow.create(wf_name: workflow_name_string)
72
+ object_client.workspace.create(source: object_path_string)
73
+ ```
74
+
50
75
  ## Development
51
76
 
52
77
  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.
@@ -6,22 +6,19 @@ require 'faraday'
6
6
  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
- require 'dor/services/client/files'
10
9
  require 'dor/services/client/object'
11
10
  require 'dor/services/client/objects'
12
- require 'dor/services/client/release_tags'
13
- require 'dor/services/client/sdr'
14
- require 'dor/services/client/workflow'
15
- require 'dor/services/client/workspace'
16
- require 'deprecation'
17
11
 
18
12
  module Dor
19
13
  module Services
20
14
  class Client
21
15
  class Error < StandardError; end
22
16
 
17
+ # Error that is raised when the remote server returns a 404 Not Found
18
+ class NotFoundResponse < Error; end
19
+
23
20
  # Error that is raised when the remote server returns some unexpected response
24
- # this could be any 4xx or 5xx status.
21
+ # this could be any 4xx or 5xx status
25
22
  class UnexpectedResponse < Error; end
26
23
 
27
24
  # Error that is raised when the remote server returns some unparsable response
@@ -30,36 +27,15 @@ module Dor
30
27
  DEFAULT_VERSION = 'v1'
31
28
 
32
29
  include Singleton
33
- extend Deprecation
34
30
 
35
- def object(object)
36
- Object.new(connection: connection, version: DEFAULT_VERSION, object: object)
31
+ def object(object_identifier)
32
+ Object.new(connection: connection, version: DEFAULT_VERSION, object_id: object_identifier)
37
33
  end
38
34
 
39
35
  def objects
40
36
  @objects ||= Objects.new(connection: connection, version: DEFAULT_VERSION)
41
37
  end
42
38
 
43
- def sdr
44
- @sdr ||= SDR.new(connection: connection, version: DEFAULT_VERSION)
45
- end
46
-
47
- def files
48
- @files ||= Files.new(connection: connection, version: DEFAULT_VERSION)
49
- end
50
-
51
- def workflow
52
- @workflow ||= Workflow.new(connection: connection, version: DEFAULT_VERSION)
53
- end
54
-
55
- def workspace
56
- @workspace ||= Workspace.new(connection: connection, version: DEFAULT_VERSION)
57
- end
58
-
59
- def release_tags
60
- @release_tags ||= ReleaseTags.new(connection: connection, version: DEFAULT_VERSION)
61
- end
62
-
63
39
  class << self
64
40
  def configure(url:, username: nil, password: nil)
65
41
  instance.url = url
@@ -71,99 +47,7 @@ module Dor
71
47
  self
72
48
  end
73
49
 
74
- delegate :objects, :object, :files, :workflow, :workspace, :release_tags, :sdr, to: :instance
75
- private :objects, :files, :workflow, :workspace, :release_tags
76
-
77
- # Creates a new object in DOR
78
- # @return [HashWithIndifferentAccess] the response, which includes a :pid
79
- delegate :register, to: :objects
80
-
81
- # @param [String] object the identifier for the object
82
- # @param [String] filename the name of the file to retrieve
83
- # @return [String] the file contents from the workspace
84
- def retrieve_file(object:, filename:)
85
- files.retrieve(object: object, filename: filename)
86
- end
87
-
88
- # Get the preserved file contents
89
- # @param [String] object the identifier for the object
90
- # @param [String] filename the name of the file to retrieve
91
- # @param [Integer] version the version of the file to retrieve
92
- # @return [String] the file contents from the SDR
93
- delegate :preserved_content, to: :files
94
-
95
- # @param [String] object the identifier for the object
96
- # @return [Array<String>] the list of filenames in the workspace
97
- def list_files(object:)
98
- files.list(object: object)
99
- end
100
-
101
- # Initializes a new workflow
102
- # @param object [String] the pid for the object
103
- # @param wf_name [String] the name of the workflow
104
- # @raises [UnexpectedResponse] if the request is unsuccessful.
105
- # @return nil
106
- def initialize_workflow(object:, wf_name:)
107
- workflow.create(object: object, wf_name: wf_name)
108
- end
109
-
110
- # Initializes a new workspace
111
- # @param object [String] the pid for the object
112
- # @param source [String] the path to the object
113
- # @raises [UnexpectedResponse] if the request is unsuccessful.
114
- # @return nil
115
- def initialize_workspace(object:, source:)
116
- workspace.create(object: object, source: source)
117
- end
118
-
119
- # Creates a new release tag for the object
120
- # @param object [String] the pid for the object
121
- # @param release [Boolean]
122
- # @param what [String]
123
- # @param to [String]
124
- # @param who [String]
125
- # @return [Boolean] true if successful
126
- def create_release_tag(object:, release:, what:, to:, who:)
127
- release_tags.create(object: object, release: release, what: what, to: to, who: who)
128
- end
129
-
130
- # Open new version for an object
131
- # @param object [String] object identifier
132
- # @param params [Hash] optional params (see dor-services-app)
133
- # @raise [UnexpectedResponse] when the response is not successful.
134
- # @raise [MalformedResponse] when the response is not parseable.
135
- # @return [String] the current version
136
- def open_new_version(object:, **params)
137
- object(object).open_new_version(**params)
138
- end
139
-
140
- # Close current version for an object
141
- # @param object [String] object identifier
142
- # @param params [Hash] optional params (see dor-services-app)
143
- # @raise [UnexpectedResponse] when the response is not successful.
144
- # @return [String] a message confirming successful closing
145
- def close_version(object:, **params)
146
- object(object).close_version(**params)
147
- end
148
-
149
- # Publish a new object
150
- # @param object [String] the pid for the object
151
- # @raise [UnexpectedResponse] when the response is not successful.
152
- # @return [boolean] true on success
153
- delegate :publish, to: :objects
154
-
155
- # Notify goobi system of a new object
156
- delegate :notify_goobi, to: :objects
157
-
158
- # Gets the current version number for the object
159
- # @param object [String] the pid for the object
160
- # @raise [UnexpectedResponse] when the response is not successful.
161
- # @raise [MalformedResponse] when the response is not parseable.
162
- # @return [Integer] the current version
163
- def current_version(object:)
164
- sdr.current_version(object: object)
165
- end
166
- deprecation_deprecate current_version: 'use Client.sdr.current_version instead'
50
+ delegate :objects, :object, to: :instance
167
51
  end
168
52
 
169
53
  attr_writer :url, :username, :password, :connection
@@ -5,13 +5,18 @@ module Dor
5
5
  class Client
6
6
  # API calls relating to files
7
7
  class Files < VersionedService
8
+ # @param object_id [String] the pid for the object
9
+ def initialize(connection:, version:, object_id:)
10
+ super(connection: connection, version: version)
11
+ @object_id = object_id
12
+ end
13
+
8
14
  # Get the contents from the workspace
9
- # @param [String] object the identifier for the object
10
15
  # @param [String] filename the name of the file to retrieve
11
16
  # @return [String] the file contents from the workspace
12
- def retrieve(object:, filename:)
17
+ def retrieve(filename:)
13
18
  resp = connection.get do |req|
14
- req.url "#{api_version}/objects/#{object}/contents/#{filename}"
19
+ req.url "#{api_version}/objects/#{object_id}/contents/#{filename}"
15
20
  end
16
21
  return unless resp.success?
17
22
 
@@ -19,13 +24,12 @@ module Dor
19
24
  end
20
25
 
21
26
  # Get the preserved file contents
22
- # @param [String] object the identifier for the object
23
27
  # @param [String] filename the name of the file to retrieve
24
28
  # @param [Integer] version the version of the file to retrieve
25
29
  # @return [String] the file contents from the SDR
26
- def preserved_content(object:, filename:, version:)
30
+ def preserved_content(filename:, version:)
27
31
  resp = connection.get do |req|
28
- req.url "#{api_version}/sdr/objects/#{object}/content/#{CGI.escape(filename)}?version=#{version}"
32
+ req.url "#{api_version}/sdr/objects/#{object_id}/content/#{CGI.escape(filename)}?version=#{version}"
29
33
  end
30
34
  return unless resp.success?
31
35
 
@@ -33,17 +37,20 @@ module Dor
33
37
  end
34
38
 
35
39
  # Get the list of files in the workspace
36
- # @param [String] object the identifier for the object
37
40
  # @return [Array<String>] the list of filenames in the workspace
38
- def list(object:)
41
+ def list
39
42
  resp = connection.get do |req|
40
- req.url "#{api_version}/objects/#{object}/contents"
43
+ req.url "#{api_version}/objects/#{object_id}/contents"
41
44
  end
42
45
  return [] unless resp.success?
43
46
 
44
47
  json = JSON.parse(resp.body)
45
48
  json['items'].map { |item| item['name'] }
46
49
  end
50
+
51
+ private
52
+
53
+ attr_reader :object_id
47
54
  end
48
55
  end
49
56
  end
@@ -1,69 +1,99 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'nokogiri'
4
- require 'deprecation'
3
+ require 'dor/services/client/files'
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'
5
8
 
6
9
  module Dor
7
10
  module Services
8
11
  class Client
9
12
  # API calls that are about a repository object
10
13
  class Object < VersionedService
11
- # @param object [String] the pid for the object
12
- def initialize(connection:, version:, object:)
14
+ # @param object_id [String] the pid for the object
15
+ def initialize(connection:, version:, object_id:)
16
+ raise ArgumentError, "The `object_id` parameter must be an identifier string: #{object_id.inspect}" unless object_id.is_a?(String)
17
+
13
18
  super(connection: connection, version: version)
14
- @object = object
19
+ @object_id = object_id
20
+ end
21
+
22
+ def sdr
23
+ @sdr ||= SDR.new(connection: connection, version: api_version, object_id: object_id)
24
+ end
25
+
26
+ def files
27
+ @files ||= Files.new(connection: connection, version: api_version, object_id: object_id)
28
+ end
29
+
30
+ def workflow
31
+ @workflow ||= Workflow.new(connection: connection, version: api_version, object_id: object_id)
32
+ end
33
+
34
+ def workspace
35
+ @workspace ||= Workspace.new(connection: connection, version: api_version, object_id: object_id)
36
+ end
37
+
38
+ def release_tags
39
+ @release_tags ||= ReleaseTags.new(connection: connection, version: api_version, object_id: object_id)
15
40
  end
16
41
 
17
42
  # Publish a new object
43
+ # @raise [NotFoundResponse] when the response is a 404 (object not found)
18
44
  # @raise [UnexpectedResponse] when the response is not successful.
19
45
  # @return [boolean] true on success
20
46
  def publish
21
47
  resp = connection.post do |req|
22
- req.url "#{api_version}/objects/#{object}/publish"
48
+ req.url "#{object_path}/publish"
23
49
  end
24
- raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
50
+ return true if resp.success?
25
51
 
26
- true
52
+ raise_exception_based_on_response!(resp)
27
53
  end
28
54
 
29
55
  # Notify the external Goobi system for a new object that was registered in DOR
56
+ # @raise [NotFoundResponse] when the response is a 404 (object not found)
30
57
  # @raise [UnexpectedResponse] when the response is not successful.
31
58
  # @return [boolean] true on success
32
59
  def notify_goobi
33
60
  resp = connection.post do |req|
34
61
  req.url "#{object_path}/notify_goobi"
35
62
  end
36
- raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
63
+ return true if resp.success?
37
64
 
38
- true
65
+ raise_exception_based_on_response!(resp)
39
66
  end
40
67
 
41
68
  # Get the current_version for a DOR object. This comes from Dor::VersionMetadataDS
69
+ # @raise [NotFoundResponse] when the response is a 404 (object not found)
42
70
  # @raise [UnexpectedResponse] when the response is not successful.
43
71
  # @return [String] the version identifier
44
72
  def current_version
45
73
  resp = connection.get do |req|
46
74
  req.url "#{object_path}/versions/current"
47
75
  end
48
- raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
76
+ return resp.body if resp.success?
49
77
 
50
- resp.body
78
+ raise_exception_based_on_response!(resp)
51
79
  end
52
80
 
53
81
  # Open new version for an object
54
82
  # @param params [Hash] optional params (see dor-services-app)
55
- # @raise [UnexpectedResponse] when the response is not successful.
56
83
  # @raise [MalformedResponse] when the response is not parseable.
84
+ # @raise [NotFoundResponse] when the response is a 404 (object not found)
85
+ # @raise [UnexpectedResponse] when the response is not successful.
57
86
  # @return [String] the current version
58
87
  def open_new_version(**params)
59
88
  version = open_new_version_response(**params)
60
- raise MalformedResponse, "Version of #{object} is empty" if version.empty?
89
+ raise MalformedResponse, "Version of #{object_id} is empty" if version.empty?
61
90
 
62
91
  version
63
92
  end
64
93
 
65
94
  # Close current version for an object
66
95
  # @param params [Hash] optional params (see dor-services-app)
96
+ # @raise [NotFoundResponse] when the response is a 404 (object not found)
67
97
  # @raise [UnexpectedResponse] when the response is not successful.
68
98
  # @return [String] a message confirming successful closing
69
99
  def close_version(**params)
@@ -74,19 +104,25 @@ module Dor
74
104
  end
75
105
  return resp.body if resp.success?
76
106
 
77
- raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body}) for #{object}"
107
+ raise_exception_based_on_response!(resp)
78
108
  end
79
109
 
80
110
  private
81
111
 
82
- attr_reader :object
112
+ attr_reader :object_id
83
113
 
84
114
  def object_path
85
- "#{api_version}/objects/#{object}"
115
+ "#{api_version}/objects/#{object_id}"
116
+ end
117
+
118
+ def raise_exception_based_on_response!(response)
119
+ raise (response.status == 404 ? NotFoundResponse : UnexpectedResponse),
120
+ "#{response.reason_phrase}: #{response.status} (#{response.body})"
86
121
  end
87
122
 
88
123
  # Make request to server to open a new version
89
124
  # @param params [Hash] optional params (see dor-services-app)
125
+ # @raise [NotFoundResponse] when the response is a 404 (object not found)
90
126
  # @raises [UnexpectedResponse] on an unsuccessful response from the server
91
127
  # @returns [String] the plain text from the server
92
128
  def open_new_version_response(**params)
@@ -97,7 +133,7 @@ module Dor
97
133
  end
98
134
  return resp.body if resp.success?
99
135
 
100
- raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body}) for #{object}"
136
+ raise_exception_based_on_response!(resp)
101
137
  end
102
138
 
103
139
  def open_new_version_path
@@ -1,14 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'nokogiri'
4
-
5
3
  module Dor
6
4
  module Services
7
5
  class Client
8
6
  # API calls that are about a repository objects
9
7
  class Objects < VersionedService
10
- extend Deprecation
11
-
12
8
  # Creates a new object in DOR
13
9
  # @return [HashWithIndifferentAccess] the response, which includes a :pid
14
10
  def register(params:)
@@ -16,34 +12,6 @@ module Dor
16
12
  JSON.parse(json).with_indifferent_access
17
13
  end
18
14
 
19
- # Publish a new object
20
- # @param object [String] the pid for the object
21
- # @raise [UnexpectedResponse] when the response is not successful.
22
- # @return [boolean] true on success
23
- def publish(object:)
24
- Object.new(connection: connection, version: api_version, object: object).publish
25
- end
26
- deprecation_deprecate publish: 'Use Dor::Services::Client.object(obj).publish instead'
27
-
28
- # Notify the external Goobi system for a new object that was registered in DOR
29
- # @param object [String] the pid for the object
30
- # @raise [UnexpectedResponse] when the response is not successful.
31
- # @return [boolean] true on success
32
- def notify_goobi(object:)
33
- Object.new(connection: connection, version: api_version, object: object).notify_goobi
34
- end
35
- deprecation_deprecate notify_goobi: 'Use Dor::Services::Client.object(obj).notify_goobi instead'
36
-
37
- # Gets the current version number for the object
38
- # @param object [String] the pid for the object
39
- # @raise [UnexpectedResponse] when the response is not successful.
40
- # @raise [MalformedResponse] when the response is not parseable.
41
- # @return [Integer] the current version
42
- def current_version(object:)
43
- SDR.new(connection: connection, version: api_version).current_version(object: object)
44
- end
45
- deprecation_deprecate current_version: 'Use Dor::Services::Client.sdr.current_version(object: obj) instead'
46
-
47
15
  private
48
16
 
49
17
  # make the registration request to the server
@@ -5,8 +5,13 @@ module Dor
5
5
  class Client
6
6
  # API calls that are about a repository object
7
7
  class ReleaseTags < VersionedService
8
+ # @param object_id [String] the pid for the object
9
+ def initialize(connection:, version:, object_id:)
10
+ super(connection: connection, version: version)
11
+ @object_id = object_id
12
+ end
13
+
8
14
  # Creates a new release tag for the object
9
- # @param object [String] the pid for the object
10
15
  # @param release [Boolean]
11
16
  # @param what [String]
12
17
  # @param to [String]
@@ -14,7 +19,7 @@ module Dor
14
19
  # @raises [UnexpectedResponse] if the request is unsuccessful.
15
20
  # @return [Boolean] true if successful
16
21
  # rubocop:disable Metrics/MethodLength
17
- def create(object:, release:, what:, to:, who:)
22
+ def create(release:, what:, to:, who:)
18
23
  params = {
19
24
  to: to,
20
25
  who: who,
@@ -22,7 +27,7 @@ module Dor
22
27
  release: release
23
28
  }
24
29
  resp = connection.post do |req|
25
- req.url "#{api_version}/objects/#{object}/release_tags"
30
+ req.url "#{api_version}/objects/#{object_id}/release_tags"
26
31
  req.headers['Content-Type'] = 'application/json'
27
32
  req.body = params.to_json
28
33
  end
@@ -31,6 +36,10 @@ module Dor
31
36
  true
32
37
  end
33
38
  # rubocop:enable Metrics/MethodLength
39
+
40
+ private
41
+
42
+ attr_reader :object_id
34
43
  end
35
44
  end
36
45
  end
@@ -1,17 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'nokogiri'
4
+
3
5
  module Dor
4
6
  module Services
5
7
  class Client
6
8
  # API calls that are about preserved objects
7
9
  class SDR < VersionedService
10
+ # @param object_id [String] the pid for the object
11
+ def initialize(connection:, version:, object_id:)
12
+ super(connection: connection, version: version)
13
+ @object_id = object_id
14
+ end
15
+
8
16
  # Gets the current version number for the object
9
- # @param object [String] the pid for the object
10
17
  # @raise [UnexpectedResponse] when the response is not successful.
11
18
  # @raise [MalformedResponse] when the response is not parseable.
12
19
  # @return [Integer] the current version
13
- def current_version(object:)
14
- xml = current_version_response(object: object)
20
+ def current_version
21
+ xml = current_version_response
15
22
  begin
16
23
  doc = Nokogiri::XML xml
17
24
  raise if doc.root.name != 'currentVersion'
@@ -24,20 +31,22 @@ module Dor
24
31
 
25
32
  private
26
33
 
34
+ attr_reader :object_id
35
+
27
36
  # make the request to the server for the currentVersion xml
28
37
  # @raises [UnexpectedResponse] on an unsuccessful response from the server
29
38
  # @returns [String] the raw xml from the server
30
- def current_version_response(object:)
39
+ def current_version_response
31
40
  resp = connection.get do |req|
32
- req.url current_version_path(object: object)
41
+ req.url current_version_path
33
42
  end
34
43
  return resp.body if resp.success?
35
44
 
36
- raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body}) for #{object}"
45
+ raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body}) for #{object_id}"
37
46
  end
38
47
 
39
- def current_version_path(object:)
40
- "#{api_version}/sdr/objects/#{object}/current_version"
48
+ def current_version_path
49
+ "#{api_version}/sdr/objects/#{object_id}/current_version"
41
50
  end
42
51
  end
43
52
  end
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Services
5
5
  class Client
6
- VERSION = '0.10.0'
6
+ VERSION = '1.0.0'
7
7
  end
8
8
  end
9
9
  end
@@ -5,17 +5,26 @@ module Dor
5
5
  class Client
6
6
  # API calls that are about workflow
7
7
  class Workflow < VersionedService
8
+ # @param object_id [String] the pid for the object
9
+ def initialize(connection:, version:, object_id:)
10
+ super(connection: connection, version: version)
11
+ @object_id = object_id
12
+ end
13
+
8
14
  # Begin a new workflow
9
- # @param object [String] the pid for the object
10
15
  # @param wf_name [String] the name of the workflow
11
16
  # @raises [UnexpectedResponse] if the request is unsuccessful.
12
17
  # @return nil
13
- def create(object:, wf_name:)
18
+ def create(wf_name:)
14
19
  resp = connection.post do |req|
15
- req.url "#{api_version}/objects/#{object}/apo_workflows/#{wf_name}"
20
+ req.url "#{api_version}/objects/#{object_id}/apo_workflows/#{wf_name}"
16
21
  end
17
22
  raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
18
23
  end
24
+
25
+ private
26
+
27
+ attr_reader :object_id
19
28
  end
20
29
  end
21
30
  end
@@ -5,18 +5,27 @@ module Dor
5
5
  class Client
6
6
  # API calls that are about the DOR workspace
7
7
  class Workspace < VersionedService
8
+ # @param object_id [String] the pid for the object
9
+ def initialize(connection:, version:, object_id:)
10
+ super(connection: connection, version: version)
11
+ @object_id = object_id
12
+ end
13
+
8
14
  # Initializes a new workspace
9
- # @param object [String] the pid for the object
10
15
  # @param source [String] the path to the object
11
16
  # @raises [UnexpectedResponse] if the request is unsuccessful.
12
17
  # @return nil
13
- def create(object:, source:)
18
+ def create(source:)
14
19
  resp = connection.post do |req|
15
- req.url "#{api_version}/objects/#{object}/initialize_workspace"
20
+ req.url "#{api_version}/objects/#{object_id}/initialize_workspace"
16
21
  req.params['source'] = source
17
22
  end
18
23
  raise UnexpectedResponse, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
19
24
  end
25
+
26
+ private
27
+
28
+ attr_reader :object_id
20
29
  end
21
30
  end
22
31
  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.10.0
4
+ version: 1.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-01-09 00:00:00.000000000 Z
12
+ date: 2019-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport