activitypub 0.3.7 → 0.4.1

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: 58943510abdbebb4cce7084adcd2fd5c587abed81f103db968148248a9b1e7c1
4
- data.tar.gz: 5ccd6bd6cff637fdc5717d064b8b02a29282c9e6d7549c8ad322bd30a0ce2503
3
+ metadata.gz: 422c4769d3efddf0251d5cb9f64f92b6f4c9c72c054bed80bd2e2e4d74fb6870
4
+ data.tar.gz: 8d503eed716a1a54d62e654ba647415c6d9b89cfeb060bedc6dbc52a1735aaf5
5
5
  SHA512:
6
- metadata.gz: 7a8b4a3a8cdac1be9d069c47b413d00573640ad59e0deca098bf0a0b5f06124bd3c2a43b66462b2f3bf23b3b187c0de55478878b875fa38674b7c53eac968b54
7
- data.tar.gz: c4981e523c2754b2d83c9cf6f52fc6de61353b3373097a55b5531f325b08c1477195ba7bac58f3ee47eb3138cb743d06c1719f61e3779a06a3f9b45112011770
6
+ metadata.gz: 487e02cb6426a2ac76d3ccedcea22f9fe1693b697aea51969b16d0164a1e9fdbc8233c355182e2e695b04177a4bd2e81f05cb4e25090f972a36938f6cc4260b1
7
+ data.tar.gz: 6ca2c9ca57226499972c51b6d9017a96ace046964d754e0a8eaa46ae5b0d6441d900c473cd16d6ed670eed3838b0181e1f7b31fb7b29d757b0324cb2d2ed066a
@@ -30,10 +30,25 @@ puts
30
30
 
31
31
  ob = href.get
32
32
  PP.pp(ob)
33
+ #puts ob.to_json
33
34
  puts
34
35
  puts "Enter to continue"
35
36
  gets
36
37
 
37
38
  puts "Trying to retrieve outbox"
38
- ob = ActivityPub::URI.new(ob.outbox).get
39
+ ob = ob.outbox.get
39
40
  PP.pp(ob)
41
+ puts
42
+ puts "Enter to continue"
43
+ gets
44
+
45
+ puts
46
+ puts "PAGE: #{ob.first}"
47
+ ob = ob.first.get
48
+ PP.pp(ob)
49
+
50
+ # For now, this will let you iterate through the collection.
51
+ # while ob && ob.orderedItems.length > 0
52
+ # PP.pp ob.id
53
+ # ob = ob.next&.get
54
+ # end
@@ -22,6 +22,9 @@ module ActivityPub
22
22
 
23
23
  ob = klass ? klass.new : nil
24
24
 
25
+ # FIXME: Useful for debug. Add flag to allow enabling.
26
+ # ob.instance_variable_set("@_raw",h)
27
+
25
28
  if ob
26
29
  context = h.dig("@context")
27
30
  ob.instance_variable_set("@_context", context) if context
@@ -36,8 +39,9 @@ module ActivityPub
36
39
  av.is_a?(Hash) && av["type"] ? from_hash(av) : av
37
40
  end
38
41
  end
39
- if attr.to_s == "href" && v.is_a?(String)
40
- v = ActivityPub::URI.new(v)
42
+
43
+ if t = klass.ap_types[attr]
44
+ v = t.new(v) if v
41
45
  end
42
46
  ob.instance_variable_set("@#{attr}", v) if !v.nil?
43
47
  end
@@ -55,12 +59,19 @@ module ActivityPub
55
59
 
56
60
 
57
61
  # FIXME: Allow specifying a type (e.g. URI)
58
- def self.ap_attr(*names)
62
+ def self.ap_attr(name, type=nil)
59
63
  @ap_attributes ||= []
60
- @ap_attributes.concat(names)
61
- attr_accessor *names
64
+ @ap_attributes << name
65
+ @ap_types ||= {}
66
+ @ap_types[name] = type
67
+ attr_accessor name
62
68
  end
63
69
 
70
+ def self.ap_types
71
+ parent = superclass.respond_to?(:ap_types) ? superclass.ap_types : {}
72
+ parent.merge(@ap_types || {})
73
+ end
74
+
64
75
  def self.ap_attributes
65
76
  parent = superclass.respond_to?(:ap_attributes) ? superclass.ap_attributes : []
66
77
  parent.concat(@ap_attributes||[])
@@ -7,19 +7,57 @@ require_relative 'uri'
7
7
  module ActivityPub
8
8
 
9
9
  class Link < Base
10
- ap_attr :href, :rel, :mediaType, :name, :hreflang, :height, :width, :preview
10
+ ap_attr :href, URI
11
+
12
+ # We don't mark "rel" as a URI as it's effectively
13
+ # used as an identifier for comparison rather than to
14
+ # dereference
15
+ ap_attr :rel
16
+
17
+ ap_attr :mediaType
18
+ ap_attr :name
19
+ ap_attr :hreflang
20
+ ap_attr :height
21
+ ap_attr :width
22
+ ap_attr :preview
11
23
  end
12
24
 
13
25
  class Object < Base
14
26
  ap_attr :id
15
- ap_attr :attachment, :attributedTo, :audience, :content, :context,
16
- :name, :endTime, :generator, :icon, :image, :inReplyTo, :location,
17
- :preview, :published, :replies, :startTime, :summary, :tag, :updated,
18
- :url, :to, :bto, :cc, :mediaType, :duration
27
+ ap_attr :attachment
28
+ ap_attr :attributedTo
29
+ ap_attr :audience
30
+ ap_attr :content
31
+ ap_attr :context
32
+ ap_attr :name
33
+ ap_attr :endTime
34
+ ap_attr :generator
35
+ ap_attr :icon
36
+ ap_attr :image
37
+ ap_attr :inReplyTo, URI
38
+ ap_attr :location
39
+ ap_attr :preview
40
+ ap_attr :published
41
+ ap_attr :replies
42
+ ap_attr :startTime
43
+ ap_attr :summary
44
+ ap_attr :tag
45
+ ap_attr :updated
46
+ ap_attr :url, URI
47
+ ap_attr :to
48
+ ap_attr :bto
49
+ ap_attr :cc
50
+ ap_attr :mediaType
51
+ ap_attr :duration
19
52
  end
20
53
 
21
54
  class Activity < Object
22
- ap_attr :actor, :object, :target, :result, :origin, :instrument
55
+ ap_attr :actor
56
+ ap_attr :object
57
+ ap_attr :target
58
+ ap_attr :result
59
+ ap_attr :origin
60
+ ap_attr :instrument
23
61
  end
24
62
 
25
63
  # @FIXME
@@ -28,7 +66,11 @@ module ActivityPub
28
66
  end
29
67
 
30
68
  class Collection < Object
31
- ap_attr :totalItems, :current, :first, :last, :items
69
+ ap_attr :totalItems
70
+ ap_attr :current
71
+ ap_attr :first, URI
72
+ ap_attr :last, URI
73
+ ap_attr :items
32
74
  end
33
75
 
34
76
  class OrderedCollection < Collection
@@ -42,10 +84,18 @@ module ActivityPub
42
84
  end
43
85
 
44
86
  class CollectionPage < Collection
45
- ap_attr :partOf, :next, :prev
87
+ ap_attr :partOf, URI
88
+ ap_attr :next, URI
89
+ ap_attr :prev, URI
46
90
  end
47
-
48
- class OrderedCollectionPage < CollectionPage
91
+
92
+ # FIXME: OrderedCollectionPage inherits both CollectionPage and
93
+ # OrderedCollection.
94
+ #
95
+ class OrderedCollectionPage < OrderedCollection
96
+ ap_attr :partOf, URI
97
+ ap_attr :next, URI
98
+ ap_attr :prev, URI
49
99
  ap_attr :startIndex
50
100
  end
51
101
 
@@ -130,7 +180,9 @@ module ActivityPub
130
180
  end
131
181
 
132
182
  class Question < IntransitiveActivity
133
- ap_attr :oneOf, :anyOf, :closed
183
+ ap_attr :oneOf
184
+ ap_attr :anyOf
185
+ ap_attr :closed
134
186
  end
135
187
 
136
188
  # ## Actor Types
@@ -144,20 +196,27 @@ module ActivityPub
144
196
  # Section 4.1
145
197
 
146
198
  # MUST have:
147
- ap_attr :inbox, :outbox
199
+ ap_attr :inbox, URI
200
+ ap_attr :outbox, URI
148
201
 
149
202
  # SHOULD have:
150
- ap_attr :following, :followers
203
+ ap_attr :following
204
+ ap_attr :followers
151
205
 
152
206
  # MAY have:
153
- ap_attr :liked, :streams, :preferredUsername,
154
- :endpoints
207
+ ap_attr :liked
208
+ ap_attr :streams
209
+ ap_attr :preferredUsername
210
+ ap_attr :endpoints
155
211
 
156
212
 
157
213
  # Per https://docs-p.joinmastodon.org/spec/activitypub/#extensions
158
214
  # These are extensions used by Mastodon for Actor types
159
- ap_attr :publicKey, :featured, :featuredTags,
160
- :discoverable, :suspended
215
+ ap_attr :publicKey
216
+ ap_attr :featured
217
+ ap_attr :featuredTags
218
+ ap_attr :discoverable
219
+ ap_attr :suspended
161
220
  end
162
221
 
163
222
  # FIXME: Add "toot:Emoji
@@ -173,7 +232,9 @@ module ActivityPub
173
232
 
174
233
  # Mastodon extension per
175
234
  # https://docs-p.joinmastodon.org/spec/activitypub/#extensions
176
- ap_attr :likes, :bookmarks, :manuallyApprovesFollowers
235
+ ap_attr :likes
236
+ ap_attr :bookmarks
237
+ ap_attr :manuallyApprovesFollowers
177
238
  end
178
239
 
179
240
  class Service < Actor
@@ -183,7 +244,9 @@ module ActivityPub
183
244
  # ## Object types
184
245
 
185
246
  class Relationship < Object
186
- ap_attr :subject, :object, :relationship
247
+ ap_attr :subject
248
+ ap_attr :object
249
+ ap_attr :relationship
187
250
  end
188
251
 
189
252
  class Article < Object
@@ -199,7 +262,8 @@ module ActivityPub
199
262
 
200
263
  # Mastodon extension per
201
264
  # https://docs-p.joinmastodon.org/spec/activitypub/#extensions
202
- ap_attr :focalPoint, :blurhash
265
+ ap_attr :focalPoint
266
+ ap_attr :blurhash
203
267
  end
204
268
 
205
269
  class Video < Document
@@ -224,7 +288,8 @@ module ActivityPub
224
288
  end
225
289
 
226
290
  class Tombstone < Object
227
- ap_attr :formerType, :deleted
291
+ ap_attr :formerType
292
+ ap_attr :deleted
228
293
  end
229
294
 
230
295
  # Mastodon extensions
@@ -9,7 +9,7 @@ module ActivityPub
9
9
  end
10
10
 
11
11
  def to_s = @href
12
- def to_json = @href
12
+ def to_json(...) = @href
13
13
 
14
14
  def get
15
15
  response = Faraday.get(self.to_s, {}, {"Accept": "application/activity+json"})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivityPub
4
- VERSION = "0.3.7"
4
+ VERSION = "0.4.1"
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.7
4
+ version: 0.4.1
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-11 00:00:00.000000000 Z
11
+ date: 2024-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webfinger