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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 836e345691ad1ed5a6899ebc8bcfcb638e5b2d8fddfb6f947c84c2bd94f155b0
4
- data.tar.gz: efe7d11dac7c925d328c0be16185e24a095be59ec11eedb223a30dfb9142f77c
3
+ metadata.gz: 97a9c36acefc2ea476545820078749cba9d3a54c84e16ad179396193bbe4b9de
4
+ data.tar.gz: 6a20be7873ecaf8a11417511e493edf3cd041195cf55b7e4e785c9ae56e24c5a
5
5
  SHA512:
6
- metadata.gz: 10d33a9cc5f31928b07917a7db36bbdc21bfc3eb33f984eaa76aa760614fcdd6b929c8b0061e25388c691889ec187459a607f26ca75727a865fbab65857c6eb1
7
- data.tar.gz: ad57ee2402ac1bcbb0359b14206d8fde897f9d66daa944b089ad8b80a6a5e5d46adf91244e259219a58ce419d958d516835bd266bdb00baa16656f38097524d7
6
+ metadata.gz: d66d0f0b879114c2feab58a353ebd508a88f79e3d5d3d4e9f6b7f16c44cad6bcb9fd9358526f72acbfe0a92fc46eed168ebc158a1a6b01c1f122b7aedd06d2c1
7
+ data.tar.gz: 66edfeaa772e4b4fe763e67792ee1d1b15431714ef9a9c6fbbdf5ebd40edbd07cd62e710b598b0a4aca65d2c43fab36c202acb3bacafe78be8a47fb3112dc4f8
@@ -33,7 +33,7 @@ class DistributedPress
33
33
  validate_schema! schema
34
34
  validate_capabilities!
35
35
 
36
- client.delete(endpoint: "/v1/admin/#{schema[:id]}", schema: schema)
36
+ client.delete(endpoint: "/v1/admin/#{schema[:id]}")
37
37
  end
38
38
 
39
39
  private
@@ -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]}", schema: schema)
38
+ client.delete(endpoint: "/v1/auth/revoke/#{schema[:tokenId]}")
39
39
  end
40
40
 
41
41
  private
@@ -36,7 +36,7 @@ class DistributedPress
36
36
  validate_schema! schema
37
37
  validate_capabilities!
38
38
 
39
- client.delete(endpoint: "/v1/publisher/#{schema[:id]}", schema: schema)
39
+ client.delete(endpoint: "/v1/publisher/#{schema[:id]}")
40
40
  end
41
41
 
42
42
  private
@@ -65,7 +65,9 @@ class DistributedPress
65
65
  validate_capabilities!
66
66
  responses = []
67
67
 
68
- Open3.popen2('tar', '--to-stdout', '--create', '--gzip', '--dereference', '--directory', path,
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? &:success?
89
+ responses.all?(&:success?)
88
90
  end
89
91
 
90
- def delete
91
- raise NotImplementedError
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
- def initialize(url: 'https://api.distributed.press', token: nil)
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).tap do |response|
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:, schema:)
99
- self.class.delete(endpoint, body: schema.to_h.to_json, headers: headers).tap do |response|
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", "")}" unless response.ok?
141
+ raise Error, "#{endpoint}: #{response.code} #{response.to_s.tr("\n", '')}" unless response.ok?
137
142
  end
138
143
  end
139
144
  end
@@ -3,5 +3,5 @@
3
3
  # API client
4
4
  class DistributedPress
5
5
  # Version
6
- VERSION = '0.2.1'
6
+ VERSION = '0.2.3'
7
7
  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.1
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-02-08 00:00:00.000000000 Z
11
+ date: 2023-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable