distributed-press-api-client 0.4.0rc3 → 0.4.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a027ef2456449498ff03679402ac4a0f3689656cd5990e0aa9498b07e86beea
|
4
|
+
data.tar.gz: 1117e426318b07a0bbb833713b6e15fd5c614490d4ff05d1c29cac4cbbb8fc1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c462c24bd87a73557218beefe37b3194016ee1462fbd061155018b09c068fba019027512c17eee71c8096f83bd10a14a81aaca06d6597efa9218e615341f24de
|
7
|
+
data.tar.gz: b9424cca5bf2d55085298e5205df63bfe6813b1a3874f3854c85a1cd9019a4207284468b5337081e2e73b7fbe7b9e8f6ceccc1e289d7a7a28fd856674ca5acb1
|
@@ -202,7 +202,7 @@ class DistributedPress
|
|
202
202
|
# after the request is instantiated. No need to process
|
203
203
|
# cookies for now. Uses the public key URL as a caching key so
|
204
204
|
# we revalidate access on shared caches.
|
205
|
-
options = { body: body, headers: headers, base_uri: url, parser: parser, stream_body: true
|
205
|
+
options = { body: body, headers: headers, base_uri: url, parser: parser, stream_body: true }
|
206
206
|
options = HTTParty::ModuleInheritableAttributes.hash_deep_dup(self.class.default_options).merge(options)
|
207
207
|
response_body = ''.dup
|
208
208
|
|
@@ -21,6 +21,23 @@ class DistributedPress
|
|
21
21
|
@actor = actor
|
22
22
|
end
|
23
23
|
|
24
|
+
# Creates a Social Inbox by uploading the keypair to it.
|
25
|
+
#
|
26
|
+
# @param actor_url [String] The URL where the Actor profile is hosted
|
27
|
+
# @return [HTTParty::Response]
|
28
|
+
def create(actor_url)
|
29
|
+
inbox_body = {
|
30
|
+
'actorUrl' => actor_url,
|
31
|
+
'publicKeyId' => "#{actor_url}#main-key",
|
32
|
+
'keypair' => {
|
33
|
+
'publicKeyPem' => client.public_key.public_to_pem,
|
34
|
+
'privateKeyPem' => client.private_key.export
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
client.post(endpoint: "/v1/#{actor}", body: inbox_body)
|
39
|
+
end
|
40
|
+
|
24
41
|
# Get the actor's inbox
|
25
42
|
#
|
26
43
|
# @return [HTTParty::Response]
|
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.
|
4
|
+
version: 0.4.0
|
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
|
+
date: 2024-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -311,7 +311,6 @@ 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/dereferencer.rb.orig
|
315
314
|
- lib/distributed_press/v1/social/hook.rb
|
316
315
|
- lib/distributed_press/v1/social/inbox.rb
|
317
316
|
- lib/distributed_press/v1/social/outbox.rb
|
@@ -351,9 +350,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
351
350
|
version: '2.7'
|
352
351
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
353
352
|
requirements:
|
354
|
-
- - "
|
353
|
+
- - ">="
|
355
354
|
- !ruby/object:Gem::Version
|
356
|
-
version:
|
355
|
+
version: '0'
|
357
356
|
requirements: []
|
358
357
|
rubygems_version: 3.3.26
|
359
358
|
signing_key:
|
@@ -1,132 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'addressable'
|
4
|
-
require_relative 'reference'
|
5
|
-
|
6
|
-
class DistributedPress
|
7
|
-
module V1
|
8
|
-
module Social
|
9
|
-
# Fetches ActivityStreams from different instances by
|
10
|
-
# instantiating clients.
|
11
|
-
class Dereferencer
|
12
|
-
# @return [DistributedPress::V1::Social::Client]
|
13
|
-
attr_reader :client
|
14
|
-
|
15
|
-
REFERENTIABLE_ATTRIBUTES =
|
16
|
-
%w[
|
17
|
-
actor
|
18
|
-
owner
|
19
|
-
attributedTo
|
20
|
-
cc
|
21
|
-
inReplyTo
|
22
|
-
object
|
23
|
-
replies
|
24
|
-
to
|
25
|
-
publicKey
|
26
|
-
|
27
|
-
alsoKnownAs
|
28
|
-
devices
|
29
|
-
featured
|
30
|
-
featuredTags
|
31
|
-
followers
|
32
|
-
following
|
33
|
-
inbox
|
34
|
-
movedTo
|
35
|
-
outbox
|
36
|
-
|
37
|
-
first
|
38
|
-
items
|
39
|
-
next
|
40
|
-
orderedItems
|
41
|
-
partOf
|
42
|
-
prev
|
43
|
-
].freeze
|
44
|
-
|
45
|
-
# @param :client [DistributedPress::V1::Social::Client]
|
46
|
-
def initialize(client:)
|
47
|
-
@client = client
|
48
|
-
@parser =
|
49
|
-
proc do |body, format|
|
50
|
-
next HTTParty::Parser.call(body, format || :plain) unless body&.starts_with? '{'
|
51
|
-
|
52
|
-
HTTParty::Parser.call(body, :json).tap do |object|
|
53
|
-
reference_object! object
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Fetch a URI
|
59
|
-
#
|
60
|
-
# @param :uri [String, Addressable::URI]
|
61
|
-
# @return [HTTParty::Response]
|
62
|
-
def get(uri:)
|
63
|
-
uri = uris(uri)
|
64
|
-
|
65
|
-
clients(uri).get(endpoint: uri.path, parser: @parser)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Gets a client for a URI
|
69
|
-
#
|
70
|
-
# @param :uri [Addressable::URI]
|
71
|
-
# @return [DistributedPress::V1::Social::Client]
|
72
|
-
def clients(uri)
|
73
|
-
@clients ||= {}
|
74
|
-
@clients[uri.origin] ||=
|
75
|
-
client.class.new(
|
76
|
-
url: uri.origin,
|
77
|
-
public_key_url: client.public_key_url,
|
78
|
-
private_key_pem: client.private_key.to_s,
|
79
|
-
logger: client.logger,
|
80
|
-
cache_store: client.class.cache_store
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
# Gets a reference for a URI and indexes it by the complete
|
85
|
-
# and normalized URI
|
86
|
-
#
|
87
|
-
# @param :uri [String, Addressable::URI]
|
88
|
-
# @return [DistributedPress::V1::Social::Reference]
|
89
|
-
def references(uri)
|
90
|
-
@references ||= {}
|
91
|
-
@references[uri.to_s] ||= Reference.new(uri: uri.to_s, dereferencer: self)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Make sure we're getting a normalized Addressable::URI
|
95
|
-
#
|
96
|
-
# @param :uri [String, Addressable::URI]
|
97
|
-
# @return [Addressable::URI]
|
98
|
-
def uris(uri)
|
99
|
-
@uris ||= {}
|
100
|
-
@uris[uri.to_s] ||=
|
101
|
-
(if uri.is_a? Addressable::URI
|
102
|
-
uri
|
103
|
-
else
|
104
|
-
Addressable::URI.parse(uri)
|
105
|
-
end).normalize
|
106
|
-
end
|
107
|
-
|
108
|
-
def reference_object!(object)
|
109
|
-
REFERENTIABLE_ATTRIBUTES.each do |attribute|
|
110
|
-
next unless object.key? attribute
|
111
|
-
|
112
|
-
case object[attribute]
|
113
|
-
when Array
|
114
|
-
object[attribute].map! do |o|
|
115
|
-
case o
|
116
|
-
when Hash
|
117
|
-
reference_object!(o)
|
118
|
-
o
|
119
|
-
when String then references(uris(o))
|
120
|
-
end
|
121
|
-
end
|
122
|
-
when Hash
|
123
|
-
reference_object!(object[attribute])
|
124
|
-
when String
|
125
|
-
object[attribute] = references(uris(object[attribute]))
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|