2017-07-15 04:01:39 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::Adapter < ActiveModelSerializers::Adapter::Base
|
2017-09-02 15:01:23 +03:00
|
|
|
CONTEXT = {
|
|
|
|
'@context': [
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
|
|
|
|
{
|
|
|
|
'locked' => 'as:locked',
|
|
|
|
'sensitive' => 'as:sensitive',
|
|
|
|
'Hashtag' => 'as:Hashtag',
|
|
|
|
|
|
|
|
'ostatus' => 'http://ostatus.org#',
|
|
|
|
'atomUri' => 'ostatus:atomUri',
|
|
|
|
'inReplyToAtomUri' => 'ostatus:inReplyToAtomUri',
|
|
|
|
'conversation' => 'ostatus:conversation',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}.freeze
|
|
|
|
|
2017-07-15 04:01:39 +03:00
|
|
|
def self.default_key_transform
|
|
|
|
:camel_lower
|
|
|
|
end
|
|
|
|
|
2017-08-12 18:41:03 +03:00
|
|
|
def self.transform_key_casing!(value, _options)
|
|
|
|
ActivityPub::CaseTransform.camel_lower(value)
|
|
|
|
end
|
|
|
|
|
2017-07-15 04:01:39 +03:00
|
|
|
def serializable_hash(options = nil)
|
|
|
|
options = serialization_options(options)
|
2017-09-02 15:01:23 +03:00
|
|
|
serialized_hash = CONTEXT.merge(ActiveModelSerializers::Adapter::Attributes.new(serializer, instance_options).serializable_hash(options))
|
2017-07-15 04:01:39 +03:00
|
|
|
self.class.transform_key_casing!(serialized_hash, instance_options)
|
|
|
|
end
|
|
|
|
end
|