activitypub 0.2.0 → 0.3.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: 26d9d9069a471b10cb01a4ab0989098f6e9b6d3736d4f3c9739844de63b57e43
4
- data.tar.gz: 34fe597a239e1ef1a16765a53ca4554000c8e6c97354f984dfdc583ed579f9c4
3
+ metadata.gz: 3d6b1c47f6ac1051a3057f0ae8d57fe2d83c3c99aea99a45ff09c50f1f044a9b
4
+ data.tar.gz: df120e3bad47452d3a22bb400feab41db3b4c27502b16247f389c751373ccb9b
5
5
  SHA512:
6
- metadata.gz: e06d022fd40649670cf3133c90ab05935d96c6747a4fc3899a266492ee03c767b21407103d111e5ff6b23f351349d9c99cd2c9de03768eeafbd4e8e025291c60
7
- data.tar.gz: ad8f7d544c4565518866825845a95e27d48c5ccc384595db4d627916d3990d772c9f9b3ca2aafd7a6a98263117cb37c89e1e23350fb30b2a3b19b6ca8a1b4f4f
6
+ metadata.gz: bc9e697ab7e8b67c040c482d9ba1f63ada540f5b2d08a5da689495670f960a71900b21e11548c8fe97ddc205bb5185afa5273c20df53bea9ddd36a1633d8cc6d
7
+ data.tar.gz: 27545eed23569575170cff387692c3d48ffe94c3afe0a9f417d37c121442852d3f5d145e4416ce5bec41c074a2e6ece46d4875183381c0c8b37d8bbb2d1821fd
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/README.md CHANGED
@@ -3,18 +3,28 @@
3
3
  *Very* early start on a set of classes to serialize/deserialize
4
4
  ActivityPub/ActivityStream objects.
5
5
 
6
+ ## Goals
7
+
8
+ * To provide a fairly *minimalist*, *barebones* set of classes to
9
+ work with ActivityPub objects *as used* by major Fediverse apps.
10
+ * Matching real-world use will be prioritized over strict adherence
11
+ to the specs - my use-cases require me to be able to handle documents
12
+ even if they have errors. But I want to be able to *produce* output
13
+ that prefers standards compliance where it doesn't sacrifice interop.
14
+ * Support extensions and namespace used by e.g. Mastodon and others.
15
+ * Be easy to extend/layer new functionality on top of for anything
16
+ that doesn't fit in this core.
6
17
 
7
- ## Installation
8
18
 
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.
19
+ ## Installation
10
20
 
11
21
  Install the gem and add to the application's Gemfile by executing:
12
22
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
23
+ $ bundle add activitypub
14
24
 
15
25
  If bundler is not being used to manage dependencies, install the gem by executing:
16
26
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
27
+ $ gem install activitypub
18
28
 
19
29
  ## Usage
20
30
 
@@ -28,7 +38,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
28
38
 
29
39
  ## Contributing
30
40
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activitypub.
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vidarh/activitypub.
32
42
 
33
43
  ## License
34
44
 
@@ -1,11 +1,26 @@
1
1
 
2
- module ActivityPub
2
+ require 'json'
3
3
 
4
+ module ActivityPub
5
+ class Error < StandardError; end
6
+
7
+ def self.from_json(json)
8
+ h = JSON.parse(json)
9
+ type = h&.dig("type")
10
+
11
+ raise Error, "'type' attribute is required" if !type
12
+ raise NameError, "'type' attribute with '::' is not allowed" if !type.index("::").nil?
13
+
14
+ klass = ActivityPub.const_get(type)
15
+
16
+ klass ? klass.new : nil
17
+ end
18
+
4
19
  # This is not part of ActivityPub, but provides basic mechanisms
5
20
  # for serialization and dezerialisation.
6
21
  #
7
22
  class Base
8
- def _context = "https://www.w3.org/ns/activitystreams"
23
+ def _context = "https://www.w3.org/ns/activitystreams".freeze
9
24
  def _type = self.class.name.split("::").last
10
25
 
11
26
 
@@ -124,6 +124,49 @@ module ActivityPub
124
124
  ap_attr :oneOf, :anyOf, :closed
125
125
  end
126
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
+
127
170
  # ## Object types
128
171
 
129
172
  class Relationship < Object
@@ -140,6 +183,10 @@ module ActivityPub
140
183
  end
141
184
 
142
185
  class Image < Document
186
+
187
+ # Mastodon extension per
188
+ # https://docs-p.joinmastodon.org/spec/activitypub/#extensions
189
+ ap_attr :focalPoint, :blurhash
143
190
  end
144
191
 
145
192
  class Video < Document
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivityPub
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.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.2.0
4
+ version: 0.3.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-01 00:00:00.000000000 Z
11
+ date: 2024-07-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -17,6 +17,7 @@ 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