preservation-client 0.5.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: 05d036c5889b48b53bcd21a9d86edbbcb1bfe0dee6664532d52ae4358ccb4253
4
- data.tar.gz: 1f69f80a51334169011dbff4b2f612465d12733f38c0ba064ec1eee9d030bfc9
3
+ metadata.gz: c3e72f59fd17b0ef985fb4ede247f9c598aa729a57aee3df6cf3b03bb58df68d
4
+ data.tar.gz: 5b91b5227bfbeca9e0e1df2162fc66ef19ca871570ea9709a076d697b4b3295e
5
5
  SHA512:
6
- metadata.gz: 0b48324d321045fd466bf52a766dea050ea0cb82bfef4d5456bea54fd80e48d917ea698e5d3729628c7d004fba90b8425dc383f741b0d376e96de1d99904571c
7
- data.tar.gz: c23a295b93adc88877a125535c21126c865462bc49a6241e8f7511feb0fd6b4fb6e79e3f7af6f6a574e472bcdc82a9a085ad187e931e66638dab3887e04fba95
6
+ metadata.gz: fb5818a17c85a4cc2695ea369f7eae4fd499a7cced7334522d9e508f5cd0c11be78161d7547d1b5c28a33c0c99fef3dff6dedf9caf914b546b610c99be43fa23
7
+ data.tar.gz: a91fb05d81e242b25a0ffafd7f146e201b1774d7cc49d8d2c58d2cbbca2406303411d51e64908b9e022b8a4488b86da07b98fc2a22771b92a71128812b9fa0cb
data/README.md CHANGED
@@ -25,6 +25,8 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
 
28
+ Preservation::Client is a singleton object, and thus can be used as a class or an instance.
29
+
28
30
  ```ruby
29
31
  require 'preservation/client'
30
32
 
@@ -39,13 +41,28 @@ def client
39
41
  end
40
42
  ```
41
43
 
44
+ OR
45
+
46
+ ```ruby
47
+ require 'preservation/client'
48
+
49
+ def initialize
50
+ Preservation::Client.configure(url: Settings.preservation_catalog.url)
51
+ end
52
+
53
+ def do_the_thing
54
+ current_version_as_integer = Preservation::Client.current_version('druid:oo000oo0000')
55
+ end
56
+ ```
57
+
42
58
  Note that the client may **not** be used without first having been configured, and the `url` keyword is **required**.
43
59
 
44
60
  Note that the preservation service is behind a firewall.
45
61
 
46
62
  ## API Coverage
47
63
 
48
- druids may be with or without the "druid:" prefix - 'oo000oo0000' or 'druid:oo000oo0000'
64
+ - druids may be with or without the "druid:" prefix - 'oo000oo0000' or 'druid:oo000oo0000'
65
+ - methods can be called as `client_instance.objects.method` or `Preservation::Client.objects.method`
49
66
 
50
67
  ### Get the current version of a preserved object (Moab)
51
68
 
@@ -67,8 +84,7 @@ druids may be with or without the "druid:" prefix - 'oo000oo0000' or 'druid:oo00
67
84
  - `client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml')` - returns contents of identityMetadata.xml in most recent version of Moab object
68
85
  - You may specify the version:
69
86
  - `client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml', version: '8')` - returns contents of identityMetadata.xml in version 8 of Moab object
70
- - `client.objects.signature_catalog('oo000oo0000')` - returns latest Moab::SignatureCatalog from Moab, or new Moab::SignatureCatalog for Moab if none yet exists
71
-
87
+ - `client.objects.signature_catalog('oo000oo0000')` - returns latest Moab::SignatureCatalog from Moab
72
88
 
73
89
  ### Get difference information between passed contentMetadata.xml and files in the Moab
74
90
 
@@ -71,16 +71,10 @@ module Preservation
71
71
  end
72
72
 
73
73
  # convenience method for retrieving latest Moab::SignatureCatalog from a Moab object,
74
- # or a newly minted Moab::SignatureCatalog if it doesn't yet exist
75
74
  # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
76
- # @return [Moab::SignatureCatalog] the catalog of all files previously ingested
75
+ # @return [Moab::SignatureCatalog] the manifest of all files previously ingested
77
76
  def signature_catalog(druid)
78
77
  Moab::SignatureCatalog.parse manifest(druid: druid, filepath: 'signatureCatalog.xml')
79
- rescue Preservation::Client::UnexpectedResponseError => e
80
- return Moab::SignatureCatalog.new(digital_object_id: druid, version_id: 0) if
81
- e.message.match?('404 File Not Found')
82
-
83
- raise
84
78
  end
85
79
 
86
80
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Preservation
4
4
  class Client
5
- VERSION = '0.5.0'
5
+ VERSION = '1.0.0'
6
6
  end
7
7
  end
@@ -34,7 +34,7 @@ module Preservation
34
34
  rescue Faraday::ResourceNotFound => e
35
35
  errmsg = "HTTP GET to #{connection.url_prefix}#{req_url} failed with #{e.class}: #{e.message}"
36
36
  raise Preservation::Client::NotFoundError, errmsg
37
- rescue Faraday::ParsingError, Faraday::RetriableResponse => e
37
+ rescue Faraday::Error => e
38
38
  errmsg = "HTTP GET to #{connection.url_prefix}#{req_url} failed with #{e.class}: #{e.message}"
39
39
  raise Preservation::Client::UnexpectedResponseError, errmsg
40
40
  end
@@ -42,36 +42,32 @@ module Preservation
42
42
  # @param path [String] path to be appended to connection url (no leading slash)
43
43
  # @param params [Hash] optional params
44
44
  def get(path, params)
45
- get_path = api_version.present? ? "#{api_version}/#{path}" : path
46
- resp = connection.get get_path, params
47
- return resp.body if resp.success?
48
-
49
- errmsg = ResponseErrorFormatter
50
- .format(response: resp, client_method_name: caller_locations.first.label)
51
- raise Preservation::Client::UnexpectedResponseError, errmsg
52
- rescue Faraday::ResourceNotFound => e
53
- errmsg = "HTTP GET to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
54
- raise Preservation::Client::NotFoundError, errmsg
55
- rescue Faraday::ParsingError, Faraday::RetriableResponse => e
56
- errmsg = "HTTP GET to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
57
- raise Preservation::Client::UnexpectedResponseError, errmsg
45
+ http_response(:get, path, params)
58
46
  end
59
47
 
60
48
  # @param path [String] path to be appended to connection url (no leading slash)
61
49
  # @param params [Hash] optional params
62
50
  def post(path, params)
63
- post_path = api_version.present? ? "#{api_version}/#{path}" : path
64
- resp = connection.post post_path, params
51
+ http_response(:post, path, params)
52
+ end
53
+
54
+ # @param method [Symbol] :get or :post
55
+ # @param path [String] path to be appended to connection url (no leading slash)
56
+ # @param params [Hash] optional params
57
+ def http_response(method, path, params)
58
+ req_path = api_version.present? ? "#{api_version}/#{path}" : path
59
+ resp = connection.send(method, req_path, params)
65
60
  return resp.body if resp.success?
66
61
 
67
- errmsg = ResponseErrorFormatter
68
- .format(response: resp, client_method_name: caller_locations.first.label)
62
+ errmsg = ResponseErrorFormatter.format(response: resp, client_method_name: caller_locations.first.label)
63
+ raise Preservation::Client::NotFoundError, errmsg if resp.status == 404
64
+
69
65
  raise Preservation::Client::UnexpectedResponseError, errmsg
70
66
  rescue Faraday::ResourceNotFound => e
71
- errmsg = "HTTP POST to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
67
+ errmsg = "HTTP #{method.to_s.upcase} to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
72
68
  raise Preservation::Client::NotFoundError, errmsg
73
- rescue Faraday::ParsingError, Faraday::RetriableResponse => e
74
- errmsg = "HTTP POST to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
69
+ rescue Faraday::Error => e
70
+ errmsg = "HTTP #{method.to_s.upcase} to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
75
71
  raise Preservation::Client::UnexpectedResponseError, errmsg
76
72
  end
77
73
  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.5.0
4
+ version: 1.0.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-12-07 00:00:00.000000000 Z
11
+ date: 2019-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport