activitypub 0.3.6 → 0.3.7

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: ed038947b69b69a8e0571743cbf28fdfaf7131c4922bc26b1e0d47a532dd6002
4
- data.tar.gz: fdda56411f0ebc9d50365eea7bb028eb8b6f718947c10a57f4a838b8201e7d50
3
+ metadata.gz: 58943510abdbebb4cce7084adcd2fd5c587abed81f103db968148248a9b1e7c1
4
+ data.tar.gz: 5ccd6bd6cff637fdc5717d064b8b02a29282c9e6d7549c8ad322bd30a0ce2503
5
5
  SHA512:
6
- metadata.gz: a1339e651c59ec7d18c9b82a48b15e15c7591821276c2d8934f9c8ecd5a014bbfed57e56cc20d95627bca5ac5182d6e6ba6e10e14c36f673948fa555f3cd76b8
7
- data.tar.gz: dba788189a64fff38c808db2734bd567bb25bae0ffd0db6503242f56e1edf52b299474eeab4a11bdd40fd994782ee255cada4fa68fc4fbbe23b3056ef8cd28a7
6
+ metadata.gz: 7a8b4a3a8cdac1be9d069c47b413d00573640ad59e0deca098bf0a0b5f06124bd3c2a43b66462b2f3bf23b3b187c0de55478878b875fa38674b7c53eac968b54
7
+ data.tar.gz: c4981e523c2754b2d83c9cf6f52fc6de61353b3373097a55b5531f325b08c1477195ba7bac58f3ee47eb3138cb743d06c1719f61e3779a06a3f9b45112011770
@@ -1,17 +1,14 @@
1
1
 
2
- require 'webfinger'
3
- require 'faraday'
4
2
  require 'pp'
5
3
  $: << File.expand_path(__FILE__ + "/../../lib")
6
- require 'activitypub/types'
7
- require 'activitypub/base'
4
+ require 'activitypub'
8
5
 
9
6
  acct = ARGV.shift || "vidar@galaxybound.com"
10
7
 
11
8
  puts "Trying webfinger for #{acct} (to choose your own account, provide it as an argument)"
12
9
  puts
13
10
 
14
- wf = WebFinger.discover!(acct)
11
+ wf = ActivityPub.webfinger(acct)
15
12
  if !wf
16
13
  puts "Unable to find #{acct}"
17
14
  exit(1)
@@ -22,35 +19,21 @@ puts
22
19
  puts "Enter to continue"
23
20
  gets
24
21
 
25
- link = wf["links"].find{ _1["rel"] == "self" && _1["type"] == "application/activity+json" }
26
- if !link || !link["href"]
22
+ href = wf.activitypub
23
+ if !href
27
24
  puts "Unable to find a link to the actor"
28
25
  exit(2)
29
26
  end
30
27
 
31
- href = link["href"]
32
-
33
28
  puts "Trying to retrieve the Actor from #{href}"
34
29
  puts
35
30
 
36
- response = Faraday.get(href,{}, {"Accept": "application/activity+json"})
37
- if response.status != 200
38
- PP.pp response
39
- exit(3)
40
- end
41
-
42
- ob = ActivityPub.from_json(response.body)
31
+ ob = href.get
43
32
  PP.pp(ob)
44
33
  puts
45
34
  puts "Enter to continue"
46
35
  gets
47
36
 
48
37
  puts "Trying to retrieve outbox"
49
- response = Faraday.get(ob.outbox, {}, {"Accept": "application/activity+json"})
50
- if response.status != 200
51
- PP.pp response
52
- exit(4)
53
- end
54
-
55
- ob = ActivityPub.from_json(response.body)
38
+ ob = ActivityPub::URI.new(ob.outbox).get
56
39
  PP.pp(ob)
@@ -36,6 +36,9 @@ module ActivityPub
36
36
  av.is_a?(Hash) && av["type"] ? from_hash(av) : av
37
37
  end
38
38
  end
39
+ if attr.to_s == "href" && v.is_a?(String)
40
+ v = ActivityPub::URI.new(v)
41
+ end
39
42
  ob.instance_variable_set("@#{attr}", v) if !v.nil?
40
43
  end
41
44
  end
@@ -51,6 +54,7 @@ module ActivityPub
51
54
  def _type = self.class.name.split("::").last
52
55
 
53
56
 
57
+ # FIXME: Allow specifying a type (e.g. URI)
54
58
  def self.ap_attr(*names)
55
59
  @ap_attributes ||= []
56
60
  @ap_attributes.concat(names)
@@ -2,6 +2,7 @@
2
2
  # https://www.w3.org/TR/activitystreams-vocabulary/
3
3
 
4
4
  require_relative 'base'
5
+ require_relative 'uri'
5
6
 
6
7
  module ActivityPub
7
8
 
@@ -0,0 +1,23 @@
1
+
2
+ require 'uri'
3
+ require 'faraday'
4
+
5
+ module ActivityPub
6
+ class URI
7
+ def initialize(href)
8
+ @href = href
9
+ end
10
+
11
+ def to_s = @href
12
+ def to_json = @href
13
+
14
+ def get
15
+ response = Faraday.get(self.to_s, {}, {"Accept": "application/activity+json"})
16
+ if response.status == 200
17
+ ActivityPub.from_json(response.body)
18
+ else
19
+ response
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivityPub
4
- VERSION = "0.3.6"
4
+ VERSION = "0.3.7"
5
5
  end
@@ -0,0 +1,27 @@
1
+
2
+ require 'webfinger'
3
+
4
+ module ActivityPub
5
+ class WebFingerResult
6
+ def initialize(hash)
7
+ @h = hash
8
+
9
+ @h["aliases"] = @h["aliases"].map{ ActivityPub::URI.new(_1) }
10
+ @h["links"].each do |v|
11
+ if v["href"]
12
+ v["href"] = ActivityPub::URI.new(v["href"])
13
+ end
14
+ end
15
+ end
16
+
17
+ def[](i) = @h[i]
18
+
19
+ def activitypub
20
+ @activitypub ||= self["links"].find{ _1["rel"] == "self" && _1["type"] == "application/activity+json" }&.dig("href")
21
+ end
22
+ end
23
+
24
+ def self.webfinger(acct)
25
+ WebFingerResult.new(WebFinger.discover!(acct))
26
+ end
27
+ end
data/lib/activitypub.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "activitypub/version"
4
+ require_relative "activitypub/base"
4
5
  require_relative "activitypub/types"
6
+ require_relative "activitypub/uri"
7
+ require_relative "activitypub/webfinger"
5
8
 
6
9
  module ActivityPub
7
10
  class Error < StandardError; end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activitypub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vidar Hokstad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-08 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webfinger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.3
13
27
  description:
14
28
  email:
15
29
  - vidar@hokstad.com
@@ -27,7 +41,9 @@ files:
27
41
  - lib/activitypub.rb
28
42
  - lib/activitypub/base.rb
29
43
  - lib/activitypub/types.rb
44
+ - lib/activitypub/uri.rb
30
45
  - lib/activitypub/version.rb
46
+ - lib/activitypub/webfinger.rb
31
47
  - sig/activitypub.rbs
32
48
  homepage: https://github.com/vidarh/activitypub
33
49
  licenses: