Module: ActionFigure::Formatters::Jsend
Overview
JSend-formatted responses
Constant Summary
ActionFigure::Formatter::REQUIRED_METHODS
Instance Method Summary
collapse
#NoContent
#Conflict, #Forbidden, #Gone, #Locked, #NotFound, #PaymentRequired, #UnavailableForLegalReasons, #UnprocessableContent
Instance Method Details
#Accepted(resource: nil, meta: nil) ⇒ ActionFigure::response
21
22
23
24
25
26
|
# File 'lib/action_figure/formatters/jsend.rb', line 21
def Accepted(resource: nil, meta: nil)
body = { status: "success" }
body[:data] = resource unless resource.nil?
body[:meta] = meta if meta
{ json: body, status: :accepted }
end
|
#Created(resource:, meta: nil) ⇒ ActionFigure::response
15
16
17
18
19
|
# File 'lib/action_figure/formatters/jsend.rb', line 15
def Created(resource:, meta: nil)
body = { status: "success", data: resource }
body[:meta] = meta if meta
{ json: body, status: :created }
end
|
#error_response(errors:, status:) ⇒ ActionFigure::response
28
29
30
|
# File 'lib/action_figure/formatters/jsend.rb', line 28
def error_response(errors:, status:)
{ json: { status: "fail", data: errors }, status: status }
end
|
#Ok(resource:, meta: nil) ⇒ ActionFigure::response
9
10
11
12
13
|
# File 'lib/action_figure/formatters/jsend.rb', line 9
def Ok(resource:, meta: nil)
body = { status: "success", data: resource }
body[:meta] = meta if meta
{ json: body, status: :ok }
end
|