dor-services-client 0.3.0 → 0.4.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: b45f21acc65f3b29c81ebf03e4512ee40c5003a315ff47feae0996d15d29d595
4
- data.tar.gz: 2b2097c966dedfa7a0fc48d1b6833dd7ce635404e881672b92068d4dcd25eb6b
3
+ metadata.gz: d0938b1979de1f6767e88044a77182623502a0ee923d445fd11d892f83c9c81c
4
+ data.tar.gz: d091617c14b075d111980b1052ab0662382362bbbdd2ffe943609c4d94f997ee
5
5
  SHA512:
6
- metadata.gz: 96db3a5aa59b83229cd041a1940fdc04e0a288b956913bafb0ba5ea00c6bbab2647d4fb5d8d6cd96c5a4f1f82ec7a74e1d7621f37bd9900503a550f7b3d08762
7
- data.tar.gz: d1943ff6479e2cc78a482fea8b51cc532ed6b96ea62db2ee9f1ff76effe23b0cf52c0045715b3bc9115fe4be6f5166f37839f9c4e5900058b9451fcb00d381cb
6
+ metadata.gz: 121eecbb6172914d1bd345167ae7f92064c815c17634f2e017cf1c39617368da597e4d0cb9598c7d907cff64e3d7740d4916f174ba3d1c33b5b2e57b7eb66087
7
+ data.tar.gz: 99ce5863977ec58b8b315ed91867eeb8c1f2f31efe763f045ca0519676d0b03842bdf9095f67bee5e9ea5bd041c3ddf939c26dd792d68f645eabd591594e4b67
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'activesupport', '~> 5.0'
25
+ spec.add_dependency 'activesupport', '>= 4.2', '< 6'
26
26
  spec.add_dependency 'faraday', '~> 0.15'
27
27
 
28
28
  spec.add_development_dependency 'bundler', '~> 1.17'
@@ -4,6 +4,7 @@ require 'dor/services/client/version'
4
4
  require 'singleton'
5
5
  require 'faraday'
6
6
  require 'active_support/core_ext/hash/indifferent_access'
7
+ require 'dor/services/client/versioned_service'
7
8
  require 'dor/services/client/files'
8
9
  require 'dor/services/client/objects'
9
10
  require 'dor/services/client/release_tags'
@@ -15,30 +16,36 @@ module Dor
15
16
  class Client
16
17
  class Error < StandardError; end
17
18
 
19
+ DEFAULT_VERSION = 'v1'
20
+
18
21
  include Singleton
19
22
 
20
23
  def objects
21
- @objects ||= Objects.new(connection: connection)
24
+ @objects ||= Objects.new(connection: connection, version: DEFAULT_VERSION)
22
25
  end
23
26
 
24
27
  def files
25
- @files ||= Files.new(connection: connection)
28
+ @files ||= Files.new(connection: connection, version: DEFAULT_VERSION)
26
29
  end
27
30
 
28
31
  def workflow
29
- @workflow ||= Workflow.new(connection: connection)
32
+ @workflow ||= Workflow.new(connection: connection, version: DEFAULT_VERSION)
30
33
  end
31
34
 
32
35
  def workspace
33
- @workspace ||= Workspace.new(connection: connection)
36
+ @workspace ||= Workspace.new(connection: connection, version: DEFAULT_VERSION)
34
37
  end
35
38
 
36
39
  def release_tags
37
- @release_tags ||= ReleaseTags.new(connection: connection)
40
+ @release_tags ||= ReleaseTags.new(connection: connection, version: DEFAULT_VERSION)
38
41
  end
39
42
 
40
- def self.configure(url:)
43
+ def self.configure(url:, username: nil, password: nil)
41
44
  instance.url = url
45
+ instance.username = username
46
+ instance.password = password
47
+ # Force connection to be re-established when `.configure` is called
48
+ instance.connection = nil
42
49
  end
43
50
 
44
51
  # Creates a new object in DOR
@@ -97,16 +104,24 @@ module Dor
97
104
  instance.objects.publish(object: object)
98
105
  end
99
106
 
100
- attr_writer :url
107
+ attr_writer :url, :username, :password, :connection
101
108
 
102
109
  private
103
110
 
111
+ attr_reader :username, :password
112
+
104
113
  def url
105
114
  @url || raise(Error, 'url has not yet been configured')
106
115
  end
107
116
 
108
117
  def connection
109
- @connection ||= Faraday.new(url)
118
+ @connection ||= Faraday.new(url) do |conn|
119
+ # @note when username & password are nil, this line is required else
120
+ # the Faraday instance will be passed an empty block, which
121
+ # causes the adapter not to be set. Thus, everything breaks.
122
+ conn.adapter Faraday.default_adapter
123
+ conn.basic_auth username, password if username && password
124
+ end
110
125
  end
111
126
  end
112
127
  end
@@ -4,14 +4,10 @@ module Dor
4
4
  module Services
5
5
  class Client
6
6
  # API calls relating to files
7
- class Files
8
- def initialize(connection:)
9
- @connection = connection
10
- end
11
-
7
+ class Files < VersionedService
12
8
  def retrieve(object:, filename:)
13
9
  resp = connection.get do |req|
14
- req.url "v1/objects/#{object}/contents/#{filename}"
10
+ req.url "#{version}/objects/#{object}/contents/#{filename}"
15
11
  end
16
12
  return unless resp.success?
17
13
 
@@ -20,17 +16,13 @@ module Dor
20
16
 
21
17
  def list(object:)
22
18
  resp = connection.get do |req|
23
- req.url "v1/objects/#{object}/contents"
19
+ req.url "#{version}/objects/#{object}/contents"
24
20
  end
25
21
  return [] unless resp.success?
26
22
 
27
23
  json = JSON.parse(resp.body)
28
24
  json['items'].map { |item| item['name'] }
29
25
  end
30
-
31
- private
32
-
33
- attr_reader :connection
34
26
  end
35
27
  end
36
28
  end
@@ -4,18 +4,12 @@ module Dor
4
4
  module Services
5
5
  class Client
6
6
  # API calls that are about a repository object
7
- class Objects
8
- def initialize(connection:)
9
- @connection = connection
10
- end
11
-
12
- attr_reader :connection
13
-
7
+ class Objects < VersionedService
14
8
  # Creates a new object in DOR
15
9
  # @return [HashWithIndifferentAccess] the response, which includes a :pid
16
10
  def register(params:)
17
11
  resp = connection.post do |req|
18
- req.url 'v1/objects'
12
+ req.url "#{version}/objects"
19
13
  req.headers['Content-Type'] = 'application/json'
20
14
  # asking the service to return JSON (else it'll be plain text)
21
15
  req.headers['Accept'] = 'application/json'
@@ -32,7 +26,7 @@ module Dor
32
26
  # @return [boolean] true on success
33
27
  def publish(object:)
34
28
  resp = connection.post do |req|
35
- req.url "v1/objects/#{object}/publish"
29
+ req.url "#{version}/objects/#{object}/publish"
36
30
  end
37
31
  raise Error, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
38
32
 
@@ -4,13 +4,7 @@ module Dor
4
4
  module Services
5
5
  class Client
6
6
  # API calls that are about a repository object
7
- class ReleaseTags
8
- def initialize(connection:)
9
- @connection = connection
10
- end
11
-
12
- attr_reader :connection
13
-
7
+ class ReleaseTags < VersionedService
14
8
  # Creates a new release tag for the object
15
9
  # @param object [String] the pid for the object
16
10
  # @param release [Boolean]
@@ -27,7 +21,7 @@ module Dor
27
21
  release: release
28
22
  }
29
23
  resp = connection.post do |req|
30
- req.url "v1/objects/#{object}/release_tags"
24
+ req.url "#{version}/objects/#{object}/release_tags"
31
25
  req.headers['Content-Type'] = 'application/json'
32
26
  req.body = params.to_json
33
27
  end
@@ -3,7 +3,7 @@
3
3
  module Dor
4
4
  module Services
5
5
  class Client
6
- VERSION = '0.3.0'
6
+ VERSION = '0.4.0'
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dor
4
+ module Services
5
+ class Client
6
+ # @abstract API calls to a versioned endpoint
7
+ class VersionedService
8
+ def initialize(connection:, version:)
9
+ @connection = connection
10
+ @version = version
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :connection, :version
16
+ end
17
+ end
18
+ end
19
+ end
@@ -4,13 +4,7 @@ module Dor
4
4
  module Services
5
5
  class Client
6
6
  # API calls that are about workflow
7
- class Workflow
8
- def initialize(connection:)
9
- @connection = connection
10
- end
11
-
12
- attr_reader :connection
13
-
7
+ class Workflow < VersionedService
14
8
  # Begin a new workflow
15
9
  # @param object [String] the pid for the object
16
10
  # @param wf_name [String] the name of the workflow
@@ -18,7 +12,7 @@ module Dor
18
12
  # @return nil
19
13
  def create(object:, wf_name:)
20
14
  resp = connection.post do |req|
21
- req.url "v1/objects/#{object}/apo_workflows/#{wf_name}"
15
+ req.url "#{version}/objects/#{object}/apo_workflows/#{wf_name}"
22
16
  end
23
17
  raise Error, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
24
18
  end
@@ -4,13 +4,7 @@ module Dor
4
4
  module Services
5
5
  class Client
6
6
  # API calls that are about the DOR workspace
7
- class Workspace
8
- def initialize(connection:)
9
- @connection = connection
10
- end
11
-
12
- attr_reader :connection
13
-
7
+ class Workspace < VersionedService
14
8
  # Initializes a new workspace
15
9
  # @param object [String] the pid for the object
16
10
  # @param source [String] the path to the object
@@ -18,7 +12,7 @@ module Dor
18
12
  # @return nil
19
13
  def create(object:, source:)
20
14
  resp = connection.post do |req|
21
- req.url "v1/objects/#{object}/initialize_workspace"
15
+ req.url "#{version}/objects/#{object}/initialize_workspace"
22
16
  req.params['source'] = source
23
17
  end
24
18
  raise Error, "#{resp.reason_phrase}: #{resp.status} (#{resp.body})" unless resp.success?
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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Coyne
@@ -9,22 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-12-19 00:00:00.000000000 Z
12
+ date: 2018-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '4.2'
21
+ - - "<"
19
22
  - !ruby/object:Gem::Version
20
- version: '5.0'
23
+ version: '6'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '4.2'
31
+ - - "<"
26
32
  - !ruby/object:Gem::Version
27
- version: '5.0'
33
+ version: '6'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: faraday
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +139,7 @@ files:
133
139
  - lib/dor/services/client/objects.rb
134
140
  - lib/dor/services/client/release_tags.rb
135
141
  - lib/dor/services/client/version.rb
142
+ - lib/dor/services/client/versioned_service.rb
136
143
  - lib/dor/services/client/workflow.rb
137
144
  - lib/dor/services/client/workspace.rb
138
145
  homepage: https://github.com/sul-dlss/dor-services-client