Class: DMAO::API::OrganisationUnit
- Inherits:
-
Entity
show all
- Defined in:
- lib/dmao/api/organisation_unit.rb
Constant Summary
collapse
- ENDPOINT =
'organisation_units'
- NOT_FOUND_ERROR =
DMAO::API::Errors::OrganisationUnitNotFound
- INVALID_ID_ERROR =
DMAO::API::Errors::InvalidOrganisationUnitID
- INVALID_ENTITY_CLASS =
DMAO::API::Errors::InvalidOrganisationUnit
- INVALID_ENTITY_ERROR_MESSAGE =
"Invalid person details, please see errors."
- VALID_ATTRIBUTES =
[:id, :institution_id, :name, :description, :url, :system_uuid, :system_modified_at, :isni, :unit_type, :parent_id]
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Entity
all, create, delete, find_by_system_uuid, get, instance_from_response, parse_error_response, raise_error_if_key, set_id_attribute_if_not_nil, update, validate_attributes, validate_id, validate_system_uuid
Methods inherited from Base
api
Constructor Details
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# 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
|
Class Method Details
.handle_unprocessable_entity(error_response) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# 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) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# 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
|