Module: ActionFigure::Formatters::JsonApi
- Includes:
- ActionFigure::Formatter
- Defined in:
- lib/action_figure/formatters/json_api.rb,
lib/action_figure/formatters/json_api/resource.rb,
sig/action_figure.rbs
Overview
JSON:API-formatted responses
Defined Under Namespace
Classes: Resource
Constant Summary
Constants included from ActionFigure::Formatter
ActionFigure::Formatter::REQUIRED_METHODS
Instance Method Summary collapse
- #Accepted(resource: nil, meta: nil) ⇒ ActionFigure::response
- #Created(resource:, meta: nil) ⇒ ActionFigure::response
- #error_response(errors:, status:) ⇒ ActionFigure::response
- #Ok(resource:, meta: nil) ⇒ ActionFigure::response
Methods included from ActionFigure::Formatter
Methods included from ErrorRegistry::Helpers
#Conflict, #Forbidden, #Gone, #Locked, #NotFound, #PaymentRequired, #UnavailableForLegalReasons, #UnprocessableContent
Instance Method Details
#Accepted(resource: nil, meta: nil) ⇒ ActionFigure::response
23 24 25 26 27 |
# File 'lib/action_figure/formatters/json_api.rb', line 23 def Accepted(resource: nil, meta: nil) body = resource.nil? ? {} : { data: Resource.serialize(resource) } body[:meta] = if { json: body, status: :accepted } end |
#Created(resource:, meta: nil) ⇒ ActionFigure::response
17 18 19 20 21 |
# File 'lib/action_figure/formatters/json_api.rb', line 17 def Created(resource:, meta: nil) body = { data: Resource.serialize(resource) } body[:meta] = if { json: body, status: :created } end |
#error_response(errors:, status:) ⇒ ActionFigure::response
29 30 31 32 |
# File 'lib/action_figure/formatters/json_api.rb', line 29 def error_response(errors:, status:) code = ActionFigure.status_code_for(status).to_s { json: { errors: convert_errors(errors, code) }, status: status } end |