Sha256: 5bd01bfa3d5008b9671942dc90e807c8a62dc1c51a014f746d6e2001f33f9c48

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

require 'rest-client'

class Datacite
  ENDPOINT = 'https://mds.datacite.org'

  def initialize(user_name, password, endpoint=nil)
    endpoint ||= ENDPOINT
    @endpoint = RestClient::Resource.new(endpoint, user_name, password)
  end

  def resolve doi
    begin
      response = @endpoint["doi/#{doi}"].get
    rescue Exception => e
      e.message
    end
  end

  def mint doi, url
    begin
      response = @endpoint['doi'].post "doi=#{doi}\nurl=#{url}", content_type: "text/plain;charset=UTF-8"
    rescue Exception => e
      e.message
    end
  end

  def upload_metadata metadata
    begin
      response = @endpoint['metadata'].post(metadata,content_type: 'application/xml;charset=UTF-8')
    rescue Exception => e
      e.message
    end
  end

  def metadata doi
    begin
      response = @endpoint["metadata/#{doi}"].get
    rescue Exception => e
      e.message
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datacite_doi_ify-1.0.0 lib/datacite_doi_ify/datacite.rb