purl_fetcher-client 2.0.0 → 2.1.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: 3a8e135cc1e6d731b5a6fbf1706b21764524f422fbe5935306d8c42355ac225a
4
- data.tar.gz: 617533e69ecaabe0ea954d3052a74197bbe78c14eb2e58921aa1c0d13dfd18af
3
+ metadata.gz: 8017e254342b99f9124349f201e4208be5f770266cea433a8dace94af780b880
4
+ data.tar.gz: 1ca31e0176e72973c32ceb02e0e44c29db4dab7a99b067eb7521a7e1ee6d70b1
5
5
  SHA512:
6
- metadata.gz: ceed9ffc1a6480273b180966c208a02b0e63eff3c1d1725c0b82a968900d1cc98573b734eebdfc4578709e4782d9e90130b79fca718ff9c8e5056913cda6e48d
7
- data.tar.gz: 0dc89a720e25f1e0c9f8330665ac3625463053e69717c27fa564876347f949aa9e95d9073c2131cb4eac039ca1d3dc91267edd232c7f3dfcacc02efafb02a042
6
+ metadata.gz: 026716e6518e2240863859fc6e7142eb3110d5fed36d951ee5232b1579697e0202ad2413bc0e92b85b86b3ca44bc36773a6dba447159f0e4a73ead3f1d648f0a
7
+ data.tar.gz: c3a4d72a5dbd0052190a719507ef5ea80082b2719d5f6eb1dc66e9f4884744f3967be904ddc0d26d49b93efd5210b4acb9445b9bf2450609195e2e4c443832ca
@@ -23,7 +23,7 @@ module PurlFetcher
23
23
 
24
24
  def publish
25
25
  logger.debug("Starting a publish request for: #{druid}")
26
- client.post(path:, body:)
26
+ client.put(path:, body:)
27
27
  logger.debug("Publish request complete")
28
28
  end
29
29
 
@@ -54,7 +54,7 @@ module PurlFetcher
54
54
  end
55
55
 
56
56
  def path
57
- "/v1/resources"
57
+ "/v1/purls/#{druid}"
58
58
  end
59
59
  end
60
60
  end
@@ -25,7 +25,7 @@ class PurlFetcher::Client::Reader
25
25
  # @raise [PurlFetcher::Client::NotFoundResponseError] if item is not found
26
26
  # @raise [PurlFetcher::Client::ResponseError] if the response is not successful
27
27
  def files_by_digest(druid)
28
- retrieve_json("/purls/druid:#{druid.delete_prefix('druid:')}", {})
28
+ retrieve_json("/v1/purls/druid:#{druid.delete_prefix('druid:')}", {})
29
29
  .fetch("files_by_md5", [])
30
30
  end
31
31
 
@@ -43,7 +43,7 @@ module PurlFetcher
43
43
  end
44
44
 
45
45
  def path
46
- "/v1/released/#{druid}"
46
+ "/v1/purls/#{druid}/release_tags"
47
47
  end
48
48
  end
49
49
  end
@@ -38,7 +38,7 @@ module PurlFetcher
38
38
  end
39
39
 
40
40
  def path
41
- "/purls/#{druid}"
41
+ "/v1/purls/#{druid}"
42
42
  end
43
43
  end
44
44
  end
@@ -1,5 +1,5 @@
1
1
  module PurlFetcher
2
2
  class Client
3
- VERSION = "2.0.0"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PurlFetcher
4
+ class Client
5
+ # Withdraw / restore a version of an item from the purl-fetcher cache
6
+ class Withdraw
7
+ # @param [String] druid the identifier of the item
8
+ # @param [String] version the version of the item
9
+ def self.withdraw(druid:, version:)
10
+ new(druid:, version:).withdraw
11
+ end
12
+
13
+ # @param [String] druid the identifier of the item
14
+ # @param [String] version the version of the item
15
+ def self.restore(druid:, version:)
16
+ new(druid:, version:).restore
17
+ end
18
+
19
+ # @param [String] druid the identifier of the item
20
+ # @param [String] version the version of the item
21
+ def initialize(druid:, version:)
22
+ @druid = druid
23
+ @version = version
24
+ end
25
+
26
+ def withdraw
27
+ logger.debug("Starting a withdraw request for: #{druid} (#{version})")
28
+ response = client.put(path: path(:withdraw))
29
+ logger.debug("Withdraw request complete")
30
+ response
31
+ end
32
+
33
+ def restore
34
+ logger.debug("Starting a restore request for: #{druid} (#{version})")
35
+ response = client.put(path: path(:restore))
36
+ logger.debug("Withdraw request complete")
37
+ response
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :druid, :version
43
+
44
+ def logger
45
+ Client.config.logger
46
+ end
47
+
48
+ def client
49
+ Client.instance
50
+ end
51
+
52
+ def path(action)
53
+ "/v1/purls/#{druid}/versions/#{version}/#{action}"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -7,10 +7,10 @@ require "logger"
7
7
  require "purl_fetcher/client/version"
8
8
  require "purl_fetcher/client/reader"
9
9
  require "purl_fetcher/client/mods"
10
- require "purl_fetcher/client/legacy_publish"
11
10
  require "purl_fetcher/client/publish"
12
11
  require "purl_fetcher/client/release_tags"
13
12
  require "purl_fetcher/client/unpublish"
13
+ require "purl_fetcher/client/withdraw"
14
14
 
15
15
  module PurlFetcher
16
16
  class Client
@@ -76,9 +76,9 @@ module PurlFetcher
76
76
  # @param path [String] the path for the API request
77
77
  # @param body [String] the body of the POST request
78
78
  # @param headers [Hash] extra headers to add to the SDR API request
79
- def put(path:, body:, headers: {})
79
+ def put(path:, body: nil, headers: {})
80
80
  response = connection.put(path) do |request|
81
- request.body = body
81
+ request.body = body if body
82
82
  request.headers = default_headers.merge(headers)
83
83
  end
84
84
 
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: 2.0.0
4
+ version: 2.1.0
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-07-23 00:00:00.000000000 Z
11
+ date: 2024-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -126,13 +126,13 @@ files:
126
126
  - bin/console
127
127
  - bin/setup
128
128
  - lib/purl_fetcher/client.rb
129
- - lib/purl_fetcher/client/legacy_publish.rb
130
129
  - lib/purl_fetcher/client/mods.rb
131
130
  - lib/purl_fetcher/client/publish.rb
132
131
  - lib/purl_fetcher/client/reader.rb
133
132
  - lib/purl_fetcher/client/release_tags.rb
134
133
  - lib/purl_fetcher/client/unpublish.rb
135
134
  - lib/purl_fetcher/client/version.rb
135
+ - lib/purl_fetcher/client/withdraw.rb
136
136
  - purl_fetcher-client.gemspec
137
137
  homepage:
138
138
  licenses: []
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PurlFetcher
4
- class Client
5
- # Publish (metadata-only). This will be replaced with a single publish operation
6
- class LegacyPublish
7
- # @param [Cocina::Models::DRO,Cocina::Models::Collection] cocina the Cocina data object
8
- def self.publish(cocina:)
9
- new(cocina:).publish
10
- end
11
-
12
- # @param [Cocina::Models::DRO,Cocina::Models::Collection] cocina the Cocina data object
13
- def initialize(cocina:)
14
- @cocina = cocina
15
- end
16
-
17
- def publish
18
- logger.debug("Starting a legacy publish request for: #{druid}")
19
- response = client.post(path:, body:)
20
- logger.debug("Legacy publish request complete")
21
- end
22
-
23
- private
24
-
25
- attr_reader :cocina
26
-
27
- def druid
28
- cocina.externalIdentifier
29
- end
30
-
31
- def body
32
- cocina.to_json
33
- end
34
-
35
- def logger
36
- Client.config.logger
37
- end
38
-
39
- def client
40
- Client.instance
41
- end
42
-
43
- def path
44
- "/purls/#{druid}"
45
- end
46
- end
47
- end
48
- end