purl_fetcher-client 1.1.0 → 1.2.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: cb1a08fc0010f80045db352cb2bfb2735dd2b7447513ba366281cc4d488895e4
4
- data.tar.gz: a2213eda4272694dcf1e889ed9185956b0ba1da24e98056e2360a242e9eb6a0b
3
+ metadata.gz: a5dc9b0fa9c56c53babf48c772a0c555f0dfc0eb76e1fb91bf62525388c10979
4
+ data.tar.gz: 1e18078edd5308c8306a285ea1205736e907ab0a035e621583e1c8527874fbd6
5
5
  SHA512:
6
- metadata.gz: f8a0200ff798158ca1b5c58c120c94b1cb3e8f172cec1c28b30b1a1cae47291483dc5d681467a17f08d7ef650a14bf9fffc0c8d33895fd36565e2b2ea7e70ac9
7
- data.tar.gz: 4600d53676d35892f3485f9cbc280afb4cc1fd8cedd9028794376cb20b9a49ad6d3981279e84e89b56549b87173fdc106aaa09f459d1d461a72675b2c2c2ca12
6
+ metadata.gz: 53b063bc3ce2b827df7386b520df3c86413edaa41a03dedd0a77a3f018eeb175600724e7ccb7244f59c99733e3a291e0e1da2489c79bfed683d0a18e54dbeefe
7
+ data.tar.gz: e8535af5122e38dc52ef7d239013f3b4214c32e3803a9417c37c1310a2d1c676705f95a0bec9bb89dcdcd849a33068c90bea1fafd2aeec31c17926862a5ba223
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "digest"
4
-
5
3
  module PurlFetcher
6
4
  class Client
7
5
  # This models the JSON that we send to the server.
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PurlFetcher
4
+ class Client
5
+ # Transfer release tags to purl-fetcher
6
+ class ReleaseTags
7
+ # @param [String] druid the identifier of the object
8
+ # @param [Array<String>] index ([]) list of properties to index to
9
+ # @param [Array<String>] delete ([]) list of properties to delete from
10
+ def self.release(druid:, index: [], delete: [])
11
+ new(druid:, index:, delete:).release
12
+ end
13
+
14
+ # @param [String] druid the identifier of the object
15
+ # @param [Array<String>] index ([]) list of properties to index to
16
+ # @param [Array<String>] delete ([]) list of properties to delete from
17
+ def initialize(druid:, index: [], delete: [])
18
+ @druid = druid
19
+ @index = index
20
+ @delete = delete
21
+ end
22
+
23
+ def release
24
+ logger.debug("Starting an release request for: #{druid}")
25
+ response = client.put(path:, body:)
26
+ logger.debug("Release request complete")
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :druid, :index, :delete
32
+
33
+ def body
34
+ { index:, delete: }.to_json
35
+ end
36
+
37
+ def logger
38
+ Client.config.logger
39
+ end
40
+
41
+ def client
42
+ Client.instance
43
+ end
44
+
45
+ def path
46
+ "/v1/released/#{druid}"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PurlFetcher
4
+ class Client
5
+ # Delete an item from the purl-fetcher cache
6
+ class Unpublish
7
+ # @param [String] druid the identifier of the item
8
+ def self.unpublish(druid:)
9
+ new(druid:).unpublish
10
+ end
11
+
12
+ # @param [String] druid the identifier of the item
13
+ def initialize(druid:)
14
+ @druid = druid
15
+ end
16
+
17
+ def unpublish
18
+ logger.debug("Starting a unpublish request for: #{druid}")
19
+ response = client.delete(path:)
20
+ logger.debug("Unpublish request complete")
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :druid
26
+
27
+ def logger
28
+ Client.config.logger
29
+ end
30
+
31
+ def client
32
+ Client.instance
33
+ end
34
+
35
+ def path
36
+ "/purls/#{druid}"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  module PurlFetcher
2
2
  class Client
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.1"
4
4
  end
5
5
  end
@@ -9,6 +9,9 @@ require "purl_fetcher/client/reader"
9
9
  require "purl_fetcher/client/upload_files"
10
10
  require "purl_fetcher/client/direct_upload_request"
11
11
  require "purl_fetcher/client/direct_upload_response"
12
+ require "purl_fetcher/client/legacy_publish"
13
+ require "purl_fetcher/client/release_tags"
14
+ require "purl_fetcher/client/unpublish"
12
15
 
13
16
  module PurlFetcher
14
17
  class Client
@@ -39,6 +42,16 @@ module PurlFetcher
39
42
 
40
43
  attr_accessor :config
41
44
 
45
+ # Send an DELETE request
46
+ # @param path [String] the path for the API request
47
+ def delete(path:)
48
+ response = connection.delete(path)
49
+
50
+ raise "unexpected response: #{response.status} #{response.body}" unless response.success?
51
+
52
+ response.body
53
+ end
54
+
42
55
  # Send an POST request
43
56
  # @param path [String] the path for the API request
44
57
  # @param body [String] the body of the POST request
@@ -83,10 +96,13 @@ module PurlFetcher
83
96
  def default_headers
84
97
  {
85
98
  accept: "application/json",
86
- content_type: "application/json"
87
- }.tap do |headers|
88
- headers[:authorization] = "Bearer #{config.token}" if config.token
89
- end
99
+ content_type: "application/json",
100
+ authorization: auth_header
101
+ }.compact
102
+ end
103
+
104
+ def auth_header
105
+ "Bearer #{config.token}" if config.token
90
106
  end
91
107
  end
92
108
  end
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.1.0
4
+ version: 1.2.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-02 00:00:00.000000000 Z
11
+ date: 2024-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -128,7 +128,10 @@ files:
128
128
  - lib/purl_fetcher/client.rb
129
129
  - lib/purl_fetcher/client/direct_upload_request.rb
130
130
  - lib/purl_fetcher/client/direct_upload_response.rb
131
+ - lib/purl_fetcher/client/legacy_publish.rb
131
132
  - lib/purl_fetcher/client/reader.rb
133
+ - lib/purl_fetcher/client/release_tags.rb
134
+ - lib/purl_fetcher/client/unpublish.rb
132
135
  - lib/purl_fetcher/client/upload_files.rb
133
136
  - lib/purl_fetcher/client/version.rb
134
137
  - purl_fetcher-client.gemspec