preservation-client 3.1.0 → 3.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: a5935f4397931242b724daedc842b1fdbdb8d84de5a0a61c0bd08b00064c4396
4
- data.tar.gz: d9ffeef6b17897ebad03ddab8508c62caaa247a35ce380e4ba5b543cf8244a04
3
+ metadata.gz: 6e05a1561753b1ba55bf0d15d239ab6e740430818548143e330327e32e44da7f
4
+ data.tar.gz: 8385f5b0f5c7fdbf0ee69e9c0f182a899fd36ea4e41b1d1f5d7f3a008e9e207f
5
5
  SHA512:
6
- metadata.gz: 5afaae843e9fd36aac08b07d514e307993864222a60210e94537f3cfa25f278bd7eccbdc7af6c1bc90b9987ca0bce3e78330092408acc3bf125e6f9685fea28f
7
- data.tar.gz: 4177db6c38c34714601a481ef8c6b4b89de04ce607ef766db3af6f136fd497675679a17080c1404fddc5c91a29d85ce2af1e18e09d5d0abcb9b10b47f3e1355d
6
+ metadata.gz: af564b18b850e9a4528743844dfc062fdb6b848f3725470f86e6b46e4c3c1e640952c736dfbad40985bdacee81c78ca344a2fe74455df862ab3ee44263a65981
7
+ data.tar.gz: 83944e43ffc7538068655d5dbf9385bb137e6a978e1307fb43285f574ddda510a705ce8ba64077bb6573cea67f0cae5a2b8e05e094df5793f518b52f6eec2762
@@ -50,8 +50,9 @@ module Preservation
50
50
  # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
51
51
  # @param [String] filepath - the path of the file relative to the moab content directory
52
52
  # @param [String] version - the version of the file requested (defaults to nil for latest version)
53
- def content(druid:, filepath:, version: nil)
54
- file(druid, 'content', filepath, version)
53
+ # @param [Proc] on_data a block, if provided is called to do streaming responses
54
+ def content(druid:, filepath:, version: nil, on_data: nil)
55
+ file(druid, 'content', filepath, version, on_data: on_data)
55
56
  end
56
57
 
57
58
  # retrieve a manifest file from a Moab object
@@ -83,10 +84,11 @@ module Preservation
83
84
  # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
84
85
  # @param [String] category - one of 'manifest', 'metadata' or 'content'
85
86
  # @param [String] filepath - the path of the file relative to the moab category directory
86
- # @param [String] version - the version of the file requested (defaults to nil for latest version)
87
+ # @param [String] version - the version of the file requested
88
+ # @param [Proc] on_data a block, if provided is called to do streaming responses
87
89
  # @return the retrieved file
88
- def file(druid, category, filepath, version = nil)
89
- get("objects/#{druid}/file", category: category, filepath: filepath, version: version)
90
+ def file(druid, category, filepath, version, on_data: nil)
91
+ get("objects/#{druid}/file", { category: category, filepath: filepath, version: version }, on_data: on_data)
90
92
  end
91
93
  end
92
94
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Preservation
4
4
  class Client
5
- VERSION = '3.1.0'
5
+ VERSION = '3.2.0'
6
6
  end
7
7
  end
@@ -15,7 +15,7 @@ module Preservation
15
15
 
16
16
  # @param path [String] path to be appended to connection url (no leading slash)
17
17
  def get_json(path, object_id)
18
- req_url = api_version.present? ? "#{api_version}/#{path}" : path
18
+ req_url = "#{api_version}/#{path}"
19
19
  resp = connection.get do |req|
20
20
  req.url req_url
21
21
  req.headers['Content-Type'] = 'application/json'
@@ -36,29 +36,52 @@ module Preservation
36
36
  end
37
37
 
38
38
  # @param path [String] path to be appended to connection url (no leading slash)
39
- # @param params [Hash] optional params
40
- def get(path, params)
41
- http_response(:get, path, params)
39
+ # @param params [Hash] optional request parameters
40
+ # @param on_data [Proc] a callback to use when a streaming response is desired.
41
+ def get(path, params, on_data:)
42
+ return http_response(:get, path, params) unless on_data
43
+
44
+ connection.get("#{api_version}/#{path}", params) do |req|
45
+ req.options.on_data = on_data
46
+ end
42
47
  end
43
48
 
44
49
  # @param path [String] path to be appended to connection url (no leading slash)
45
- # @param params [Hash] optional params
50
+ # @param params [Hash] optional request parameters
46
51
  def post(path, params)
47
52
  http_response(:post, path, params)
48
53
  end
49
54
 
50
- # @param method [Symbol] :get or :post
51
55
  # @param path [String] path to be appended to connection url (no leading slash)
52
- # @param params [Hash] optional params
56
+ # @param params [Hash] optional request parameters
57
+ def patch(path, params)
58
+ http_response(:patch, path, params)
59
+ end
60
+
61
+ # @param path [String] path to be appended to connection url (no leading slash)
62
+ # @param params [Hash] optional request parameters
63
+ def put(path, params)
64
+ http_response(:put, path, params)
65
+ end
66
+
67
+ # @param path [String] path to be appended to connection url (no leading slash)
68
+ # @param params [Hash] optional request parameters
69
+ def delete(path, params)
70
+ http_response(:delete, path, params)
71
+ end
72
+
73
+ # @param method [Symbol] a symbol representing an HTTP method: :get, :post, :patch, :put, :delete
74
+ # @param path [String] path to be appended to connection url (no leading slash)
75
+ # @param params [Hash] optional request parameters
53
76
  def http_response(method, path, params)
54
- req_url = api_version.present? ? "#{api_version}/#{path}" : path
77
+ req_url = "#{api_version}/#{path}"
55
78
  resp =
56
79
  case method
57
- when :get
58
- connection.get(req_url, params)
59
- when :post
80
+ when :delete, :get
81
+ connection.public_send(method, req_url, params)
82
+ when :patch, :post, :put
60
83
  request_json = params.to_json if params&.any?
61
- connection.post(req_url, request_json, 'Content-Type' => 'application/json')
84
+ connection.public_send(method, req_url, request_json, 'Content-Type' => 'application/json')
62
85
  end
63
86
  return resp.body if resp.success?
64
87
 
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_development_dependency 'bundler', '~> 2.0'
37
37
  spec.add_development_dependency 'pry-byebug'
38
- spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rake', '>= 12.3.3'
39
39
  spec.add_development_dependency 'rspec', '~> 3.0'
40
40
  spec.add_development_dependency 'rubocop', '~> 0.77.0'
41
41
  spec.add_development_dependency 'simplecov'
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: 3.1.0
4
+ version: 3.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: 2020-01-29 00:00:00.000000000 Z
11
+ date: 2020-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -110,16 +110,16 @@ dependencies:
110
110
  name: rake
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
- version: '10.0'
115
+ version: 12.3.3
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - "~>"
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: '10.0'
122
+ version: 12.3.3
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: rspec
125
125
  requirement: !ruby/object:Gem::Requirement
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
225
  - !ruby/object:Gem::Version
226
226
  version: '0'
227
227
  requirements: []
228
- rubygems_version: 3.1.2
228
+ rubygems_version: 3.0.3
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: A thin client for getting info from SDR preservation.