Sha256: 4b1d23e48dc841e4a02380447008c3dc3a5b8739aaa86934f83bf5aa3d0b27e5

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require_relative "metadata"

module Ezid
  class Identifier

    class << self
      def create(id, metadata=nil)
        response = Client.create_identifier(id, metadata)
        Identifier.new(response.identifier)
      end

      def mint(metadata=nil)
        response = Client.mint_identifier(metadata)
        identifier = Identifier.new(response.identifier)
      end

      def find(id)
        response = Client.get_identifier_metadata(id)
        Identifier.new(response.identifier, response.metadata)
      end
    end

    attr_reader :id

    def initialize(id, metadata=nil)
      @id = id
      @metadata = Metadata.new(metadata)
    end

    def metadata
      reload if @metadata.empty?
      @metadata
    end

    def reload
      response = client.get_identifier_metadata(id)
      @metadata.update(response.metadata)
      self
    end

    def client
      @client ||= Client.new
    end

    def save
      response = client.modify_identifier(id, metadata)
      response.success?
    end

    def delete
      response = client.delete_identifier(id)
      response.success?
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ezid-client-0.1.0 lib/ezid/identifier.rb