activitypub 0.1.0 → 0.3.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: c1ca73a9e32bd5ed6fe6fc28cdeeaae31b82d498c433ecc7b814362ab0d55833
4
- data.tar.gz: 3843cf8bd348e19771798efe7557ec6e2701e21734e22a784a2340dffe328d9e
3
+ metadata.gz: bfcd0189a94cb5ee758ef31409bfee306f70f56d6c4a13aca63dd0a26bc41f39
4
+ data.tar.gz: 5add381a4640f4e6b58748e67d342a105507ea09bea46c1e489dc45d9369362b
5
5
  SHA512:
6
- metadata.gz: 5c0ddf7fd8672ba4d44b7f3f9b894625a2b279e0bd2c0f867a74a1da45ab462dc04d530dd2430c8ec5065b7c4ce1b4282fa5dc79a1a4a85b04fdb48bdb38148e
7
- data.tar.gz: 69ad1655d931018f102e2b8c25cf5e2310803fc3a5ca4fc02a2192e9b0ccfd74cf59cc8891fbacb96c3ee69c17fddf5af594738aaf0a65042a9d950fb77d09f5
6
+ metadata.gz: 6c966ce54df93f5953e943f2a22b99258ed9549ebd9646020dd3fb8306003ab3e6f7c911d7e98baa8d893abb2ffeee8fcc93af4c0fdbb35c4985280a7d961b1a
7
+ data.tar.gz: 8bb7a8405035bfac1c09c939c03a200734b60c2c3b7169b5d316c8e1e9fb668a65f5fe603fe5e30550f614e6b97d681da3bc13b188218d3073829d76f5daa289
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/README.md CHANGED
@@ -1,20 +1,18 @@
1
- # Activitypub
1
+ # ActivityPub
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ *Very* early start on a set of classes to serialize/deserialize
4
+ ActivityPub/ActivityStream objects.
4
5
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activitypub`. To experiment with that code, run `bin/console` for an interactive prompt.
6
6
 
7
7
  ## Installation
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
9
  Install the gem and add to the application's Gemfile by executing:
12
10
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
11
+ $ bundle add activitypub
14
12
 
15
13
  If bundler is not being used to manage dependencies, install the gem by executing:
16
14
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
15
+ $ gem install activitypub
18
16
 
19
17
  ## Usage
20
18
 
@@ -28,7 +26,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
28
26
 
29
27
  ## Contributing
30
28
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activitypub.
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vidarh/activitypub.
32
30
 
33
31
  ## License
34
32
 
@@ -0,0 +1,41 @@
1
+
2
+ module ActivityPub
3
+
4
+ # This is not part of ActivityPub, but provides basic mechanisms
5
+ # for serialization and dezerialisation.
6
+ #
7
+ class Base
8
+ def _context = "https://www.w3.org/ns/activitystreams"
9
+ def _type = self.class.name.split("::").last
10
+
11
+
12
+ def self.ap_attr(*names)
13
+ @ap_attributes ||= []
14
+ @ap_attributes.concat(names)
15
+ attr_accessor *names
16
+ end
17
+
18
+ def self.ap_attributes
19
+ parent = superclass.respond_to?(:ap_attributes) ? superclass.ap_attributes : []
20
+ parent.concat(@ap_attributes||[])
21
+ end
22
+
23
+ def to_h
24
+ h = {
25
+ "@context" => _context,
26
+ "type" => _type,
27
+ }
28
+
29
+ self.class.ap_attributes.each do |attr|
30
+ val = instance_variable_get("@#{attr}")
31
+ h[attr.to_s] = val if val
32
+ end
33
+
34
+ h
35
+ end
36
+
37
+ def to_json(...) = to_h.to_json(...)
38
+ end
39
+
40
+
41
+ end
@@ -0,0 +1,216 @@
1
+
2
+ # https://www.w3.org/TR/activitystreams-vocabulary/
3
+
4
+ require_relative 'base'
5
+
6
+ module ActivityPub
7
+
8
+ class Link < Base
9
+ ap_attr :href, :rel, :mediaType, :name, :hreflang, :height, :width, :preview
10
+ end
11
+
12
+ class Object < Base
13
+ ap_attr :attachment, :attributedTo, :audience, :content, :context,
14
+ :name, :endTime, :generator, :icon, :image, :inReplyTo, :location,
15
+ :preview, :published, :replies, :startTime, :summary, :tag, :updated,
16
+ :url, :to, :bto, :cc, :mediaType, :duration
17
+ end
18
+
19
+ class Activity < Object
20
+ ap_attr :actor, :object, :target, :result, :origin, :instrument
21
+ end
22
+
23
+ # @FIXME
24
+ # All attributes from Activity *except* object.
25
+ class IntransitiveActivity < Activity
26
+ end
27
+
28
+ class Collection < Object
29
+ ap_attr :totalItems, :current, :first, :last, :items
30
+ end
31
+
32
+ class OrderedCollection < Collection
33
+ end
34
+
35
+ class CollectionPage < Collection
36
+ ap_attr :partOf, :next, :prev
37
+ end
38
+
39
+ class OrderedCollectionPage < CollectionPage
40
+ ap_attr :startIndex
41
+ end
42
+
43
+ # ## ActivityTypes
44
+
45
+ class Accept < Activity
46
+ end
47
+
48
+ class TentativeAccept < Accept
49
+ end
50
+
51
+ class Add < Activity
52
+ end
53
+
54
+ class Arrive < IntransitiveActivity
55
+ end
56
+
57
+ class Create < Activity
58
+ end
59
+
60
+ class Delete < Activity
61
+ end
62
+
63
+ class Follow < Activity
64
+ end
65
+
66
+ class Ignore < Activity
67
+ end
68
+
69
+ class Join < Activity
70
+ end
71
+
72
+ class Leave < Activity
73
+ end
74
+
75
+ class Like < Activity
76
+ end
77
+
78
+ class Offer < Activity
79
+ end
80
+
81
+ class Invite < Offer
82
+ end
83
+
84
+ class Reject < Activity
85
+ end
86
+
87
+ class TentativeReject < Reject
88
+ end
89
+
90
+ class Remove < Activity
91
+ end
92
+
93
+ class Undo < Activity
94
+ end
95
+
96
+ class Update < Activity
97
+ end
98
+
99
+ class View < Activity
100
+ end
101
+
102
+ class Listen < Activity
103
+ end
104
+
105
+ class Move < Activity
106
+ end
107
+
108
+ class Travel < IntransitiveActivity
109
+ end
110
+
111
+ class Announce < Activity
112
+ end
113
+
114
+ class Block < Ignore
115
+ end
116
+
117
+ class Flag < Activity
118
+ end
119
+
120
+ class Dislike < Activity
121
+ end
122
+
123
+ class Question < IntransitiveActivity
124
+ ap_attr :oneOf, :anyOf, :closed
125
+ end
126
+
127
+ # ## Actor Types
128
+
129
+ # NOTE: *NOT* an ActivityPub object type
130
+ # FIXME: Should probably not be possible to instantiate
131
+ # directly.
132
+ #
133
+ class Actor < Object
134
+ # Per https://www.w3.org/TR/activitypub/#actors
135
+ # Section 4.1
136
+
137
+ # MUST have:
138
+ ap_attr :inbox, :outbox
139
+
140
+ # SHOULD have:
141
+ ap_attr :following, :followers
142
+
143
+ # MAY have:
144
+ ap_attr :liked, :streams, :preferredUsername,
145
+ :endpoints
146
+
147
+
148
+ # Per https://docs-p.joinmastodon.org/spec/activitypub/#extensions
149
+ # These are extensions used by Mastodon for Actor types
150
+ ap_attr :publicKey, :featured, :featuredTags,
151
+ :discoverable, :suspended
152
+ end
153
+
154
+ # FIXME: Add "toot:Emoji
155
+ # FIXME: Add PropertyValue
156
+
157
+ class Application < Actor
158
+ end
159
+
160
+ class Group < Actor
161
+ end
162
+
163
+ class Person < Actor
164
+ end
165
+
166
+ class Service < Actor
167
+ end
168
+
169
+
170
+ # ## Object types
171
+
172
+ class Relationship < Object
173
+ ap_attr :subject, :object, :relationship
174
+ end
175
+
176
+ class Article < Object
177
+ end
178
+
179
+ class Document < Object
180
+ end
181
+
182
+ class Audio < Document
183
+ end
184
+
185
+ class Image < Document
186
+
187
+ # Mastodon extension per
188
+ # https://docs-p.joinmastodon.org/spec/activitypub/#extensions
189
+ ap_attr :focalPoint, :blurhash
190
+ end
191
+
192
+ class Video < Document
193
+ end
194
+
195
+ class Note < Object
196
+ end
197
+
198
+ class Page < Object
199
+ end
200
+
201
+ class Event < Object
202
+ end
203
+
204
+ class Place < Object
205
+ end
206
+
207
+ class Mention < Link
208
+ end
209
+
210
+ class Profile < Object
211
+ end
212
+
213
+ class Tombstone < Object
214
+ ap_attr :formerType, :deleted
215
+ end
216
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivityPub
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/activitypub.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "activitypub/version"
4
+ require_relative "activitypub/types"
4
5
 
5
6
  module ActivityPub
6
7
  class Error < StandardError; 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.1.0
4
+ version: 0.3.0
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-01 00:00:00.000000000 Z
11
+ date: 2024-07-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -17,10 +17,13 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".rspec"
20
21
  - LICENSE.txt
21
22
  - README.md
22
23
  - Rakefile
23
24
  - lib/activitypub.rb
25
+ - lib/activitypub/base.rb
26
+ - lib/activitypub/types.rb
24
27
  - lib/activitypub/version.rb
25
28
  - sig/activitypub.rbs
26
29
  homepage: https://github.com/vidarh/activitypub