Module: Hyrax::API

Defined in:
app/controllers/concerns/hyrax/api.rb,
app/controllers/hyrax/api/items_controller.rb,
app/controllers/hyrax/api/zotero_controller.rb

Defined Under Namespace

Classes: ItemsController, ZoteroController

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/hyrax/api.rb', line 12

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