activitypub 0.3.4 → 0.3.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17f43a4f939aa54391fce983f65b2599fce783d3c1f5cb1fbeadf92bc56bf63f
4
- data.tar.gz: 1f527109c8f80bb80fa6c4b6af988dc1672219757c2177b2bcdff6e6c529ce8a
3
+ metadata.gz: ed038947b69b69a8e0571743cbf28fdfaf7131c4922bc26b1e0d47a532dd6002
4
+ data.tar.gz: fdda56411f0ebc9d50365eea7bb028eb8b6f718947c10a57f4a838b8201e7d50
5
5
  SHA512:
6
- metadata.gz: ee5dab8ee0ed11b02aa08e878b0e35844244a7894248da373c8441cd3aebede599e66fdcc175b2b7d3f172ed6f79ba6e2edc0d0bedb3f6bb32a5589822a59bc6
7
- data.tar.gz: 5090b6f6dc1b4fc61219f542a28ca5415387270354912c5f2a8c967fcd8404f2044aac6f91424d5e10359550881b2649edc20cdc93878c618bbe2f61055f37f8
6
+ metadata.gz: a1339e651c59ec7d18c9b82a48b15e15c7591821276c2d8934f9c8ecd5a014bbfed57e56cc20d95627bca5ac5182d6e6ba6e10e14c36f673948fa555f3cd76b8
7
+ data.tar.gz: dba788189a64fff38c808db2734bd567bb25bae0ffd0db6503242f56e1edf52b299474eeab4a11bdd40fd994782ee255cada4fa68fc4fbbe23b3056ef8cd28a7
data/examples/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "webfinger"
6
+ gem "faraday"
@@ -0,0 +1,48 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (7.1.3.4)
5
+ base64
6
+ bigdecimal
7
+ concurrent-ruby (~> 1.0, >= 1.0.2)
8
+ connection_pool (>= 2.2.5)
9
+ drb
10
+ i18n (>= 1.6, < 2)
11
+ minitest (>= 5.1)
12
+ mutex_m
13
+ tzinfo (~> 2.0)
14
+ base64 (0.2.0)
15
+ bigdecimal (3.1.8)
16
+ concurrent-ruby (1.3.3)
17
+ connection_pool (2.4.1)
18
+ drb (2.2.1)
19
+ faraday (2.10.0)
20
+ faraday-net_http (>= 2.0, < 3.2)
21
+ logger
22
+ faraday-follow_redirects (0.3.0)
23
+ faraday (>= 1, < 3)
24
+ faraday-net_http (3.1.0)
25
+ net-http
26
+ i18n (1.14.5)
27
+ concurrent-ruby (~> 1.0)
28
+ logger (1.6.0)
29
+ minitest (5.24.1)
30
+ mutex_m (0.2.0)
31
+ net-http (0.4.1)
32
+ uri
33
+ tzinfo (2.0.6)
34
+ concurrent-ruby (~> 1.0)
35
+ uri (0.13.0)
36
+ webfinger (2.1.3)
37
+ activesupport
38
+ faraday (~> 2.0)
39
+ faraday-follow_redirects
40
+
41
+ PLATFORMS
42
+ x86_64-linux
43
+
44
+ DEPENDENCIES
45
+ webfinger
46
+
47
+ BUNDLED WITH
48
+ 2.4.19
@@ -0,0 +1,56 @@
1
+
2
+ require 'webfinger'
3
+ require 'faraday'
4
+ require 'pp'
5
+ $: << File.expand_path(__FILE__ + "/../../lib")
6
+ require 'activitypub/types'
7
+ require 'activitypub/base'
8
+
9
+ acct = ARGV.shift || "vidar@galaxybound.com"
10
+
11
+ puts "Trying webfinger for #{acct} (to choose your own account, provide it as an argument)"
12
+ puts
13
+
14
+ wf = WebFinger.discover!(acct)
15
+ if !wf
16
+ puts "Unable to find #{acct}"
17
+ exit(1)
18
+ end
19
+
20
+ PP.pp wf
21
+ puts
22
+ puts "Enter to continue"
23
+ gets
24
+
25
+ link = wf["links"].find{ _1["rel"] == "self" && _1["type"] == "application/activity+json" }
26
+ if !link || !link["href"]
27
+ puts "Unable to find a link to the actor"
28
+ exit(2)
29
+ end
30
+
31
+ href = link["href"]
32
+
33
+ puts "Trying to retrieve the Actor from #{href}"
34
+ puts
35
+
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)
43
+ PP.pp(ob)
44
+ puts
45
+ puts "Enter to continue"
46
+ gets
47
+
48
+ 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)
56
+ PP.pp(ob)
@@ -4,9 +4,13 @@ require 'json'
4
4
 
5
5
  module ActivityPub
6
6
  class Error < StandardError; end
7
+
7
8
 
8
9
  def self.from_json(json)
9
- h = JSON.parse(json)
10
+ from_hash(JSON.parse(json))
11
+ end
12
+
13
+ def self.from_hash(h)
10
14
  type = h&.dig("type")
11
15
 
12
16
  raise Error, "'type' attribute is required" if !type
@@ -23,7 +27,16 @@ module ActivityPub
23
27
  ob.instance_variable_set("@_context", context) if context
24
28
 
25
29
  klass.ap_attributes.each do |attr|
26
- ob.instance_variable_set("@#{attr}", h.dig(attr.to_s))
30
+ v = h.dig(attr.to_s)
31
+
32
+ if v.is_a?(Hash) && v["type"]
33
+ v = from_hash(v)
34
+ elsif v.is_a?(Array)
35
+ v = v.map do |av|
36
+ av.is_a?(Hash) && av["type"] ? from_hash(av) : av
37
+ end
38
+ end
39
+ ob.instance_variable_set("@#{attr}", v) if !v.nil?
27
40
  end
28
41
  end
29
42
 
@@ -225,4 +225,13 @@ module ActivityPub
225
225
  class Tombstone < Object
226
226
  ap_attr :formerType, :deleted
227
227
  end
228
+
229
+ # Mastodon extensions
230
+
231
+ class Hashtag < Link
232
+ end
233
+
234
+ class PropertyValue < Object
235
+ ap_attr :value
236
+ end
228
237
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivityPub
4
- VERSION = "0.3.4"
4
+ VERSION = "0.3.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activitypub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
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-04 00:00:00.000000000 Z
11
+ date: 2024-07-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -21,6 +21,9 @@ files:
21
21
  - LICENSE.txt
22
22
  - README.md
23
23
  - Rakefile
24
+ - examples/Gemfile
25
+ - examples/Gemfile.lock
26
+ - examples/get_actor.rb
24
27
  - lib/activitypub.rb
25
28
  - lib/activitypub/base.rb
26
29
  - lib/activitypub/types.rb