activitypub 0.3.2 → 0.3.5
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 +4 -4
 - data/lib/activitypub/base.rb +22 -3
 - data/lib/activitypub/types.rb +16 -0
 - data/lib/activitypub/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 8c0e1247ee89de99f86956188ce6bd17a3a5360b9abb222badc18b2671cca5b9
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: eeede65bac6dd07a3ba9acdb9569d764448d2ff06816e59741431f9a8f3fdbff
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 62a13084316cbf4c333ab333f41639a1a41ec29e72d53c5a9ab61a82b13396a08eb553e2c147d9c2a35dc197756859f2c11d5c6dccfd8525573a2c1f9a74bbe3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: acdb52191d7b1fc1ca31178dc8becbeaeac3c97e4a4c14e2fba27fee3ca22722edb3c766cc3d98a9188181541a8b6384643ee3d241953558fd44360d36418c95
         
     | 
    
        data/lib/activitypub/base.rb
    CHANGED
    
    | 
         @@ -1,23 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         | 
| 
       2 
3 
     | 
    
         
             
            require 'json'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            module ActivityPub
         
     | 
| 
       5 
6 
     | 
    
         
             
              class Error < StandardError; end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
9 
     | 
    
         
             
              def self.from_json(json)
         
     | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
      
 10 
     | 
    
         
            +
                from_hash(JSON.parse(json))
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              def self.from_hash(h)
         
     | 
| 
       9 
14 
     | 
    
         
             
                type = h&.dig("type")
         
     | 
| 
       10 
15 
     | 
    
         | 
| 
       11 
16 
     | 
    
         
             
                raise Error, "'type' attribute is required" if !type
         
     | 
| 
       12 
17 
     | 
    
         
             
                raise NameError, "'type' attribute with '::' is not allowed" if !type.index("::").nil?
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                # FIXME: May need a way to override/handle custom namespaces.
         
     | 
| 
       13 
20 
     | 
    
         | 
| 
       14 
21 
     | 
    
         
             
                klass = ActivityPub.const_get(type)
         
     | 
| 
       15 
22 
     | 
    
         | 
| 
       16 
23 
     | 
    
         
             
                ob = klass ? klass.new : nil
         
     | 
| 
       17 
24 
     | 
    
         | 
| 
       18 
25 
     | 
    
         
             
                if ob
         
     | 
| 
      
 26 
     | 
    
         
            +
                  context = h.dig("@context")
         
     | 
| 
      
 27 
     | 
    
         
            +
                  ob.instance_variable_set("@_context", context) if context
         
     | 
| 
      
 28 
     | 
    
         
            +
                  
         
     | 
| 
       19 
29 
     | 
    
         
             
                  klass.ap_attributes.each do |attr|
         
     | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
      
 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)
         
     | 
| 
       21 
40 
     | 
    
         
             
                  end
         
     | 
| 
       22 
41 
     | 
    
         
             
                end
         
     | 
| 
       23 
42 
     | 
    
         | 
| 
         @@ -28,7 +47,7 @@ module ActivityPub 
     | 
|
| 
       28 
47 
     | 
    
         
             
              # for serialization and dezerialisation.
         
     | 
| 
       29 
48 
     | 
    
         
             
              #
         
     | 
| 
       30 
49 
     | 
    
         
             
              class Base
         
     | 
| 
       31 
     | 
    
         
            -
                def _context = "https://www.w3.org/ns/activitystreams" 
     | 
| 
      
 50 
     | 
    
         
            +
                def _context = @_context || "https://www.w3.org/ns/activitystreams"
         
     | 
| 
       32 
51 
     | 
    
         
             
                def _type = self.class.name.split("::").last
         
     | 
| 
       33 
52 
     | 
    
         | 
| 
       34 
53 
     | 
    
         | 
    
        data/lib/activitypub/types.rb
    CHANGED
    
    | 
         @@ -31,6 +31,13 @@ module ActivityPub 
     | 
|
| 
       31 
31 
     | 
    
         
             
              end
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
33 
     | 
    
         
             
              class OrderedCollection < Collection
         
     | 
| 
      
 34 
     | 
    
         
            +
                # "orderedItems" is not part of
         
     | 
| 
      
 35 
     | 
    
         
            +
                # https://www.w3.org/TR/activitystreams-vocabulary/#dfn-orderedcollection,
         
     | 
| 
      
 36 
     | 
    
         
            +
                # however it is part of at least some Mastodon exports, and so we include
         
     | 
| 
      
 37 
     | 
    
         
            +
                # it here
         
     | 
| 
      
 38 
     | 
    
         
            +
                #
         
     | 
| 
      
 39 
     | 
    
         
            +
                # FIXME: Review/consider whether to marge orderedItems/items internally.
         
     | 
| 
      
 40 
     | 
    
         
            +
                ap_attr :orderedItems
         
     | 
| 
       34 
41 
     | 
    
         
             
              end
         
     | 
| 
       35 
42 
     | 
    
         | 
| 
       36 
43 
     | 
    
         
             
              class CollectionPage < Collection
         
     | 
| 
         @@ -218,4 +225,13 @@ module ActivityPub 
     | 
|
| 
       218 
225 
     | 
    
         
             
              class Tombstone < Object
         
     | 
| 
       219 
226 
     | 
    
         
             
                ap_attr :formerType, :deleted
         
     | 
| 
       220 
227 
     | 
    
         
             
              end
         
     | 
| 
      
 228 
     | 
    
         
            +
             
     | 
| 
      
 229 
     | 
    
         
            +
              # Mastodon extensions
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
              class Hashtag < Link
         
     | 
| 
      
 232 
     | 
    
         
            +
              end
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
      
 234 
     | 
    
         
            +
              class PropertyValue < Object
         
     | 
| 
      
 235 
     | 
    
         
            +
                ap_attr :value
         
     | 
| 
      
 236 
     | 
    
         
            +
              end
         
     | 
| 
       221 
237 
     | 
    
         
             
            end
         
     | 
    
        data/lib/activitypub/version.rb
    CHANGED
    
    
    
        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 
     | 
    
         
            +
              version: 0.3.5
         
     | 
| 
       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 
     | 
    
         
            +
            date: 2024-07-06 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            email:
         
     |