Sha256: dc9989ca19e9dba41ce3594b79bb2027ff6a55d4b9deccc6c6c382d6c922fe0b

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

require 'dmao/api/entity'
require 'dmao/api/errors/invalid_dmp'
require 'dmao/api/errors/invalid_dmp_id'
require 'dmao/api/errors/dmp_not_found'

module DMAO
  module API

    class DMP < Entity

      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]

      attr_reader(*VALID_ATTRIBUTES)

      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

      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

      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

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dmao_api-0.6.0 lib/dmao/api/dmp.rb
dmao_api-0.5.0 lib/dmao/api/dmp.rb
dmao_api-0.4.0 lib/dmao/api/dmp.rb