distributed-press-api-client 0.5.1 → 0.5.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
- checksums.yaml.gz.sig +0 -0
- data/lib/distributed_press/v1/social/client.rb +3 -1
- data/lib/distributed_press/v1/social/dereferencer.rb +9 -1
- data/lib/distributed_press/v1/social/likes.rb +10 -1
- data/lib/distributed_press/v1/social/reference.rb +1 -22
- data/lib/distributed_press/v1/social/referenced_object.rb +31 -2
- data/lib/distributed_press/v1/social/replies.rb +10 -1
- data/lib/distributed_press/v1/social/shares.rb +10 -1
- data/lib/distributed_press/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +31 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7e4e49cb1103910b9773a20abf64bbba998ffc605c5746b0302e90f99728eea
|
4
|
+
data.tar.gz: 014f38dadfe6efcff991a8793a290e79460043cc6c6b3d8c97181d868feb59c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e15b956699327db35b73b0af172ed3970c2d26bb82e2993057c253526242a735043c636e63d0938f9237679a5076b6b7342624bf6da432bd9771776f75c448c2
|
7
|
+
data.tar.gz: 8769c84484390019b825f40eabd3e8d967aef69efae982758e04390a0659daa209823a9206d794cbfe3394f2f81589aea2c50ae5878cf63ad86ed85f3a70df6a
|
checksums.yaml.gz.sig
ADDED
Binary file
|
@@ -35,6 +35,8 @@ class DistributedPress
|
|
35
35
|
class Error < StandardError; end
|
36
36
|
class ContentTooLargeError < Error; end
|
37
37
|
class BrotliUnsupportedError < Error; end
|
38
|
+
class ActivityIdTooLargeError < Error; end
|
39
|
+
class EmptyResponseError < Error; end
|
38
40
|
|
39
41
|
# Always cache
|
40
42
|
caching true
|
@@ -231,7 +233,7 @@ class DistributedPress
|
|
231
233
|
# after the request is instantiated. No need to process
|
232
234
|
# cookies for now. Uses the public key URL as a caching key so
|
233
235
|
# we revalidate access on shared caches.
|
234
|
-
options = { body: body, headers: headers, base_uri: url, parser: parser, stream_body: true, timeout:
|
236
|
+
options = { body: body, headers: headers, base_uri: url, parser: parser, stream_body: true, timeout: 20 }
|
235
237
|
options = HTTParty::ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(options)
|
236
238
|
response_body = ''.dup
|
237
239
|
|
@@ -51,9 +51,13 @@ class DistributedPress
|
|
51
51
|
# @param :uri [String, Addressable::URI]
|
52
52
|
# @return [HTTParty::Response]
|
53
53
|
def get(uri:)
|
54
|
+
original_uri = uri
|
54
55
|
response = nil
|
56
|
+
counter = 0
|
55
57
|
|
56
58
|
loop do
|
59
|
+
break if counter > 3
|
60
|
+
|
57
61
|
uri = uris(uri)
|
58
62
|
client = clients(uri)
|
59
63
|
response = client.get(endpoint: uri.request_uri, parser: @parser)
|
@@ -75,12 +79,16 @@ class DistributedPress
|
|
75
79
|
break if link.nil?
|
76
80
|
break if link['href'].nil?
|
77
81
|
break if link['href'].empty?
|
82
|
+
break if link['href'] == uri
|
78
83
|
|
79
84
|
# Start loop again with the new URI
|
85
|
+
counter += 1
|
80
86
|
uri = link['href']
|
81
87
|
end
|
82
88
|
|
83
|
-
response
|
89
|
+
response.tap do |r|
|
90
|
+
raise(client.class::EmptyResponseError, original_uri) unless r
|
91
|
+
end
|
84
92
|
end
|
85
93
|
|
86
94
|
# Gets a client for a URI
|
@@ -38,7 +38,16 @@ class DistributedPress
|
|
38
38
|
#
|
39
39
|
# @return [String]
|
40
40
|
def endpoint
|
41
|
-
@endpoint ||=
|
41
|
+
@endpoint ||=
|
42
|
+
begin
|
43
|
+
encoded_id = Base64.encode64(activity).delete("\n")
|
44
|
+
|
45
|
+
if encoded_id.size > 256
|
46
|
+
raise DistributedPress::V1::Social::Client::ActivityIdTooLargeError.new("Base64 encoding too large (256 char limit): #{activity}")
|
47
|
+
end
|
48
|
+
|
49
|
+
"/v1/#{actor}/inbox/likes/#{encoded_id}"
|
50
|
+
end
|
42
51
|
end
|
43
52
|
end
|
44
53
|
end
|
@@ -44,32 +44,11 @@ class DistributedPress
|
|
44
44
|
@object ||= dereferencer.get(uri: uri)
|
45
45
|
end
|
46
46
|
|
47
|
-
# Is this a public post?
|
48
|
-
#
|
49
|
-
# @return [Bool]
|
50
|
-
def public?
|
51
|
-
[slice(*%w[audience to]).values].flatten.include? PUBLIC
|
52
|
-
end
|
53
|
-
|
54
|
-
# Is it unlisted?
|
55
|
-
#
|
56
|
-
# @return [Bool]
|
57
|
-
def unlisted?
|
58
|
-
[self['cc']].flatten.include? PUBLIC
|
59
|
-
end
|
60
|
-
|
61
|
-
# It's not publicly available
|
62
|
-
#
|
63
|
-
# @return [Bool]
|
64
|
-
def private?
|
65
|
-
!public? && !unlisted?
|
66
|
-
end
|
67
|
-
|
68
47
|
def inspect
|
69
48
|
"#{self.class.name}(#{uri})"
|
70
49
|
end
|
71
50
|
|
72
|
-
def_delegators :object, :[], :dig, :to_h, :to_json, :slice, :key?, :keys, :each
|
51
|
+
def_delegators :object, :[], :dig, :to_h, :to_json, :slice, :key?, :keys, :each, :public?, :unlisted?, :private?
|
73
52
|
end
|
74
53
|
end
|
75
54
|
end
|
@@ -9,6 +9,11 @@ class DistributedPress
|
|
9
9
|
class ReferencedObject
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
+
# Public addressing doesn't lead to an activity
|
13
|
+
#
|
14
|
+
# @return [String]
|
15
|
+
PUBLIC = 'https://www.w3.org/ns/activitystreams#Public'
|
16
|
+
|
12
17
|
# Mastodon hides self-replies
|
13
18
|
URI_FIXES = %r{&?only_other_accounts=true&?}
|
14
19
|
REFERENTIABLE_ATTRIBUTES =
|
@@ -48,7 +53,7 @@ class DistributedPress
|
|
48
53
|
attr_reader :dereferencer
|
49
54
|
attr_reader :referenced
|
50
55
|
|
51
|
-
def_delegators :referenced, :[], :dig, :to_h, :to_json, :keys, :key
|
56
|
+
def_delegators :referenced, :[], :dig, :to_h, :to_json, :keys, :key?, :slice
|
52
57
|
|
53
58
|
def initialize(object:, dereferencer:, referenced: nil)
|
54
59
|
@object = object
|
@@ -56,6 +61,30 @@ class DistributedPress
|
|
56
61
|
@referenced = referenced || reference_object(object)
|
57
62
|
end
|
58
63
|
|
64
|
+
# Is this a public post? A post is public when it's addressed to
|
65
|
+
# the public or doesn't have a recipient (like Like)
|
66
|
+
#
|
67
|
+
# @return [Bool]
|
68
|
+
def public?
|
69
|
+
recipients = [slice(*%w[audience to]).values].flatten
|
70
|
+
|
71
|
+
recipients.empty? || recipients.include?(PUBLIC)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Is it unlisted?
|
75
|
+
#
|
76
|
+
# @return [Bool]
|
77
|
+
def unlisted?
|
78
|
+
[self['cc']].flatten.include? PUBLIC
|
79
|
+
end
|
80
|
+
|
81
|
+
# It's not publicly available
|
82
|
+
#
|
83
|
+
# @return [Bool]
|
84
|
+
def private?
|
85
|
+
!public? && !unlisted?
|
86
|
+
end
|
87
|
+
|
59
88
|
def _dump(_)
|
60
89
|
Marshal.dump([object, dereferencer])
|
61
90
|
end
|
@@ -107,7 +136,7 @@ class DistributedPress
|
|
107
136
|
new_object
|
108
137
|
end
|
109
138
|
when String
|
110
|
-
if object ==
|
139
|
+
if object == PUBLIC
|
111
140
|
object
|
112
141
|
else
|
113
142
|
dereferencer.references(dereferencer.uris(object.sub(URI_FIXES, '')))
|
@@ -38,7 +38,16 @@ class DistributedPress
|
|
38
38
|
#
|
39
39
|
# @return [String]
|
40
40
|
def endpoint
|
41
|
-
@endpoint ||=
|
41
|
+
@endpoint ||=
|
42
|
+
begin
|
43
|
+
encoded_id = Base64.encode64(activity).delete("\n")
|
44
|
+
|
45
|
+
if encoded_id.size > 256
|
46
|
+
raise DistributedPress::V1::Social::Client::ActivityIdTooLargeError.new("Base64 encoding too large (256 char limit): #{activity}")
|
47
|
+
end
|
48
|
+
|
49
|
+
"/v1/#{actor}/inbox/replies/#{encoded_id}"
|
50
|
+
end
|
42
51
|
end
|
43
52
|
end
|
44
53
|
end
|
@@ -38,7 +38,16 @@ class DistributedPress
|
|
38
38
|
#
|
39
39
|
# @return [String]
|
40
40
|
def endpoint
|
41
|
-
@endpoint ||=
|
41
|
+
@endpoint ||=
|
42
|
+
begin
|
43
|
+
encoded_id = Base64.encode64(activity).delete("\n")
|
44
|
+
|
45
|
+
if encoded_id.size > 256
|
46
|
+
raise DistributedPress::V1::Social::Client::ActivityIdTooLargeError.new("Base64 encoding too large (256 char limit): #{activity}")
|
47
|
+
end
|
48
|
+
|
49
|
+
"/v1/#{actor}/inbox/shares/#{encoded_id}"
|
50
|
+
end
|
42
51
|
end
|
43
52
|
end
|
44
53
|
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,41 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- f
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
|
-
cert_chain:
|
11
|
-
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIEYDCCAsigAwIBAgIBATANBgkqhkiG9w0BAQsFADA7MQ4wDAYDVQQDDAVmYXVu
|
14
|
+
bzEVMBMGCgmSJomT8ixkARkWBXN1dHR5MRIwEAYKCZImiZPyLGQBGRYCbmwwHhcN
|
15
|
+
MjUwMTA3MTczMTQ1WhcNMjYwMTA3MTczMTQ1WjA7MQ4wDAYDVQQDDAVmYXVubzEV
|
16
|
+
MBMGCgmSJomT8ixkARkWBXN1dHR5MRIwEAYKCZImiZPyLGQBGRYCbmwwggGiMA0G
|
17
|
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AwJLhYtKneU/m5PEqv9nNnJVCLlbODB
|
32
|
+
zFTjbsKtpWxNN+xWsJbjukggS8uX1400WqyjUCitDxDJknP+xeAg8wt2wT+IC1X1
|
33
|
+
zMY8gjxoBfwPum74cBTaZzYMpeGaS1fJ3N4NBU+SHLRDiKaVZzEnoNyJDHnsXXrX
|
34
|
+
MvF98+bTUHC9xcklH7RCO5uqUOq7cxIcMjzx3cpR6+AW6zXYQBjWfNB9KfaAstZy
|
35
|
+
cpurTQHNJfL/ah+9dYbgDXdG5HAAjRMAsWSvERw95YdN9XzQZCdUk5wUs+A6cNtO
|
36
|
+
AZZUMTVYNx8JqUeemxlXBRjsD/s=
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date: 2025-03-25 00:00:00.000000000 Z
|
12
39
|
dependencies:
|
13
40
|
- !ruby/object:Gem::Dependency
|
14
41
|
name: addressable
|
@@ -374,7 +401,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
374
401
|
- !ruby/object:Gem::Version
|
375
402
|
version: '0'
|
376
403
|
requirements: []
|
377
|
-
rubygems_version: 3.3.
|
404
|
+
rubygems_version: 3.3.27
|
378
405
|
signing_key:
|
379
406
|
specification_version: 4
|
380
407
|
summary: Distributed Press API Client
|
metadata.gz.sig
ADDED
Binary file
|