preservation-client 0.1.0 → 0.2.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: 95721382a355768cd08ee0280fd57dc9d7e7db65190202babb259c4dce2fe48d
4
- data.tar.gz: 198bd4efcd107026bbb864eb6ba5dc3ff058573139628bb90d864d97234700d7
3
+ metadata.gz: bd5473aaca131902c39dfed9a2f64f040f05fe058f88240a837bca61513e0aed
4
+ data.tar.gz: 0d4cabcf05268572e99869d5bb0919d94b7118d5ebf52a5de9a9acd50b1f1ca8
5
5
  SHA512:
6
- metadata.gz: cdacd347e69f8b5df8ffdebe692a7557e69de103ae2aeed8a9b1de80753f0665bd85123a7d6badaefad975852185223a444685b075f29cb4d07c38feb008f1fe
7
- data.tar.gz: ca8eb24ba43070a39e4b5ab625e31f48c07b7078123d5d6b5edf6cd0e908128230ac132ba8b20ccf0bf98b9968fb43cb219aea041a777a9e5fb724d1c13198b5
6
+ metadata.gz: c773deeb4f5106de43b9a8a87287ca6a87c3437419bbc25b2f208aee43c3f0de4c76a5835919aeecb2decc0f1458d5043337a9786f3ac5a71b4b5f2acf6de1d6
7
+ data.tar.gz: 95f6a7d7b736354ed67ab3dac8e5260d3cddd3dfa48486758e6ed926bc67f2101cdb61cf2ff60a6c0056f419eaa93b43d696ab58724c84faa01990ef51051ce3
@@ -0,0 +1,4 @@
1
+ ## Why was this change made?
2
+
3
+
4
+ ## Was the documentation (README, API, wiki, consul, etc.) updated?
data/.rubocop.yml CHANGED
@@ -8,6 +8,7 @@ Layout/EmptyLinesAroundClassBody:
8
8
 
9
9
  Metrics/BlockLength:
10
10
  Exclude:
11
+ - 'preservation-client.gemspec'
11
12
  - 'spec/**/*'
12
13
 
13
14
  Metrics/LineLength:
@@ -23,3 +24,6 @@ Style/Documentation:
23
24
  Exclude:
24
25
  - 'spec/**/*'
25
26
  - 'lib/preservation/client.rb'
27
+
28
+ Style/WordArray:
29
+ Enabled: false
data/README.md CHANGED
@@ -48,7 +48,9 @@ Note that the preservation service is behind a firewall.
48
48
 
49
49
  ## API Coverage
50
50
 
51
- TBD
51
+ - Preservation::Client.objects.current_version('oo000oo0000') (can also be 'druid:oo000oo0000')
52
+ - Preservation::Client.objects.checksums(druids: druids) - will return raw csv
53
+ - Preservation::Client.objects.checksums(druids: druids, format: 'json') - will return json
52
54
 
53
55
  ## Development
54
56
 
@@ -3,7 +3,7 @@
3
3
  module Preservation
4
4
  class Client
5
5
  # API calls that are about Preserved Objects
6
- class Objects < VersionedService
6
+ class Objects < VersionedApiService
7
7
 
8
8
  # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
9
9
  # @return [Integer] the current version of the Preserved Object
@@ -11,6 +11,13 @@ module Preservation
11
11
  resp_body = get_json("objects/#{druid}.json", druid, 'current_version')
12
12
  resp_body[:current_version]
13
13
  end
14
+
15
+ # @param [Array] druids - required list of druids with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
16
+ # @param [String] :resp_format - desired format of the HTTP response (default csv, json also possible)
17
+ # @return body of HTTP response from Preservation API
18
+ def checksums(druids: [], resp_format: 'csv')
19
+ post('objects/checksums', { druids: druids, format: resp_format }, 'checksums')
20
+ end
14
21
  end
15
22
  end
16
23
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Preservation
4
4
  class Client
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@
3
3
  module Preservation
4
4
  class Client
5
5
  # @abstract API calls to a versioned endpoint
6
- class VersionedService
6
+ class VersionedApiService
7
7
  def initialize(connection:, api_version:)
8
8
  @connection = connection
9
9
  @api_version = api_version
@@ -13,6 +13,7 @@ module Preservation
13
13
 
14
14
  attr_reader :connection, :api_version
15
15
 
16
+ # @param path [String] path to be appended to connection url (no leading slash)
16
17
  def get_json(path, object_id, caller_method_name)
17
18
  resp = connection.get do |req|
18
19
  req.url api_version.present? ? "#{api_version}/#{path}" : path
@@ -31,6 +32,24 @@ module Preservation
31
32
  errmsg = "HTTP GET to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
32
33
  raise Preservation::Client::UnexpectedResponseError, errmsg
33
34
  end
35
+
36
+ # @param path [String] path to be appended to connection url (no leading slash)
37
+ # @param params [Hash] optional params
38
+ def post(path, params, caller_method_name)
39
+ post_path = api_version.present? ? "#{api_version}/#{path}" : path
40
+ resp = connection.post post_path, params
41
+ return resp.body if resp.success?
42
+
43
+ errmsg = ResponseErrorFormatter
44
+ .format(response: resp, client_method_name: caller_method_name)
45
+ raise Preservation::Client::UnexpectedResponseError, errmsg
46
+ rescue Faraday::ResourceNotFound => e
47
+ errmsg = "HTTP POST to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
48
+ raise Preservation::Client::NotFoundError, errmsg
49
+ rescue Faraday::ParsingError, Faraday::RetriableResponse => e
50
+ errmsg = "HTTP POST to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
51
+ raise Preservation::Client::UnexpectedResponseError, errmsg
52
+ end
34
53
  end
35
54
  end
36
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preservation-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-20 00:00:00.000000000 Z
11
+ date: 2019-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -164,6 +164,7 @@ executables: []
164
164
  extensions: []
165
165
  extra_rdoc_files: []
166
166
  files:
167
+ - ".github/pull_request_template.md"
167
168
  - ".gitignore"
168
169
  - ".rspec"
169
170
  - ".rubocop.yml"
@@ -180,7 +181,7 @@ files:
180
181
  - lib/preservation/client/objects.rb
181
182
  - lib/preservation/client/response_error_formatter.rb
182
183
  - lib/preservation/client/version.rb
183
- - lib/preservation/client/versioned_service.rb
184
+ - lib/preservation/client/versioned_api_service.rb
184
185
  - preservation-client.gemspec
185
186
  homepage: https://github.com/sul-dlss/preservation-client
186
187
  licenses: []