distributed-press-api-client 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/distributed_press/v1/client/admin.rb +1 -1
- data/lib/distributed_press/v1/client/auth.rb +1 -1
- data/lib/distributed_press/v1/client/publisher.rb +1 -1
- data/lib/distributed_press/v1/client/site.rb +13 -4
- data/lib/distributed_press/v1/client.rb +11 -6
- data/lib/distributed_press/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97a9c36acefc2ea476545820078749cba9d3a54c84e16ad179396193bbe4b9de
|
4
|
+
data.tar.gz: 6a20be7873ecaf8a11417511e493edf3cd041195cf55b7e4e785c9ae56e24c5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d66d0f0b879114c2feab58a353ebd508a88f79e3d5d3d4e9f6b7f16c44cad6bcb9fd9358526f72acbfe0a92fc46eed168ebc158a1a6b01c1f122b7aedd06d2c1
|
7
|
+
data.tar.gz: 66edfeaa772e4b4fe763e67792ee1d1b15431714ef9a9c6fbbdf5ebd40edbd07cd62e710b598b0a4aca65d2c43fab36c202acb3bacafe78be8a47fb3112dc4f8
|
@@ -35,7 +35,7 @@ class DistributedPress
|
|
35
35
|
|
36
36
|
raise TokenCapabilityMissingError, 'Only admins can revoke tokens' unless client.token.admin?
|
37
37
|
|
38
|
-
client.delete(endpoint: "/v1/auth/revoke/#{schema[:tokenId]}"
|
38
|
+
client.delete(endpoint: "/v1/auth/revoke/#{schema[:tokenId]}")
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -65,7 +65,9 @@ class DistributedPress
|
|
65
65
|
validate_capabilities!
|
66
66
|
responses = []
|
67
67
|
|
68
|
-
Open3.popen2('tar', '--to-stdout', '--create', '--gzip',
|
68
|
+
Open3.popen2('tar', '--to-stdout', '--create', '--gzip',
|
69
|
+
'--dereference', '--exclude="*.gz"',
|
70
|
+
'--exclude="*.br"', '--directory', path,
|
69
71
|
'.') do |_, stdout, thread|
|
70
72
|
stream, body = IO.pipe
|
71
73
|
multipart = Multipart.new
|
@@ -84,11 +86,18 @@ class DistributedPress
|
|
84
86
|
responses << thread.value
|
85
87
|
end
|
86
88
|
|
87
|
-
responses.all?
|
89
|
+
responses.all?(&:success?)
|
88
90
|
end
|
89
91
|
|
90
|
-
|
91
|
-
|
92
|
+
# Deletes a website
|
93
|
+
#
|
94
|
+
# @param schema [DistributedPress::V1::Schemas::Site]
|
95
|
+
# @return [Boolean]
|
96
|
+
def delete(schema)
|
97
|
+
validate_schema! schema
|
98
|
+
validate_capabilities!
|
99
|
+
|
100
|
+
client.delete(endpoint: "/v1/sites/#{schema[:id]}")
|
92
101
|
end
|
93
102
|
|
94
103
|
private
|
@@ -31,8 +31,11 @@ class DistributedPress
|
|
31
31
|
#
|
32
32
|
# @param url [String]
|
33
33
|
# @param token [String,Distributed::Press::V1::Token]
|
34
|
-
|
34
|
+
# @param logger [Logger]
|
35
|
+
def initialize(url: 'https://api.distributed.press', token: nil, logger: nil)
|
35
36
|
self.class.default_options[:base_uri] = @url = HTTParty.normalize_base_uri(url)
|
37
|
+
self.class.default_options[:logger] = logger if logger
|
38
|
+
self.class.default_options[:log_format] = :logstash
|
36
39
|
|
37
40
|
@token =
|
38
41
|
case token
|
@@ -73,13 +76,15 @@ class DistributedPress
|
|
73
76
|
# @param endpoint [String]
|
74
77
|
# @param io [IO]
|
75
78
|
# @param boundary [String]
|
79
|
+
# @param timeout [Integer]
|
76
80
|
# @return [Hash]
|
77
|
-
def put(endpoint:, io:, boundary:)
|
81
|
+
def put(endpoint:, io:, boundary:, timeout: 600)
|
78
82
|
multipart_headers = headers.dup
|
79
83
|
multipart_headers['Content-Type'] = "multipart/form-data; boundary=#{boundary}"
|
80
84
|
multipart_headers['Transfer-Encoding'] = 'chunked'
|
81
85
|
|
82
|
-
self.class.put(endpoint, body_stream: io, headers: multipart_headers
|
86
|
+
self.class.put(endpoint, body_stream: io, headers: multipart_headers, max_retries: 0,
|
87
|
+
timeout: timeout).tap do |response|
|
83
88
|
process_response_errors! endpoint, response
|
84
89
|
end
|
85
90
|
end
|
@@ -95,8 +100,8 @@ class DistributedPress
|
|
95
100
|
# @param endpoint [String]
|
96
101
|
# @param schema [Dry::Schema::Result]
|
97
102
|
# @return [Boolean]
|
98
|
-
def delete(endpoint
|
99
|
-
self.class.delete(endpoint,
|
103
|
+
def delete(endpoint:)
|
104
|
+
self.class.delete(endpoint, headers: headers).tap do |response|
|
100
105
|
process_response_errors! endpoint, response
|
101
106
|
end.ok?
|
102
107
|
end
|
@@ -133,7 +138,7 @@ class DistributedPress
|
|
133
138
|
# @param response [HTTParty::Response]
|
134
139
|
def process_response_errors!(endpoint, response)
|
135
140
|
raise TokenUnauthorizedError if response.unauthorized?
|
136
|
-
raise Error, "#{endpoint}: #{response.code} #{response.to_s.tr("\n",
|
141
|
+
raise Error, "#{endpoint}: #{response.code} #{response.to_s.tr("\n", '')}" unless response.ok?
|
137
142
|
end
|
138
143
|
end
|
139
144
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distributed-press-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|