Class: DMAO::API::DMP

Inherits:
Entity show all
Defined in:
lib/dmao/api/dmp.rb

Constant Summary collapse

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]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

all, create, delete, find_by_system_uuid, 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

#initialize(attributes) ⇒ DMP

Returns a new instance of DMP.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dmao/api/dmp.rb', line 21

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

Class Method Details

.handle_unprocessable_entity(error_response) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/dmao/api/dmp.rb', line 48

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

.instance_from_api_data(data) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dmao/api/dmp.rb', line 33

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