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 +4 -4
- data/lib/purl_fetcher/client/direct_upload_request.rb +0 -2
- data/lib/purl_fetcher/client/legacy_publish.rb +48 -0
- data/lib/purl_fetcher/client/release_tags.rb +50 -0
- data/lib/purl_fetcher/client/unpublish.rb +40 -0
- data/lib/purl_fetcher/client/version.rb +1 -1
- data/lib/purl_fetcher/client.rb +20 -4
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5dc9b0fa9c56c53babf48c772a0c555f0dfc0eb76e1fb91bf62525388c10979
|
4
|
+
data.tar.gz: 1e18078edd5308c8306a285ea1205736e907ab0a035e621583e1c8527874fbd6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53b063bc3ce2b827df7386b520df3c86413edaa41a03dedd0a77a3f018eeb175600724e7ccb7244f59c99733e3a291e0e1da2489c79bfed683d0a18e54dbeefe
|
7
|
+
data.tar.gz: e8535af5122e38dc52ef7d239013f3b4214c32e3803a9417c37c1310a2d1c676705f95a0bec9bb89dcdcd849a33068c90bea1fafd2aeec31c17926862a5ba223
|
@@ -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
|
data/lib/purl_fetcher/client.rb
CHANGED
@@ -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
|
-
|
88
|
-
|
89
|
-
|
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
|
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-
|
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
|