purl_fetcher-client 1.4.1 → 1.5.1

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: 027601e72f94ac6befda0395719b6d334221fce396e2c6ef306c7ec012e19609
4
- data.tar.gz: f77c4469ee2f67e340db177d092844011619725aa28681e3ef074b362532715e
3
+ metadata.gz: 123f98e808fb6578e4f194d380d4d1d651735dbe8c5114b40b4d2348eb729a8c
4
+ data.tar.gz: 66996f257ec6210d4bd822335b3511e9877122e6203f6818e7ed4b9284a53c6a
5
5
  SHA512:
6
- metadata.gz: 2b704e9fac0330914822891a6ddd73034b7100eb11653cd506699569d341eefda56613949a64fffd4616bbfc7b63404ff529ef386228c02c54887e7316dc12e9
7
- data.tar.gz: 43eabc9ce42dcdc937cacac235550bdb396096cce0caeedf8134976b0c50aaf8848065da739aa6afec8a6c0d3d83a96a9f182e6538c246820c74c158129d4ee3
6
+ metadata.gz: 0a51f4a44b7b7b1bb070a7aa7f9dbe4faf8281eb5d4dd1448990104659f3ecce3ac7ce30d81aa6144579b1a801fd73a6b55bd9a7f075377e6070b2f5aa5c274b
7
+ data.tar.gz: 919bb94098bdec558dfec580bce657af55879eee46abdbedb441520f27f29557f4f583d1da8ac2446ee346f2937df80e2d980f934566bcaee973a792622f0386
@@ -1,5 +1,6 @@
1
1
  class PurlFetcher::Client::Reader
2
2
  include Enumerable
3
+
3
4
  attr_reader :host, :conn, :range
4
5
 
5
6
  def initialize(host: "https://purl-fetcher.stanford.edu", conn: nil)
@@ -10,6 +11,8 @@ class PurlFetcher::Client::Reader
10
11
  @range = {}
11
12
  end
12
13
 
14
+ # @raise [PurlFetcher::Client::NotFoundResponseError] if item is not found
15
+ # @raise [PurlFetcher::Client::ResponseError] if the response is not successful
13
16
  def collection_members(druid)
14
17
  return to_enum(:collection_members, druid) unless block_given?
15
18
 
@@ -18,17 +21,26 @@ class PurlFetcher::Client::Reader
18
21
  end
19
22
  end
20
23
 
24
+ # @return [Array<Hash<String,String>>] a list of hashes where the key is a digest and the value is a filepath/filename
25
+ # @raise [PurlFetcher::Client::NotFoundResponseError] if item is not found
26
+ # @raise [PurlFetcher::Client::ResponseError] if the response is not successful
27
+ def files_by_digest(druid)
28
+ retrieve_json("/purls/druid:#{druid.delete_prefix('druid:')}", {})
29
+ .fetch("files_by_md5", [])
30
+ end
31
+
21
32
  private
22
33
 
23
34
  ##
24
35
  # @return [Hash] a parsed JSON hash
25
- def fetch(path, params)
36
+ def retrieve_json(path, params)
26
37
  response = conn.get(path, params: params)
27
38
 
28
39
  unless response.success?
29
40
  if defined?(Honeybadger)
30
41
  Honeybadger.context({ path:, params:, response_code: response.code, body: response.body })
31
42
  end
43
+ raise PurlFetcher::Client::NotFoundResponseError, "Item not found" if response.status == 404
32
44
  raise PurlFetcher::Client::ResponseError, "Unsuccessful response from purl-fetcher"
33
45
  end
34
46
 
@@ -54,7 +66,7 @@ class PurlFetcher::Client::Reader
54
66
  total = 0
55
67
 
56
68
  loop do
57
- data = fetch(path, { per_page: per_page, page: page }.merge(params))
69
+ data = retrieve_json(path, { per_page: per_page, page: page }.merge(params))
58
70
  @range = data["range"]
59
71
 
60
72
  total += data[accessor].length
@@ -1,5 +1,5 @@
1
1
  module PurlFetcher
2
2
  class Client
3
- VERSION = "1.4.1"
3
+ VERSION = "1.5.1"
4
4
  end
5
5
  end
@@ -24,6 +24,9 @@ module PurlFetcher
24
24
  # Raised when the response from the server is not successful
25
25
  class ResponseError < Error; end
26
26
 
27
+ # Raised when the response from the server indicates that the requested item is not found
28
+ class NotFoundResponseError < ResponseError; end
29
+
27
30
  include Singleton
28
31
  class << self
29
32
  def configure(url:, logger: default_logger, token: nil)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purl_fetcher-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-30 00:00:00.000000000 Z
11
+ date: 2024-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport