Class: DMAO::API::Person

Inherits:
Entity show all
Defined in:
lib/dmao/api/person.rb

Constant Summary collapse

ENDPOINT =
'people'
NOT_FOUND_ERROR =
DMAO::API::Errors::PersonNotFound
INVALID_ID_ERROR =
DMAO::API::Errors::InvalidPersonID
INVALID_ENTITY_CLASS =
DMAO::API::Errors::InvalidPerson
INVALID_ENTITY_ERROR_MESSAGE =
"Invalid person details, please see errors."
VALID_ATTRIBUTES =
[:id, :institution_id, :first_name, :last_name, :email, :image_link, :orcid, :system_uuid, :system_modified_at]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

all, create, delete, find_by_system_uuid, get, handle_unprocessable_entity, 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

#initialize(attributes) ⇒ Person

Returns a new instance of Person.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dmao/api/person.rb', line 21

def initialize(attributes)

  @id = attributes[:id]
  @institution_id = attributes[:institution_id]
  @first_name = attributes[:first_name]
  @last_name = attributes[:last_name]
  @email = attributes[:email]
  @image_link = attributes[:image_link]
  @orcid = attributes[:orcid]
  @system_uuid = attributes[:system_uuid]
  @system_modified_at = attributes[:system_modified_at]

end

Class Method Details

.instance_from_api_data(data) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/dmao/api/person.rb', line 35

def self.instance_from_api_data data

  attributes = {
      id: data["id"],
      institution_id: data["relationships"]["institution"]["data"]["id"],
      first_name: data["attributes"]["first-name"],
      last_name: data["attributes"]["last-name"],
      email: data["attributes"]["email"],
      image_link: data["attributes"]["image-link"],
      orcid: data["attributes"]["orcid"],
      system_uuid: data["attributes"]["system-uuid"],
      system_modified_at: data["attributes"]["system-modified-at"]
  }

  new(attributes)

end