Class: Datacite::Mds
- Inherits:
-
Object
- Object
- Datacite::Mds
- Defined in:
- lib/datacite_mds.rb
Overview
Wraps up Mds functionality wihin an object
Instance Attribute Summary collapse
-
#http ⇒ Net::HTTP
the object wrapping up the http connection to Datacite Endpoint.
-
#passwd ⇒ String
the Datacentre’s authorised password.
-
#test_mode ⇒ Boolean
indicates whether to make APi calls in test mode.
-
#uri ⇒ URI
the object wrapping up the Datacite Endpoint.
-
#username ⇒ String
the Datacentre’s authorised username.
Class Method Summary collapse
-
.metadata_valid?(xml_doc) ⇒ Boolean
Validates the passed XML against the Datacite XML schema v3.1.
-
.validation_errors ⇒ Object
Returns the XML parser errors, as set by metadata_valid? class method.
Instance Method Summary collapse
-
#delete_metadata(doi) ⇒ Net::HTTPResponse
Deletes the metadata associated with the DOI.
-
#get_all_dois ⇒ Net::HTTPResponse
Returns a list of all DOIs for the requesting datacentre.
-
#get_metadata(doi) ⇒ Net::HTTPResponse
Returns the most recent version of metadata associated with the DOI.
-
#initialize(**options) ⇒ Mds
constructor
creates a new Mds object, passing an options hash.
-
#mint(doi, url) ⇒ Net::HTTPResponse
Will mint new DOI if specified DOI doesn’t exist.
-
#resolve(doi) ⇒ Net::HTTPResponse
Returns a url associated with a given DOI.
-
#upload_metadata(xml_string) ⇒ Net::HTTPResponse
Stores new version of metadata.
Constructor Details
#initialize(**options) ⇒ Mds
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
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/datacite_mds.rb', line 39 def initialize(**) if [:authorize] @username = [:authorize][:usr] @passwd = [:authorize][:pwd] else @username = ENV['DATACITE_USR'] @passwd = ENV['DATACITE_PWD'] end @test_mode = [:testing] ? '?testMode=true' : '' @uri = URI.parse(ENDPOINT) end |
Instance Attribute Details
#http ⇒ Net::HTTP
the object wrapping up the http connection to Datacite Endpoint
24 25 26 |
# File 'lib/datacite_mds.rb', line 24 def http @http end |
#passwd ⇒ String
the Datacentre’s authorised password
24 25 26 |
# File 'lib/datacite_mds.rb', line 24 def passwd @passwd end |
#test_mode ⇒ Boolean
indicates whether to make APi calls in test mode
24 25 26 |
# File 'lib/datacite_mds.rb', line 24 def test_mode @test_mode end |
#uri ⇒ URI
the object wrapping up the Datacite Endpoint
24 25 26 |
# File 'lib/datacite_mds.rb', line 24 def uri @uri end |
#username ⇒ String
the Datacentre’s authorised username
24 25 26 |
# File 'lib/datacite_mds.rb', line 24 def username @username end |
Class Method Details
.metadata_valid?(xml_doc) ⇒ Boolean
Validates the passed XML against the Datacite XML schema v3.1. Method will first check the well-formedness of the XML string and then validate it against the Schema errors
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/datacite_mds.rb', line 150 def self.(xml_doc) begin doc = Nokogiri::XML(xml_doc) { |config| config.strict } rescue Nokogiri::XML::SyntaxError => e raise ArgumentError, "Badly-formed meta-data XML: #{e.}" end @errors = DATACITE_SCHEMA.validate(doc) @errors.empty? end |
.validation_errors ⇒ Object
Returns the XML parser errors, as set by metadata_valid? class method
164 165 166 |
# File 'lib/datacite_mds.rb', line 164 def self.validation_errors @errors end |
Instance Method Details
#delete_metadata(doi) ⇒ Net::HTTPResponse
Deletes the metadata associated with the DOI.
134 135 136 137 138 139 |
# File 'lib/datacite_mds.rb', line 134 def (doi) @uri.path = RESOURCES[:metadata] + '/' + doi @http = Net::HTTP.new(@uri.host, @uri.port) request = Net::HTTP::Delete.new(@uri.request_uri) call_datacite(request) end |
#get_all_dois ⇒ Net::HTTPResponse
There is no guaranteed order in the list of DOIs
Returns a list of all DOIs for the requesting datacentre
69 70 71 72 73 74 |
# File 'lib/datacite_mds.rb', line 69 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.
122 123 124 125 126 127 |
# File 'lib/datacite_mds.rb', line 122 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.
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/datacite_mds.rb', line 85 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
57 58 59 60 61 62 |
# File 'lib/datacite_mds.rb', line 57 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.
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/datacite_mds.rb', line 104 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 |