Module: Virtuatable::API::Responses
- Included in:
- Controllers::Base
- Defined in:
- lib/virtuatable/api/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_empty ⇒ Object
Displays an empty body with a 204 status code.
-
#api_item(item) ⇒ Object
Displays an item with the standards of the API.
-
#api_list(items, mapper = :to_h) ⇒ 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/virtuatable/api/responses.rb', line 23 def api_created(item) halt 201, enhanced_json(item) end |
#api_empty ⇒ Object
Displays an empty body with a 204 status code
40 41 42 |
# File 'lib/virtuatable/api/responses.rb', line 40 def api_empty halt 204, '' end |
#api_item(item) ⇒ Object
Displays an item with the standards of the API.
29 30 31 |
# File 'lib/virtuatable/api/responses.rb', line 29 def api_item(item) halt 200, enhanced_json(item) end |
#api_list(items, mapper = :to_h) ⇒ 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/virtuatable/api/responses.rb', line 13 def api_list(items, mapper = :to_h) halt 200, { count: items.count, items: items.map { |item| enhanced_h(item, mapper.to_sym) } }.to_json end |
#api_ok(message) ⇒ Object
Displays a message with a 200 status code
35 36 37 |
# File 'lib/virtuatable/api/responses.rb', line 35 def api_ok() api_item message: end |