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

Constant Summary collapse

DEFAULT_RESPONSES =

Generate appropriate json response for response_type

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

Class Method Summary collapse

Class Method Details

.default_responsesObject

Default (json) responses for various response types


65
66
67
# File 'app/controllers/concerns/hyrax/api.rb', line 65

def self.default_responses
  DEFAULT_RESPONSES
end

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


58
59
60
61
62
# File 'app/controllers/concerns/hyrax/api.rb', line 58

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