Module: Core::Helpers::Responses
- Included in:
- Controllers::Base
- Defined in:
- lib/core/helpers/responses.rb
Overview
Modules holding the responses that are NOT errors.
Instance Method Summary collapse
-
#api_created(item) ⇒ Object
Displays a creation standard response, returning the informations about the created item.
-
#api_item(item) ⇒ Object
Displays an item with the standards of the API.
-
#api_list(items) ⇒ Object
Builds a list of items as a standard API response.
-
#api_ok(message) ⇒ Object
Displays a message with a 200 status code.
Instance Method Details
#api_created(item) ⇒ Object
Displays a creation standard response, returning the informations about the created item.
23 24 25 |
# File 'lib/core/helpers/responses.rb', line 23 def api_created(item) halt 201, enhanced_json(item) end |
#api_item(item) ⇒ Object
Displays an item with the standards of the API.
29 30 31 |
# File 'lib/core/helpers/responses.rb', line 29 def api_item(item) halt 200, enhanced_json(item) end |
#api_list(items) ⇒ Object
Builds a list of items as a standard API response. The response will be a JSON hash containing two keys :
-
:count will hold the number of items displayed in the list
-
:items will hold the list of items.
13 14 15 16 17 18 |
# File 'lib/core/helpers/responses.rb', line 13 def api_list(items) halt 200, { count: items.count, items: items.map { |item| enhanced_h(item) } }.to_json end |
#api_ok(message) ⇒ Object
Displays a message with a 200 status code
35 36 37 |
# File 'lib/core/helpers/responses.rb', line 35 def api_ok() api_item message: end |