blob: c2bd2112b16468d960cec9e5a3ac4792292d1643 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# frozen_string_literal: true
module ActivityPub
class InboxResolverService
attr_reader :subscription
def initialize(subscription)
@subscription = subscription
end
def execute
profile = subscriber_profile
unless profile.has_key?('inbox') && profile['inbox'].is_a?(String)
raise ThirdPartyError, 'Inbox parameter absent or invalid'
end
subscription.subscriber_inbox_url = profile['inbox']
subscription.shared_inbox_url = profile.dig('entrypoints', 'sharedInbox')
subscription.save!
end
private
def subscriber_profile
raw_data = download_subscriber_profile
begin
profile = Gitlab::Json.parse(raw_data)
rescue JSON::ParserError => e
raise ThirdPartyError, e.message
end
profile
end
def download_subscriber_profile
begin
response = Gitlab::HTTP.get(subscription.subscriber_url,
headers: {
'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
}
)
rescue StandardError => e
raise ThirdPartyError, e.message
end
response.body
end
end
end
|