Module: ApiResponser

Defined in:
lib/api_responser.rb,
lib/api_responser/railtie.rb

Defined Under Namespace

Classes: Railtie

Instance Method Summary collapse

Instance Method Details

#bad_request(debug_message = "", report: false) ⇒ Object



59
60
61
# File 'lib/api_responser.rb', line 59

def bad_request(debug_message = "", report:false)
  error_render(code: 400, message: i18n_message(__method__, status:"error"), debug_message: debug_message, report:report)
end

#conflictObject



83
84
85
# File 'lib/api_responser.rb', line 83

def conflict
  error_render(code: 409, message: i18n_message(__method__, status:"error"))
end

#forbidden(debug_message = "", report: false) ⇒ Object



67
68
69
# File 'lib/api_responser.rb', line 67

def forbidden(debug_message = "", report:false)
  error_render(code: 403, message: i18n_message(__method__, status:"error"), debug_message: debug_message, report:report)
end

#goneObject



87
88
89
# File 'lib/api_responser.rb', line 87

def gone
  error_render(code: 410, message: i18n_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(debug_message = "", report:false)
  error_render(code: 500, message: i18n_message(__method__, status:"error"), debug_message: debug_message, report:report)
end

#method_not_allowedObject



75
76
77
# File 'lib/api_responser.rb', line 75

def method_not_allowed
  error_render(code: 405, message: i18n_message(__method__, status:"error"))
end

#not_acceptableObject



79
80
81
# File 'lib/api_responser.rb', line 79

def not_acceptable
  error_render(code: 406, message: i18n_message(__method__, status:"error"))
end

#not_implementedObject



100
101
102
# File 'lib/api_responser.rb', line 100

def not_implemented
  error_render(code: 501, message: i18n_message(__method__, status:"error"))
end

#page_not_foundObject

Error responses



39
40
41
# File 'lib/api_responser.rb', line 39

def page_not_found
  error_render(code: 404, message: i18n_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: i18n_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: i18n_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: i18n_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(message, debug_message = "", report:false)
  error_render(code: 422, message: i18n_message(__method__, status:"error", message: message), debug_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(message, debug_message = "", report:false)
  error_render(code: 500, message: i18n_message(__method__, status:"error", message: message), debug_message: debug_message, report:report)
end

#record_not_foundObject



43
44
45
# File 'lib/api_responser.rb', line 43

def record_not_found
  error_render(code: 404, message: i18n_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(message, debug_message = "", report:false)
  error_render(code: 422, message: i18n_message(__method__, status:"error", message: message), debug_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: i18n_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: i18n_message(__method__, status:"success"), records: records)
  end
end

#service_unavailableObject



104
105
106
# File 'lib/api_responser.rb', line 104

def service_unavailable
  error_render(code: 503, message: i18n_message(__method__, status:"error"))
end

#too_many_requestsObject



95
96
97
# File 'lib/api_responser.rb', line 95

def too_many_requests
  error_render(code: 429, message: i18n_message(__method__, status:"error"))
end

#unauthorized(debug_message = "", message: nil, report: false) ⇒ Object



63
64
65
# File 'lib/api_responser.rb', line 63

def unauthorized(debug_message = "", message: nil,report:false)
  error_render(code: 401, message: message.nil? ? i18n_message(__method__, status:"error") : message, debug_message: debug_message, report:report)
end

#unsupported_media_typeObject



91
92
93
# File 'lib/api_responser.rb', line 91

def unsupported_media_type
  error_render(code: 415, message: i18n_message(__method__, status:"error"))
end