distributed-press-api-client 0.5.0rc7 → 0.5.0rc9
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/social/client.rb +1 -1
- data/lib/distributed_press/v1/social/collection.rb +33 -6
- data/lib/distributed_press/v1/social/dereferencer.rb +3 -3
- data/lib/distributed_press/v1/social/hook.rb +1 -1
- data/lib/distributed_press/v1/social/inbox.rb +3 -3
- data/lib/distributed_press/v1/social/reference.rb +4 -2
- data/lib/distributed_press/v1/social/referenced_object.rb +47 -28
- data/lib/distributed_press/v1/social/replies.rb +2 -2
- 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: 35ce06825d1ddabae961e86d8bdd698c5554f0e75a0dd74cc91741f508b23a2e
|
4
|
+
data.tar.gz: 74864dd3aaf4ac30d7a3a4cbba91ffe0c7d33dda6881a706e3bdef73682732ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a66393b7fd19dba0355757c0590e2334671db099892d7ffa36471053fc07402247c74ab72f26681d2cc006beba68f5ed8d1eceab3c3d793308427d57e00cd863
|
7
|
+
data.tar.gz: 2e6c050daa4c9fc9f5192be716f1bf733c221b4020ded3e1ce637ef59e02a8f8020888f539d348f9e69a412dfc1819d330d0beb1ce21535725e7d67146371cd5
|
@@ -231,7 +231,7 @@ class DistributedPress
|
|
231
231
|
# after the request is instantiated. No need to process
|
232
232
|
# cookies for now. Uses the public key URL as a caching key so
|
233
233
|
# we revalidate access on shared caches.
|
234
|
-
options = { body: body, headers: headers, base_uri: url, parser: parser, stream_body: true }
|
234
|
+
options = { body: body, headers: headers, base_uri: url, parser: parser, stream_body: true, timeout: 5 }
|
235
235
|
options = HTTParty::ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(options)
|
236
236
|
response_body = ''.dup
|
237
237
|
|
@@ -11,20 +11,47 @@ class DistributedPress
|
|
11
11
|
class Collection < ReferencedObject
|
12
12
|
include Enumerable
|
13
13
|
|
14
|
-
|
14
|
+
ATTRIBUTES = %w[items orderedItems].freeze
|
15
|
+
RECURSIVE_ATTRIBUTES = %w[first next].freeze
|
15
16
|
|
16
17
|
# If the Collection has items, yield them and keep processing
|
17
18
|
# any pages forward until the end.
|
18
19
|
#
|
19
|
-
# @todo Use totalItems from the starting object for validation
|
20
20
|
# @todo Implement lazy loading
|
21
21
|
def each(&block)
|
22
|
+
counter = 0
|
23
|
+
total_items = object['totalItems']
|
24
|
+
|
22
25
|
Enumerator.new do |enum|
|
23
|
-
|
24
|
-
|
26
|
+
catch :total_items_reached do
|
27
|
+
ATTRIBUTES.each do |attribute|
|
28
|
+
next unless object.key?(attribute)
|
29
|
+
|
30
|
+
referenced[attribute].each(&block).each do |item|
|
31
|
+
counter += 1
|
32
|
+
|
33
|
+
enum << item
|
34
|
+
|
35
|
+
if total_items
|
36
|
+
throw :total_items_reached if total_items == counter
|
37
|
+
throw :total_items_reached if counter > 1000
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
RECURSIVE_ATTRIBUTES.each do |attribute|
|
43
|
+
next unless object.key?(attribute)
|
44
|
+
throw :total_items_reached if object['id'] && object['id'] == referenced[attribute]['id']
|
45
|
+
|
46
|
+
referenced[attribute].each(&block).each do |item|
|
47
|
+
counter += 1
|
48
|
+
enum << item
|
25
49
|
|
26
|
-
|
27
|
-
|
50
|
+
if total_items
|
51
|
+
throw :total_items_reached if total_items == counter
|
52
|
+
throw :total_items_reached if counter > 1000
|
53
|
+
end
|
54
|
+
end
|
28
55
|
end
|
29
56
|
end
|
30
57
|
end
|
@@ -29,8 +29,8 @@ class DistributedPress
|
|
29
29
|
# @todo Replace with a class
|
30
30
|
@parser =
|
31
31
|
proc do |body, format|
|
32
|
-
next HTTParty::Parser.call(body, :html) if body&.
|
33
|
-
next HTTParty::Parser.call(body, format || :plain) unless body&.
|
32
|
+
next HTTParty::Parser.call(body, :html) if body&.start_with? '<'
|
33
|
+
next HTTParty::Parser.call(body, format || :plain) unless body&.start_with? '{'
|
34
34
|
|
35
35
|
object = HTTParty::Parser.call(body, :json)
|
36
36
|
|
@@ -56,7 +56,7 @@ class DistributedPress
|
|
56
56
|
loop do
|
57
57
|
uri = uris(uri)
|
58
58
|
client = clients(uri)
|
59
|
-
response = client.get(endpoint: uri.
|
59
|
+
response = client.get(endpoint: uri.request_uri, parser: @parser)
|
60
60
|
|
61
61
|
# Break the loop if the request failed
|
62
62
|
break unless response.success?
|
@@ -43,7 +43,7 @@ class DistributedPress
|
|
43
43
|
|
44
44
|
# XXX: format is nil but should be :json
|
45
45
|
@parser = proc do |body, format|
|
46
|
-
next HTTParty::Parser.call(body, format || :plain) unless body.
|
46
|
+
next HTTParty::Parser.call(body, format || :plain) unless body.start_with? '{'
|
47
47
|
|
48
48
|
json = HTTParty::Parser.call(body, :json)
|
49
49
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'base64'
|
4
4
|
require_relative 'client'
|
5
5
|
|
6
6
|
class DistributedPress
|
@@ -64,7 +64,7 @@ class DistributedPress
|
|
64
64
|
# @param :id [String] Activity ID
|
65
65
|
# @return [HTTParty::Response]
|
66
66
|
def reject(id:)
|
67
|
-
client.delete(endpoint: "#{endpoint}/#{
|
67
|
+
client.delete(endpoint: "#{endpoint}/#{Base64.encode64(id).delete("\n")}")
|
68
68
|
end
|
69
69
|
|
70
70
|
# Accept an activity queued on the inbox
|
@@ -72,7 +72,7 @@ class DistributedPress
|
|
72
72
|
# @param :id [String] Activity ID
|
73
73
|
# @return [HTTParty::Response]
|
74
74
|
def accept(id:)
|
75
|
-
client.post(endpoint: "#{endpoint}/#{
|
75
|
+
client.post(endpoint: "#{endpoint}/#{Base64.encode64(id).delete("\n")}", body: {})
|
76
76
|
end
|
77
77
|
|
78
78
|
# Inbox
|
@@ -21,7 +21,9 @@ class DistributedPress
|
|
21
21
|
|
22
22
|
# @param :uri [String]
|
23
23
|
# @param :dereferencer [DistributedPress::V1::Social::Dereferencer]
|
24
|
-
|
24
|
+
# @param :object [ReferencedObject,nil]
|
25
|
+
def initialize(uri:, dereferencer:, object: nil)
|
26
|
+
@object = object
|
25
27
|
@uri = uri
|
26
28
|
@dereferencer = dereferencer
|
27
29
|
end
|
@@ -58,7 +60,7 @@ class DistributedPress
|
|
58
60
|
"#{self.class.name}(#{uri})"
|
59
61
|
end
|
60
62
|
|
61
|
-
def_delegators :object, :[], :dig, :to_h, :to_json, :slice, :key?, :keys
|
63
|
+
def_delegators :object, :[], :dig, :to_h, :to_json, :slice, :key?, :keys, :each
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
@@ -9,6 +9,8 @@ class DistributedPress
|
|
9
9
|
class ReferencedObject
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
+
# Mastodon hides self-replies
|
13
|
+
URI_FIXES = %r{&?only_other_accounts=true&?}
|
12
14
|
REFERENTIABLE_ATTRIBUTES =
|
13
15
|
%w[
|
14
16
|
actor
|
@@ -46,11 +48,10 @@ class DistributedPress
|
|
46
48
|
|
47
49
|
def_delegators :referenced, :[], :dig, :to_h, :to_json, :keys, :key?
|
48
50
|
|
49
|
-
def initialize(object:, dereferencer:)
|
51
|
+
def initialize(object:, dereferencer:, referenced: nil)
|
50
52
|
@object = object
|
51
53
|
@dereferencer = dereferencer
|
52
|
-
@referenced =
|
53
|
-
reference_object! referenced
|
54
|
+
@referenced = referenced || reference_object(object)
|
54
55
|
end
|
55
56
|
|
56
57
|
def _dump(_)
|
@@ -63,36 +64,54 @@ class DistributedPress
|
|
63
64
|
new(object: object, dereferencer: dereferencer)
|
64
65
|
end
|
65
66
|
|
67
|
+
def success?
|
68
|
+
true
|
69
|
+
end
|
70
|
+
|
71
|
+
def parsed_response
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
66
75
|
private
|
67
76
|
|
68
|
-
def reference_object
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
def reference_object(object)
|
78
|
+
case object
|
79
|
+
when Array
|
80
|
+
object.map do |sub_object|
|
81
|
+
reference_object sub_object
|
82
|
+
end
|
83
|
+
when Hash
|
84
|
+
new_object = object.dup
|
85
|
+
|
86
|
+
new_object.each_key do |attribute|
|
87
|
+
next unless REFERENTIABLE_ATTRIBUTES.include? attribute
|
88
|
+
|
89
|
+
new_object[attribute] = reference_object object[attribute]
|
90
|
+
end
|
91
|
+
|
92
|
+
# XXX: Embedded objects may not have an ID, but they do have
|
93
|
+
# a type.
|
94
|
+
if new_object['type']
|
95
|
+
new_object =
|
96
|
+
case new_object['type']
|
97
|
+
when 'Collection', 'OrderedCollection', 'CollectionPage', 'OrderedCollectionPage'
|
98
|
+
Collection.new(object: object, referenced: new_object, dereferencer: self)
|
85
99
|
else
|
86
|
-
|
100
|
+
ReferencedObject.new(object: object, referenced: new_object, dereferencer: self)
|
87
101
|
end
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
102
|
+
|
103
|
+
Reference.new(dereferencer: dereferencer, object: new_object, uri: new_object['id'])
|
104
|
+
else
|
105
|
+
new_object
|
106
|
+
end
|
107
|
+
when String
|
108
|
+
if object == DistributedPress::V1::Social::Reference::PUBLIC
|
109
|
+
object
|
110
|
+
else
|
111
|
+
dereferencer.references(dereferencer.uris(object.sub(URI_FIXES, '')))
|
95
112
|
end
|
113
|
+
else
|
114
|
+
object
|
96
115
|
end
|
97
116
|
end
|
98
117
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'base64'
|
4
4
|
require_relative 'client'
|
5
5
|
|
6
6
|
class DistributedPress
|
@@ -38,7 +38,7 @@ class DistributedPress
|
|
38
38
|
#
|
39
39
|
# @return [String]
|
40
40
|
def endpoint
|
41
|
-
@endpoint ||= "/v1/#{actor}/inbox/replies/#{
|
41
|
+
@endpoint ||= "/v1/#{actor}/inbox/replies/#{Base64.encode64(activity).delete("\n")}"
|
42
42
|
end
|
43
43
|
end
|
44
44
|
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.5.
|
4
|
+
version: 0.5.0rc9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|