Module: CurationConcerns::API

Defined in:
app/controllers/concerns/curation_concerns/api.rb

Class Method Summary collapse

Class Method Details

.default_responsesObject

Default (json) responses for various response types



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/concerns/curation_concerns/api.rb', line 12

def self.default_responses
  {
    success: {
      code: 200,
      message: "Request Succeeded",
      description: I18n.t('curation_concerns.api.success.default')
    },
    deleted: {
      code: 200,
      message: I18n.t('curation_concerns.api.deleted.default')
    },
    created: {
      code: 201,
      message: "Created the Resource"
    },
    accepted: {
      code: 202,
      message: "Accepted",
      description: I18n.t('curation_concerns.api.accepted.default')
    },
    bad_request: {
      code: 400,
      message: "Bad Request",
      description: I18n.t('curation_concerns.api.bad_request.default')
    },
    unauthorized: {
      code: 401,
      message: "Authentication Required",
      description: I18n.t('curation_concerns.api.unauthorized.default')
    },
    forbidden: {
      code: 403,
      message: "Not Authorized",
      description: I18n.t('curation_concerns.api.forbidden.default')
    },
    not_found: {
      code: 404,
      message: "Resource not found",
      description: I18n.t('curation_concerns.api.not_found.default')
    },
    unprocessable_entity: {
      code: 422,
      message: "Unprocessable Entity",
      description: I18n.t('curation_concerns.api.unprocessable_entity.default'),
      errors: {}
    },
    internal_error: {
      code: 500,
      message: "Internal Server Error",
      description: I18n.t('curation_concerns.api.internal_error.default')
    }
  }
end

.generate_response_body(response_type: :success, message: nil, options: {}) ⇒ Object

Generate appropriate json response for response_type



5
6
7
8
9
# File 'app/controllers/concerns/curation_concerns/api.rb', line 5

def self.generate_response_body(response_type: :success, message: nil, options: {})
  json_body = default_responses[response_type].merge(options)
  json_body[:description] = message if message
  json_body
end