Sha256: 52278bb335a16884488887e5d3b3ed10339a1b1b5a2060e4fe1a4847efb543ef

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dmao_api-0.6.0 lib/dmao/api/person.rb
dmao_api-0.5.0 lib/dmao/api/person.rb
dmao_api-0.4.0 lib/dmao/api/person.rb
dmao_api-0.3.0 lib/dmao/api/person.rb