class DMAO::API::ProjectParticipant

Constants

ENDPOINT
INVALID_ENTITY_CLASS
INVALID_ENTITY_ERROR_MESSAGE
INVALID_ID_ERROR
NOT_FOUND_ERROR
VALID_ATTRIBUTES

Public Class Methods

find_by_system_uuid(_system_uuid) click to toggle source
# File lib/dmao/api/project_participant.rb, line 62
def self.find_by_system_uuid _system_uuid
  raise DMAO::API::Errors::UnsupportedQueryBySystemUUID.new
end
find_project_participant(project_id, participant_id) click to toggle source
# File lib/dmao/api/project_participant.rb, line 66
def self.find_project_participant project_id, participant_id

  response = self.api["#{self::ENDPOINT}?project=#{project_id}&person=#{participant_id}"].get

  response_data = JSON.parse(response)["data"]

  raise self::NOT_FOUND_ERROR.new if response_data.length == 0
  raise DMAO::API::Errors::InvalidResponseLength.new("Expected 1 element in response there were #{response_data.length}") if response_data.length != 1

  data = response_data[0]

  instance_from_api_data data

end
handle_unprocessable_entity(error_response) click to toggle source
# File lib/dmao/api/project_participant.rb, line 48
def self.handle_unprocessable_entity error_response

  errors = parse_error_response error_response

  raise DMAO::API::Errors::InvalidProjectParticipant.new("Invalid project participant details, please see errors.", errors) if (errors.keys.include?("project") && errors.keys.include?("person"))

  raise_error_if_key DMAO::API::Errors::InvalidProjectID, errors, "project"
  raise_error_if_key DMAO::API::Errors::InvalidPersonID, errors, "person"

  raise DMAO::API::Errors::InvalidProjectParticipant.new("Invalid project participant details, please see errors.", errors)


end
instance_from_api_data(data) click to toggle source
# File lib/dmao/api/project_participant.rb, line 34
def self.instance_from_api_data data

  attributes = {
      id: data["id"],
      institution_id: data["relationships"]["institution"]["data"]["id"],
      role: data["attributes"]["role"],
      project_id: data["relationships"]["project"]["data"]["id"],
      participant_id: data["relationships"]["person"]["data"]["id"]
  }

  new(attributes)

end
new(attributes) click to toggle source
# File lib/dmao/api/project_participant.rb, line 24
def initialize(attributes)

  @id = attributes[:id]
  @institution_id = attributes[:institution_id]
  @role = attributes[:role]
  @project_id = attributes[:project_id]
  @participant_id = @person_id = attributes[:participant_id]

end