Module: ApiResponser
- Defined in:
- lib/api_responser.rb,
lib/api_responser/railtie.rb
Defined Under Namespace
Classes: Railtie
Instance Method Summary collapse
- #bad_request(debug_message = "", report: false) ⇒ Object
- #conflict ⇒ Object
- #forbidden(debug_message = "", report: false) ⇒ Object
- #gone ⇒ Object
- #internal_server_error(debug_message = "", report: false) ⇒ Object
- #method_not_allowed ⇒ Object
- #not_acceptable ⇒ Object
- #not_implemented ⇒ Object
-
#page_not_found ⇒ Object
Error responses.
- #record_created(records = nil) ⇒ Object
- #record_deleted(records = nil) ⇒ Object
-
#record_index(records, records_count = nil) ⇒ Object
Success responses.
- #record_not_created(message, debug_message = "", report: false) ⇒ Object
- #record_not_deleted(message, debug_message = "", report: false) ⇒ Object
- #record_not_found ⇒ Object
- #record_not_updated(message, debug_message = "", report: false) ⇒ Object
- #record_show(records) ⇒ Object
- #record_updated(records = nil) ⇒ Object
- #service_unavailable ⇒ Object
- #too_many_requests ⇒ Object
- #unauthorized(debug_message = "", message: nil, report: false) ⇒ Object
- #unsupported_media_type ⇒ Object
Instance Method Details
#bad_request(debug_message = "", report: false) ⇒ Object
59 60 61 |
# File 'lib/api_responser.rb', line 59 def bad_request( = "", report:false) error_render(code: 400, message: (__method__, status:"error"), debug_message: , report:report) end |
#conflict ⇒ Object
83 84 85 |
# File 'lib/api_responser.rb', line 83 def conflict error_render(code: 409, message: (__method__, status:"error")) end |
#forbidden(debug_message = "", report: false) ⇒ Object
67 68 69 |
# File 'lib/api_responser.rb', line 67 def forbidden( = "", report:false) error_render(code: 403, message: (__method__, status:"error"), debug_message: , report:report) end |
#gone ⇒ Object
87 88 89 |
# File 'lib/api_responser.rb', line 87 def gone error_render(code: 410, message: (__method__, status:"error")) end |
#internal_server_error(debug_message = "", report: false) ⇒ Object
71 72 73 |
# File 'lib/api_responser.rb', line 71 def internal_server_error( = "", report:false) error_render(code: 500, message: (__method__, status:"error"), debug_message: , report:report) end |
#method_not_allowed ⇒ Object
75 76 77 |
# File 'lib/api_responser.rb', line 75 def method_not_allowed error_render(code: 405, message: (__method__, status:"error")) end |
#not_acceptable ⇒ Object
79 80 81 |
# File 'lib/api_responser.rb', line 79 def not_acceptable error_render(code: 406, message: (__method__, status:"error")) end |
#not_implemented ⇒ Object
100 101 102 |
# File 'lib/api_responser.rb', line 100 def not_implemented error_render(code: 501, message: (__method__, status:"error")) end |
#page_not_found ⇒ Object
Error responses
39 40 41 |
# File 'lib/api_responser.rb', line 39 def page_not_found error_render(code: 404, message: (__method__, status:"error")) end |
#record_created(records = nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/api_responser.rb', line 14 def record_created(records = nil) if records.nil? api_success(code: 201) else success_render(code: 201, message: (__method__, status:"success"), records: records) end end |
#record_deleted(records = nil) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/api_responser.rb', line 30 def record_deleted(records = nil) if records.nil? api_success(code: 204) else success_render(code: 204, message: (__method__, status:"success"), records: records) end end |
#record_index(records, records_count = nil) ⇒ Object
Success responses
6 7 8 |
# File 'lib/api_responser.rb', line 6 def record_index(records, records_count = nil) success_render(code: 200, message: (__method__, status:"success"), records: records, records_count: records_count) end |
#record_not_created(message, debug_message = "", report: false) ⇒ Object
47 48 49 |
# File 'lib/api_responser.rb', line 47 def record_not_created(, = "", report:false) error_render(code: 422, message: (__method__, status:"error", message: ), debug_message: , report:report) end |
#record_not_deleted(message, debug_message = "", report: false) ⇒ Object
55 56 57 |
# File 'lib/api_responser.rb', line 55 def record_not_deleted(, = "", report:false) error_render(code: 500, message: (__method__, status:"error", message: ), debug_message: , report:report) end |
#record_not_found ⇒ Object
43 44 45 |
# File 'lib/api_responser.rb', line 43 def record_not_found error_render(code: 404, message: (__method__, status:"error")) end |
#record_not_updated(message, debug_message = "", report: false) ⇒ Object
51 52 53 |
# File 'lib/api_responser.rb', line 51 def record_not_updated(, = "", report:false) error_render(code: 422, message: (__method__, status:"error", message: ), debug_message: , report:report) end |
#record_show(records) ⇒ Object
10 11 12 |
# File 'lib/api_responser.rb', line 10 def record_show(records) success_render(code: 200, message: (__method__, status:"success"), records: records) end |
#record_updated(records = nil) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/api_responser.rb', line 22 def record_updated(records = nil) if records.nil? api_success(code: 204) else success_render(code: 204, message: (__method__, status:"success"), records: records) end end |
#service_unavailable ⇒ Object
104 105 106 |
# File 'lib/api_responser.rb', line 104 def service_unavailable error_render(code: 503, message: (__method__, status:"error")) end |
#too_many_requests ⇒ Object
95 96 97 |
# File 'lib/api_responser.rb', line 95 def too_many_requests error_render(code: 429, message: (__method__, status:"error")) end |
#unauthorized(debug_message = "", message: nil, report: false) ⇒ Object
63 64 65 |
# File 'lib/api_responser.rb', line 63 def ( = "", message: nil,report:false) error_render(code: 401, message: .nil? ? (__method__, status:"error") : , debug_message: , report:report) end |
#unsupported_media_type ⇒ Object
91 92 93 |
# File 'lib/api_responser.rb', line 91 def unsupported_media_type error_render(code: 415, message: (__method__, status:"error")) end |