Class: DMAO::API::Dataset

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

Constant Summary collapse

ENDPOINT =
'datasets'
NOT_FOUND_ERROR =
DMAO::API::Errors::DatasetNotFound
INVALID_ID_ERROR =
DMAO::API::Errors::InvalidDatasetID
INVALID_ENTITY_CLASS =
DMAO::API::Errors::InvalidDataset
INVALID_ENTITY_ERROR_MESSAGE =
"Invalid dataset details, please see errors."
VALID_ATTRIBUTES =
[
    :id,
    :institution_id,
    :permanent_id,
    :title,
    :description,
    :publisher,
    :access,
    :notes,
    :creation_date,
    :system_uuid,
    :system_modified_at,
    :project_id,
    :owning_unit_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) ⇒ Dataset

Returns a new instance of Dataset.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dmao/api/dataset.rb', line 37

def initialize(attributes)

  @id = attributes[:id]
  @institution_id = attributes[:institution_id]
  @permanent_id = attributes[:permanent_id]
  @title = attributes[:title]
  @description = attributes[:description]
  @publisher = attributes[:publisher]
  @access = attributes[:access]
  @notes = attributes[:notes]
  @creation_date = attributes[:creation_date]
  @system_uuid = attributes[:system_uuid]
  @system_modified_at = attributes[:system_modified_at]
  @project_id = attributes[:project_id]
  @owning_unit_id = attributes[:owning_unit_id]

end

Class Method Details

.handle_unprocessable_entity(error_response) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/dmao/api/dataset.rb', line 77

def self.handle_unprocessable_entity error_response

  errors = parse_error_response error_response

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

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


end

.instance_from_api_data(data) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dmao/api/dataset.rb', line 55

def self.instance_from_api_data data

  attributes = {
      id: data["id"],
      institution_id: data["relationships"]["institution"]["data"]["id"],
      permanent_id: data["attributes"]["permanent-id"],
      title: data["attributes"]["title"],
      description: data["attributes"]["description"],
      publisher: data["attributes"]["publisher"],
      access: data["attributes"]["access"],
      notes: data["attributes"]["notes"],
      creation_date: data["attributes"]["creation-date"],
      system_uuid: data["attributes"]["system-uuid"],
      system_modified_at: data["attributes"]["system-modified-at"],
      project_id: data["relationships"]["project"]["data"]["id"],
      owning_unit_id: data["relationships"]["owning-unit"]["data"]["id"]
  }

  new(attributes)

end