Class: DMAO::API::ProjectParticipant
- Inherits:
-
Entity
show all
- Defined in:
- lib/dmao/api/project_participant.rb
Constant Summary
collapse
- ENDPOINT =
'project_participants'
- NOT_FOUND_ERROR =
DMAO::API::Errors::ProjectParticipantNotFound
- INVALID_ID_ERROR =
DMAO::API::Errors::InvalidProjectParticipantID
- INVALID_ENTITY_CLASS =
DMAO::API::Errors::InvalidProjectParticipant
- INVALID_ENTITY_ERROR_MESSAGE =
"Invalid project participant details, please see errors."
- VALID_ATTRIBUTES =
[:id, :institution_id, :role, :project_id, :participant_id, :person_id]
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Entity
all, create, delete, get, 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
Returns a new instance of ProjectParticipant.
24
25
26
27
28
29
30
31
32
|
# 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
|
Class Method Details
.find_by_system_uuid(_system_uuid) ⇒ Object
.find_project_participant(project_id, participant_id) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# 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) ⇒ Object
.instance_from_api_data(data) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# 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
|