distributed-press-api-client 0.4.0 → 0.4.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: 1a027ef2456449498ff03679402ac4a0f3689656cd5990e0aa9498b07e86beea
4
- data.tar.gz: 1117e426318b07a0bbb833713b6e15fd5c614490d4ff05d1c29cac4cbbb8fc1a
3
+ metadata.gz: 6a5f4b33d4222028ca00dfe7e4a3f9e0fd5a4e4c620068e8ae094df84e4d4a2c
4
+ data.tar.gz: ba21a56decb67357d65243ea5f7a12f92e705f689a2501fe3419921d6ffeea0f
5
5
  SHA512:
6
- metadata.gz: c462c24bd87a73557218beefe37b3194016ee1462fbd061155018b09c068fba019027512c17eee71c8096f83bd10a14a81aaca06d6597efa9218e615341f24de
7
- data.tar.gz: b9424cca5bf2d55085298e5205df63bfe6813b1a3874f3854c85a1cd9019a4207284468b5337081e2e73b7fbe7b9e8f6ceccc1e289d7a7a28fd856674ca5acb1
6
+ metadata.gz: 3a8f016d1fba233cf4e106b6f114fa82b34949af8b88cde9c252d4c33bb440c30c233eadee120205d4ff9c019327f44d9f9e4971abc8733c4e2c5856ec2a5986
7
+ data.tar.gz: 43019f74c34831fa3a9164db342e971307ab8c76e225445a7a95cf82f025e2496af8cfa0c1264fcd620ad2126f1066093280bbcfa5d113705c658247583c7aec
@@ -86,12 +86,12 @@ class DistributedPress
86
86
 
87
87
  def _dump(_)
88
88
  Marshal.dump({
89
- public_key_url: public_key_url,
90
- url: url,
91
- private_key_pem: @private_key_pem,
92
- key_size: key_size,
93
- cache_store: self.class.cache_store
94
- })
89
+ public_key_url: public_key_url,
90
+ url: url,
91
+ private_key_pem: @private_key_pem,
92
+ key_size: key_size,
93
+ cache_store: self.class.cache_store
94
+ })
95
95
  end
96
96
 
97
97
  def self._load(hash)
@@ -211,6 +211,14 @@ class DistributedPress
211
211
  end.perform do |fragment|
212
212
  fragment_to_body!(fragment, response_body)
213
213
  end.tap do |response|
214
+ # Brotli decompression is delayed until after full download
215
+ if response.headers['content-encoding'] == 'br'
216
+ ''.dup.tap do |inflated_response_body|
217
+ inflate_body!(response_body, inflated_response_body)
218
+ response_body = inflated_response_body
219
+ end
220
+ end
221
+
214
222
  next if response_body.empty?
215
223
 
216
224
  fix_response!(response, response_body)
@@ -275,16 +283,19 @@ class DistributedPress
275
283
  # tests, 2GB of zeroes were compressed to a 1.6KB fragment.
276
284
  #
277
285
  # @todo Maybe each_char is too slow?
278
- # @param fragment [HTTParty::ResponseFragment]
286
+ # @param body [String]
279
287
  # @param append_to [String]
280
- def inflate_fragment!(fragment, append_to)
281
- fragment_io = StringIO.new(fragment)
288
+ def inflate_body!(body, append_to)
289
+ body_io = StringIO.new(body)
282
290
 
283
- BRS::Stream::Reader.new(fragment_io, source_buffer_length: 256,
284
- destination_buffer_length: 1024).each_char do |char|
291
+ BRS::Stream::Reader.new(body_io, source_buffer_length: 256,
292
+ destination_buffer_length: 1024).each_char do |char|
285
293
  append_to << char
286
294
 
287
- raise ContentTooLargeError if append_to.bytesize > 1_000_000
295
+ if append_to.bytesize > 1_000_000
296
+ raise ContentTooLargeError,
297
+ "Content too large after inflating, stopped at #{append_to.bytesize} bytes!"
298
+ end
288
299
  end
289
300
  end
290
301
 
@@ -294,22 +305,16 @@ class DistributedPress
294
305
  # @param :fragment [HTTParty::ResponseFragment]
295
306
  # @param :append_to [String]
296
307
  def fragment_to_body!(fragment, append_to)
297
- case fragment.http_response['content-encoding']
298
- when 'br'
299
- # Raise an error rather than returning an empty body
300
- unless brotli?
301
- raise BrotliUnsupportedError,
302
- 'Server sent brotli-encoded response but ruby-brs gem is missing'
303
- end
304
-
305
- inflate_fragment!(fragment, append_to)
306
- else
307
- append_to << fragment
308
+ if fragment.http_response['content-encoding'] == 'br' && !brotli?
309
+ raise BrotliUnsupportedError, 'Server sent brotli-encoded response but ruby-brs gem is missing'
308
310
  end
309
311
 
310
- raise ContentTooLargeError if append_to.bytesize > 1_000_000
311
- rescue ContentTooLargeError
312
- raise ContentTooLargeError, "Content too large #{append_to.bytesize} bytes!"
312
+ append_to << fragment
313
+
314
+ return unless append_to.bytesize > 1_000_000
315
+
316
+ raise ContentTooLargeError,
317
+ "Content too large, stopped at #{append_to.bytesize} bytes!"
313
318
  end
314
319
 
315
320
  # Re-adds a streamed body to the response and caches it again so
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require_relative 'client'
5
+
6
+ class DistributedPress
7
+ module V1
8
+ module Social
9
+ # Manages the actor's followers on the Social Inbox
10
+ class Followers
11
+ # @return [DistributedPress::V1::Social::Client]
12
+ attr_reader :client
13
+
14
+ # @return [String]
15
+ attr_reader :actor
16
+
17
+ # @param :client [DistributedPress::V1::Social::Client]
18
+ # @param :actor [String]
19
+ def initialize(client:, actor:)
20
+ @client = client
21
+ @actor = actor
22
+ end
23
+
24
+ # Get the actor's inbox
25
+ #
26
+ # @return [HTTParty::Response]
27
+ def get
28
+ client.get(endpoint: endpoint)
29
+ end
30
+
31
+ #
32
+ #
33
+ # @param :id [String] Activity ID
34
+ # @return [HTTParty::Response]
35
+ def remove(id:)
36
+ client.delete(endpoint: "#{endpoint}/#{URI.encode_uri_component(id)}")
37
+ end
38
+
39
+ # Followers
40
+ #
41
+ # @return [String]
42
+ def endpoint
43
+ @endpoint ||= "/v1/#{actor}/followers"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -3,5 +3,5 @@
3
3
  # API client
4
4
  class DistributedPress
5
5
  # Version
6
- VERSION = '0.4.0'
6
+ VERSION = '0.4.1'
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-11 00:00:00.000000000 Z
11
+ date: 2024-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -311,6 +311,7 @@ files:
311
311
  - lib/distributed_press/v1/social/blocklist.rb
312
312
  - lib/distributed_press/v1/social/client.rb
313
313
  - lib/distributed_press/v1/social/dereferencer.rb
314
+ - lib/distributed_press/v1/social/followers.rb
314
315
  - lib/distributed_press/v1/social/hook.rb
315
316
  - lib/distributed_press/v1/social/inbox.rb
316
317
  - lib/distributed_press/v1/social/outbox.rb