2017-07-15 10:01:39 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
|
2017-09-02 21:01:23 +09:00
|
|
|
CONTEXT = {
|
|
|
|
'@context': [
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
|
|
|
|
{
|
2017-09-03 06:13:35 +09:00
|
|
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
|
|
|
'sensitive' => 'as:sensitive',
|
2018-07-31 02:33:37 +09:00
|
|
|
'movedTo' => { '@id' => 'as:movedTo', '@type' => '@id' },
|
2018-12-29 10:24:36 +09:00
|
|
|
'alsoKnownAs' => { '@id' => 'as:alsoKnownAs', '@type' => '@id' },
|
2017-09-03 06:13:35 +09:00
|
|
|
'Hashtag' => 'as:Hashtag',
|
|
|
|
'ostatus' => 'http://ostatus.org#',
|
|
|
|
'atomUri' => 'ostatus:atomUri',
|
|
|
|
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
|
|
|
|
'conversation' => 'ostatus:conversation',
|
2017-09-19 12:05:48 +09:00
|
|
|
'toot' => 'http://joinmastodon.org/ns#',
|
|
|
|
'Emoji' => 'toot:Emoji',
|
2018-02-22 08:35:46 +09:00
|
|
|
'focalPoint' => { '@container' => '@list', '@id' => 'toot:focalPoint' },
|
2018-07-31 02:33:37 +09:00
|
|
|
'featured' => { '@id' => 'toot:featured', '@type' => '@id' },
|
2018-04-14 19:41:08 +09:00
|
|
|
'schema' => 'http://schema.org#',
|
|
|
|
'PropertyValue' => 'schema:PropertyValue',
|
|
|
|
'value' => 'schema:value',
|
2017-09-02 21:01:23 +09:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}.freeze
|
|
|
|
|
2017-07-15 10:01:39 +09:00
|
|
|
def self.default_key_transform
|
|
|
|
:camel_lower
|
|
|
|
end
|
|
|
|
|
2017-08-13 00:41:03 +09:00
|
|
|
def self.transform_key_casing!(value, _options)
|
|
|
|
ActivityPub::CaseTransform.camel_lower(value)
|
|
|
|
end
|
|
|
|
|
2017-07-15 10:01:39 +09:00
|
|
|
def serializable_hash(options = nil)
|
|
|
|
options = serialization_options(options)
|
2017-09-12 07:16:18 +09:00
|
|
|
serialized_hash = ActiveModelSerializers::Adapter::Attributes.new(serializer, instance_options).serializable_hash(options)
|
|
|
|
CONTEXT.merge(self.class.transform_key_casing!(serialized_hash, instance_options))
|
2017-07-15 10:01:39 +09:00
|
|
|
end
|
|
|
|
end
|