require 'dmao/api/entity' require 'dmao/api/errors/invalid_person' require 'dmao/api/errors/invalid_person_id' require 'dmao/api/errors/person_not_found' module DMAO module API class Person < Entity 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] attr_reader(*VALID_ATTRIBUTES) 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 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 end end end