class DMAO::API::OrganisationUnit

Constants

ENDPOINT
INVALID_ENTITY_CLASS
INVALID_ENTITY_ERROR_MESSAGE
INVALID_ID_ERROR
NOT_FOUND_ERROR
VALID_ATTRIBUTES

Public Class Methods

handle_unprocessable_entity(error_response) click to toggle source
# File lib/dmao/api/organisation_unit.rb, line 61
def self.handle_unprocessable_entity error_response

  errors = parse_error_response error_response

  raise_error_if_key DMAO::API::Errors::InvalidParentId, errors, "parent"

  raise DMAO::API::Errors::InvalidOrganisationUnit.new("Invalid organisation unit details, please see errors.", errors)

end
instance_from_api_data(data) click to toggle source
# File lib/dmao/api/organisation_unit.rb, line 40
def self.instance_from_api_data data

  parent_id = set_id_attribute_if_not_nil data["relationships"]["parent"]["data"]

  attributes = {
      id: data["id"],
      institution_id: data["relationships"]["institution"]["data"]["id"],
      name: data["attributes"]["name"],
      description: data["attributes"]["description"],
      url: data["attributes"]["url"],
      system_uuid: data["attributes"]["system-uuid"],
      system_modified_at: data["attributes"]["system-modified-at"],
      isni: data["attributes"]["isni"],
      unit_type: data["attributes"]["unit-type"],
      parent_id: parent_id
  }

  new(attributes)

end
new(attributes) click to toggle source
# File lib/dmao/api/organisation_unit.rb, line 22
def initialize(attributes)

  @id = attributes[:id]
  @institution_id = attributes[:institution_id]
  @name = attributes[:name]
  @description = attributes[:description]
  @url = attributes[:url]
  @system_uuid = attributes[:system_uuid]
  @system_modified_at = attributes[:system_modified_at]
  @isni = attributes[:isni]
  @unit_type = attributes[:unit_type]

  if attributes[:parent_id]
    @parent_id = attributes[:parent_id]
  end

end