Class: DMAO::API::Project

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

Constant Summary collapse

ENDPOINT =
'projects'
NOT_FOUND_ERROR =
DMAO::API::Errors::ProjectNotFound
INVALID_ID_ERROR =
DMAO::API::Errors::InvalidProjectID
INVALID_ENTITY_CLASS =
DMAO::API::Errors::InvalidProject
INVALID_ENTITY_ERROR_MESSAGE =
"Invalid project details, please see errors."
VALID_ATTRIBUTES =
[
    :id,
    :institution_id,
    :title,
    :acronym,
    :description,
    :status,
    :project_type,
    :classification,
    :internal_project_code,
    :url,
    :start_date,
    :end_date,
    :system_uuid,
    :system_modified_at,
    :owning_unit_id,
    :funder_id
]

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) ⇒ Project

Returns a new instance of Project.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dmao/api/project.rb', line 39

def initialize(attributes)

  @id = attributes[:id]
  @institution_id = attributes[:institution_id]
  @title = attributes[:title]
  @acronym = attributes[:acronym]
  @description = attributes[:description]
  @status = attributes[:status]
  @project_type = attributes[:project_type]
  @classification = attributes[:classification]
  @internal_project_code = attributes[:internal_project_code]
  @url = attributes[:url]
  @start_date = attributes[:start_date]
  @end_date = attributes[:end_date]
  @system_uuid = attributes[:system_uuid]
  @system_modified_at = attributes[:system_modified_at]
  @owning_unit_id = attributes[:owning_unit_id]
  @funder_id = attributes[:funder_id]

end

Class Method Details

.handle_unprocessable_entity(error_response) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/dmao/api/project.rb', line 87

def self.handle_unprocessable_entity error_response

  errors = parse_error_response error_response

  raise_error_if_key DMAO::API::Errors::InvalidOrganisationUnitID, errors, "owning_unit"

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


end

.instance_from_api_data(data) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dmao/api/project.rb', line 60

def self.instance_from_api_data data

  funder_id = set_id_attribute_if_not_nil data["relationships"]["funder"]["data"]

  attributes = {
      id: data["id"],
      institution_id: data["relationships"]["institution"]["data"]["id"],
      title: data["attributes"]["title"],
      acronym: data["attributes"]["acronym"],
      description: data["attributes"]["description"],
      status: data["attributes"]["status"],
      project_type: data["attributes"]["project-type"],
      classification: data["attributes"]["classification"],
      internal_project_code: data["attributes"]["internal-project-code"],
      url: data["attributes"]["url"],
      start_date: data["attributes"]["start-date"],
      end_date: data["attributes"]["end-date"],
      system_uuid: data["attributes"]["system-uuid"],
      system_modified_at: data["attributes"]["system-modified-at"],
      owning_unit_id: data["relationships"]["owning-unit"]["data"]["id"],
      funder_id: funder_id
  }

  new(attributes)

end