require 'dmao/api/entity' require 'dmao/api/errors/invalid_dmp' require 'dmao/api/errors/invalid_dmp_id' require 'dmao/api/errors/dmp_not_found' module DMAO module API class DMP < Entity ENDPOINT = 'dmps' NOT_FOUND_ERROR = DMAO::API::Errors::DMPNotFound INVALID_ID_ERROR = DMAO::API::Errors::InvalidDMPID INVALID_ENTITY_CLASS = DMAO::API::Errors::InvalidDMP INVALID_ENTITY_ERROR_MESSAGE = "Invalid DMP details, please see errors." VALID_ATTRIBUTES = [:id, :institution_id, :project_id, :reviewed, :url, :system_uuid, :system_modified_at] attr_reader(*VALID_ATTRIBUTES) def initialize(attributes) @id = attributes[:id] @institution_id = attributes[:institution_id] @reviewed = attributes[:reviewed] @url = attributes[:url] @system_uuid = attributes[:system_uuid] @system_modified_at = attributes[:system_modified_at] @project_id = attributes[:project_id] end def self.instance_from_api_data data attributes = { id: data["id"], institution_id: data["relationships"]["institution"]["data"]["id"], reviewed: data["attributes"]["reviewed"], url: data["attributes"]["url"],system_uuid: data["attributes"]["system-uuid"], system_modified_at: data["attributes"]["system-modified-at"], project_id: data["relationships"]["project"]["data"]["id"] } new(attributes) end def self.handle_unprocessable_entity error_response errors = parse_error_response error_response raise_error_if_key DMAO::API::Errors::InvalidProjectID, errors, "project" raise DMAO::API::Errors::InvalidDMP.new("Invalid DMP details, please see errors.", errors) end end end end