preservation-client 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +3 -3
- data/.travis.yml +0 -5
- data/README.md +8 -1
- data/lib/preservation/client/objects.rb +47 -6
- data/lib/preservation/client/version.rb +1 -1
- data/lib/preservation/client/versioned_api_service.rb +22 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a3cb6037f122064b3cdf68406c4115c396b37cd91a54c4ea81e2f47dbff1cf9
|
4
|
+
data.tar.gz: 2ab77f39a12d58589282865ff8f764f455b384f91d83a3eec334fe9c7943a100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f57b21ddc5a6f4ed4935be2b5a156b08fe616c99972b7321c7af63c988190b8d75fd2f100714cfce70f61b457f388d8adfa896e151510c9672d42eed26ca6f4
|
7
|
+
data.tar.gz: b5bb602b1d94216dc7de1b2fe6a871be1f9e410c7261471794f1500f3217e0f2c380c4ab1170dadcd53244dd87aa59042c9f79ae17477d544f24a9cb29333306
|
data/.rubocop_todo.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2019-
|
3
|
+
# on 2019-12-03 15:41:39 -0800 using RuboCop version 0.74.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
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:
|
9
|
+
# Offense count: 3
|
10
10
|
Metrics/AbcSize:
|
11
|
-
Max:
|
11
|
+
Max: 34
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/preservation-client.svg)](https://badge.fury.io/rb/preservation-client)
|
2
2
|
[![Build Status](https://travis-ci.org/sul-dlss/preservation-client.svg?branch=master)](https://travis-ci.org/sul-dlss/preservation-client)
|
3
3
|
[![Maintainability](https://api.codeclimate.com/v1/badges/00d2d8957226777105b3/maintainability)](https://codeclimate.com/github/sul-dlss/preservation-client/maintainability)
|
4
4
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/00d2d8957226777105b3/test_coverage)](https://codeclimate.com/github/sul-dlss/preservation-client/test_coverage)
|
@@ -51,6 +51,13 @@ Note that the preservation service is behind a firewall.
|
|
51
51
|
- Preservation::Client.objects.current_version('oo000oo0000') (can also be 'druid:oo000oo0000')
|
52
52
|
- Preservation::Client.objects.checksums(druids: druids) - will return raw csv
|
53
53
|
- Preservation::Client.objects.checksums(druids: druids, format: 'json') - will return json
|
54
|
+
- Preservation::Client.objects.content(druid: 'oo000oo0000', filepath: 'my_file.pdf') - will return contents of my_file.pdf in most recent version of Moab object
|
55
|
+
- Preservation::Client.objects.content(druid: 'oo000oo0000', filepath: 'my_file.pdf', version: '1') - will return contents of my_file.pdf in version 1 of Moab object
|
56
|
+
- Preservation::Client.objects.manifest(druid: 'oo000oo0000', filepath: 'versionInventory.xml') - will return contents of versionInventory.xml in most recent version of Moab object
|
57
|
+
- Preservation::Client.objects.manifest(druid: 'oo000oo0000', filepath: 'versionInventory.xml', version: '3') - will return contents of versionInventory.xml in version 3 of Moab object
|
58
|
+
- Preservation::Client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml') - will return contents of identityMetadata.xml in most recent version of Moab object
|
59
|
+
- Preservation::Client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml', version: '8') - will return contents of identityMetadata.xml in version 8 of Moab object
|
60
|
+
- Preservation::Client.objects.signature_catalog(druid: 'oo000oo0000') - will return contents of latest version of signatureCatalog.xml from Moab object
|
54
61
|
|
55
62
|
## Development
|
56
63
|
|
@@ -4,19 +4,60 @@ module Preservation
|
|
4
4
|
class Client
|
5
5
|
# API calls that are about Preserved Objects
|
6
6
|
class Objects < VersionedApiService
|
7
|
+
# @param [Array] druids - required list of druids with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
|
8
|
+
# @param [String] resp_format - desired format of the HTTP response (default csv, json also possible)
|
9
|
+
# @return body of HTTP response from Preservation API - the checksums and filesize for each druid
|
10
|
+
def checksums(druids: [], resp_format: 'csv')
|
11
|
+
post('objects/checksums', druids: druids, format: resp_format)
|
12
|
+
end
|
7
13
|
|
8
14
|
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
|
9
15
|
# @return [Integer] the current version of the Preserved Object
|
10
16
|
def current_version(druid)
|
11
|
-
resp_body = get_json("objects/#{druid}.json", druid
|
17
|
+
resp_body = get_json("objects/#{druid}.json", druid)
|
12
18
|
resp_body[:current_version]
|
13
19
|
end
|
14
20
|
|
15
|
-
#
|
16
|
-
# @param [String]
|
17
|
-
# @
|
18
|
-
|
19
|
-
|
21
|
+
# retrieve a content file from a Moab object
|
22
|
+
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
|
23
|
+
# @param [String] filepath - the path of the file relative to the moab content directory
|
24
|
+
# @param [String] version - the version of the file requested (defaults to nil for latest version)
|
25
|
+
def content(druid:, filepath:, version: nil)
|
26
|
+
file(druid, 'content', filepath, version)
|
27
|
+
end
|
28
|
+
|
29
|
+
# retrieve a manifest file from a Moab object
|
30
|
+
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
|
31
|
+
# @param [String] filepath - the path of the file relative to the moab manifest directory
|
32
|
+
# @param [String] version - the version of the file requested (defaults to nil for latest version)
|
33
|
+
def manifest(druid:, filepath:, version: nil)
|
34
|
+
file(druid, 'manifest', filepath, version)
|
35
|
+
end
|
36
|
+
|
37
|
+
# retrieve a metadata file from a Moab object
|
38
|
+
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
|
39
|
+
# @param [String] filepath - the path of the file relative to the moab metadata directory
|
40
|
+
# @param [String] version - the version of the file requested (defaults to nil for latest version)
|
41
|
+
def metadata(druid:, filepath:, version: nil)
|
42
|
+
file(druid, 'metadata', filepath, version)
|
43
|
+
end
|
44
|
+
|
45
|
+
# convenience method for retrieving latest signatureCatalog.xml file from a Moab object
|
46
|
+
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
|
47
|
+
def signature_catalog(druid)
|
48
|
+
manifest(druid: druid, filepath: 'signatureCatalog.xml')
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# get a file from a Moab object
|
54
|
+
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
|
55
|
+
# @param [String] category - one of 'manifest', 'metadata' or 'content'
|
56
|
+
# @param [String] filepath - the path of the file relative to the moab category directory
|
57
|
+
# @param [String] version - the version of the file requested (defaults to nil for latest version)
|
58
|
+
# @return the retrieved file
|
59
|
+
def file(druid, category, filepath, version = nil)
|
60
|
+
get("objects/#{druid}/file", category: category, filepath: filepath, version: version)
|
20
61
|
end
|
21
62
|
end
|
22
63
|
end
|
@@ -14,7 +14,7 @@ module Preservation
|
|
14
14
|
attr_reader :connection, :api_version
|
15
15
|
|
16
16
|
# @param path [String] path to be appended to connection url (no leading slash)
|
17
|
-
def get_json(path, object_id
|
17
|
+
def get_json(path, object_id)
|
18
18
|
req_url = api_version.present? ? "#{api_version}/#{path}" : path
|
19
19
|
resp = connection.get do |req|
|
20
20
|
req.url req_url
|
@@ -28,7 +28,7 @@ module Preservation
|
|
28
28
|
raise Preservation::Client::NotFoundError, errmsg
|
29
29
|
else
|
30
30
|
errmsg = ResponseErrorFormatter
|
31
|
-
.format(response: resp, object_id: object_id, client_method_name:
|
31
|
+
.format(response: resp, object_id: object_id, client_method_name: caller_locations.first.label)
|
32
32
|
raise Preservation::Client::UnexpectedResponseError, errmsg
|
33
33
|
end
|
34
34
|
rescue Faraday::ResourceNotFound => e
|
@@ -41,13 +41,31 @@ module Preservation
|
|
41
41
|
|
42
42
|
# @param path [String] path to be appended to connection url (no leading slash)
|
43
43
|
# @param params [Hash] optional params
|
44
|
-
def
|
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
|
58
|
+
end
|
59
|
+
|
60
|
+
# @param path [String] path to be appended to connection url (no leading slash)
|
61
|
+
# @param params [Hash] optional params
|
62
|
+
def post(path, params)
|
45
63
|
post_path = api_version.present? ? "#{api_version}/#{path}" : path
|
46
64
|
resp = connection.post post_path, params
|
47
65
|
return resp.body if resp.success?
|
48
66
|
|
49
67
|
errmsg = ResponseErrorFormatter
|
50
|
-
.format(response: resp, client_method_name:
|
68
|
+
.format(response: resp, client_method_name: caller_locations.first.label)
|
51
69
|
raise Preservation::Client::UnexpectedResponseError, errmsg
|
52
70
|
rescue Faraday::ResourceNotFound => e
|
53
71
|
errmsg = "HTTP POST to #{connection.url_prefix}#{path} failed with #{e.class}: #{e.message}"
|
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.
|
4
|
+
version: 0.3.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-
|
11
|
+
date: 2019-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|