Sha256: 62f1e996d3776e2dc700d8b86002b2143116f4d4851ebe6a0a654a760172a289

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

require 'dmao/api/entity'
require 'dmao/api/errors/invalid_funder'
require 'dmao/api/errors/invalid_funder_id'
require 'dmao/api/errors/funder_not_found'

module DMAO
  module API

    class Funder < Entity

      ENDPOINT = 'funders'
      NOT_FOUND_ERROR = DMAO::API::Errors::FunderNotFound
      INVALID_ID_ERROR = DMAO::API::Errors::InvalidFunderID
      INVALID_ENTITY_CLASS = DMAO::API::Errors::InvalidFunder
      INVALID_ENTITY_ERROR_MESSAGE = "Invalid funder details, please see errors."

      VALID_ATTRIBUTES = [:id, :institution_id, :name, :parent_group, :system_uuid, :system_modified_at]

      attr_reader(*VALID_ATTRIBUTES)

      def initialize(attributes)

        @id = attributes[:id]
        @institution_id = attributes[:institution_id]
        @name = attributes[:name]
        @parent_group = attributes[:parent_group]
        @system_uuid = attributes[:system_uuid]
        @system_modified_at = attributes[:system_modified_at]

      end

      def self.instance_from_api_data data

        attributes = {
            id: data["id"],
            institution_id: data["relationships"]["institution"]["data"]["id"],
            name: data["attributes"]["name"],
            parent_group: data["attributes"]["parent-group"],
            system_uuid: data["attributes"]["system-uuid"],
            system_modified_at: data["attributes"]["system-modified-at"]
        }

        new(attributes)

      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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