Class: Datacite::Mds Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/datacite_mds.rb

Overview

This class is abstract.

Wraps up Mds functionality wihin an object

Author:

  • Fred Heath

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Mds

Note:

If :authorize is not passed as an option , then the method will look for the usrname and password in environment variables DATACITE_USR and DATACITE_PWD.

creates a new Mds object, passing an options hash

Options Hash (**options):

  • :authorize (Hash)

    Authorization includes two keys :usr [String], :pwd [String]

  • :test_mode (String)

    If true, all API calls to Datacite will occur in test mode

Since:

  • 0.1.0


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/datacite_mds.rb', line 37

def initialize(**options)
  if options[:authorize]
    @username = options[:authorize][:usr]
    @passwd = options[:authorize][:pwd]
  else
    @username = ENV['DATACITE_USR']
    @passwd = ENV['DATACITE_PWD']
  end
  @test_mode = options[:testing] ? '?testMode=true' : ''
  @uri = URI.parse(ENDPOINT)

end

Instance Attribute Details

#httpNet::HTTP

the object wrapping up the http connection to Datacite Endpoint


23
24
25
# File 'lib/datacite_mds.rb', line 23

def http
  @http
end

#passwdString

the Datacentre's authorised password


23
24
25
# File 'lib/datacite_mds.rb', line 23

def passwd
  @passwd
end

#test_modeBoolean

indicates whether to make APi calls in test mode


23
24
25
# File 'lib/datacite_mds.rb', line 23

def test_mode
  @test_mode
end

#uriURI

the object wrapping up the Datacite Endpoint


23
24
25
# File 'lib/datacite_mds.rb', line 23

def uri
  @uri
end

#usernameString

the Datacentre's authorised username


23
24
25
# File 'lib/datacite_mds.rb', line 23

def username
  @username
end

Instance Method Details

#get_all_doisNet::HTTPResponse

Note:

There is no guaranteed order in the list of DOIs

Returns a list of all DOIs for the requesting datacentre

Since:

  • 0.1.0


67
68
69
70
71
72
# File 'lib/datacite_mds.rb', line 67

def get_all_dois
  @uri.path = RESOURCES[:doi]
  @http = Net::HTTP.new(@uri.host, @uri.port)
  request = Net::HTTP::Get.new(@uri.request_uri)
  call_datacite(request)
end

#get_metadata(doi) ⇒ Net::HTTPResponse

Returns the most recent version of metadata associated with the DOI.

Since:

  • 0.1.0


120
121
122
123
124
125
# File 'lib/datacite_mds.rb', line 120

def (doi)
  @uri.path = RESOURCES[:metadata] + '/' + doi
  @http = Net::HTTP.new(@uri.host, @uri.port)
  request = Net::HTTP::Get.new(@uri.request_uri)
  call_datacite(request)
end

#mint(doi, url) ⇒ Net::HTTPResponse

Will mint new DOI if specified DOI doesn't exist. This method will attempt to update URL if you specify existing DOI. Standard domains and quota restrictions check will be performed by Datacite.

Since:

  • 0.1.0


83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/datacite_mds.rb', line 83

def mint(doi, url)
  @uri.path = RESOURCES[:doi]
  @http = Net::HTTP.new(@uri.host, @uri.port)

  request = Net::HTTP::Post.new(@uri.request_uri)
  @uri.query = @test_mode unless @test_mode.empty?

  request.content_type = 'text/plain'
  request.set_form_data({doi: doi, url: url})

  call_datacite(request)
end

#resolve(doi) ⇒ Net::HTTPResponse

Returns a url associated with a given DOI

Since:

  • 0.1.0


55
56
57
58
59
60
# File 'lib/datacite_mds.rb', line 55

def resolve(doi)
  @uri.path = RESOURCES[:doi] + '/' + doi
  @http = Net::HTTP.new(@uri.host, @uri.port)
  request = Net::HTTP::Get.new(@uri.request_uri)
  call_datacite(request)
end

#upload_metadata(xml_string) ⇒ Net::HTTPResponse

Stores new version of metadata.

Since:

  • 0.1.0


102
103
104
105
106
107
108
109
110
111
# File 'lib/datacite_mds.rb', line 102

def (xml_string)
  @uri.path = RESOURCES[:metadata]
  @http = Net::HTTP.new(@uri.host, @uri.port)

  @uri.query = @test_mode unless @test_mode.empty?
  request = Net::HTTP::Post.new(@uri.request_uri)
  request.content_type = 'application/xml'
  request.body = xml_string
  call_datacite(request)
end