docbrown/app/serializers/webhook/article_serializer.rb
Anna Buianova 4c9a40be41 Dispatch events to the webhook endpoints #3715 (#3872)
* Start with webhooks: table and model

* Start with webhooks api

* Start with webhooks api

* Webhook::Event class and events list

* Remove commented callbacks

* Start with sending events to webhook endpoints

* A couple of tests for Articles::Creator

* Send event to webhook endpoint on article destroy

* Dispatch event on article update

* Dispatch event when an article updated from admin

* Spec for the webhook job

* One more test for the dispatch event job

* Integration-like spec for event dispatching to webhook endpoints when creating an article

* Use Addressable::URI to parse endpoint url

* Add oj as a faster fast_jsonapi backend

* Renamed serializers

* Move article serialization out of a model

* Don't allow to create a webhook event with invalid type

* Add fields for ArticleSerializer

* Fix webhook event job specs

* Specify timeout when dispatching events

* Fix webhook job spec

* Change webhook events queue name

* Change serialized article fields for the dispatchable events

* Include user data when serializing an article for webhook event

* Moved decorating out of Webhook::DispatchEvent, fixed most specs

* Fix route in ArticleSerializer

* Move Article decoration to Webhook::PayloadAdapter

* Refactor image url helpers to avoid including helpers into serializer

* Fix specs

* Default url options for production
2019-09-07 13:17:45 -04:00

36 lines
1 KiB
Ruby

module Webhook
class ArticleSerializer
include FastJsonapi::ObjectSerializer
set_type :article
attributes :title, :description, :readable_publish_date, :cached_tag_list, :cached_tag_list_array,
:slug, :path, :url, :comments_count, :positive_reactions_count, :body_markdown
attribute :canonical_url, &:processed_canonical_url
attribute :body_html, &:processed_html
attribute :created_at do |a|
a.created_at.utc.iso8601
end
attribute :edited_at do |a|
a.edited_at&.utc&.iso8601
end
attribute :crossposted_at do |a|
a.crossposted_at&.utc&.iso8601
end
attribute :published_at do |a|
a.published_at&.utc&.iso8601
end
attribute :last_comment_at do |a|
a.last_comment_at&.utc&.iso8601
end
attribute :cover_image do |a|
CloudCoverUrl.new(a.url).call
end
attribute :social_image do |article|
Articles::SocialImage.new(article).url
end
attribute :user do |a|
UserSerializer.new(a.user).serializable_hash
end
end
end