datacite_mds 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +34 -0
- data/.travis.yml +12 -0
- data/CHANGES.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/datacite_mds.gemspec +28 -0
- data/lib/datacite_mds/version.rb +3 -0
- data/lib/datacite_mds.rb +174 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bd64bbb6e3ec7cec2258e6df4adc4d8c83a9897e
|
4
|
+
data.tar.gz: 5e769539f9f1c214e64bcf695be715d633666246
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f31cefbef36720d091ca636cacc6ddf01e974304b21b020fa782b93cd8e8bc237b93bf6e1913c78e674d49c7f5c052844535fff81e97f4bb64d2fbf0eaeaa70c
|
7
|
+
data.tar.gz: 3790c4929d5748465bf4e3b0b7dc05ab8ac82974772441c000216ba4d6f42e083aa96510b5eed3a14540bd89eb3fdecdfe0173ac69e5381fbfaff97802625a33
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*~
|
2
|
+
/.bundle/
|
3
|
+
/.yardoc
|
4
|
+
/Gemfile.lock
|
5
|
+
/_yardoc/
|
6
|
+
/coverage/
|
7
|
+
/doc/
|
8
|
+
/pkg/
|
9
|
+
/spec/reports/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
|
13
|
+
### SublimeText ###
|
14
|
+
# cache files for sublime text
|
15
|
+
*.tmlanguage.cache
|
16
|
+
*.tmPreferences.cache
|
17
|
+
*.stTheme.cache
|
18
|
+
|
19
|
+
# workspace files are user-specific
|
20
|
+
*.sublime-workspace
|
21
|
+
|
22
|
+
|
23
|
+
# Simplecov
|
24
|
+
coverage
|
25
|
+
|
26
|
+
|
27
|
+
.ruby-version
|
28
|
+
.ruby-gemset
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
data/.travis.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.5
|
4
|
+
before_install: gem install bundler -v 1.10.5
|
5
|
+
env:
|
6
|
+
global:
|
7
|
+
- secure: RvBfYOK0KzVTku2mRwQKFK4gjiJsXO5lVLdFG2Hj9ecwBkbG10e3yodoe8dKZgfb9MZDXrzsxGL4mgFayWhnyhQIGLSBKbn03XJGuzWQP8ADxdepNneaX1QpPE4oy4TTK5eKucQ7dRnc/FO19DNJeMbf2tOBP1SYHqbWnnJWECKGmUKkwj2wU4e4wi+VUIArsS0/3pOocEr5TGwKlp5WbAaNVNXctUKBwSKfv5pKajXTFD6JafJvehAkTtwcBHgZJKnORvD6MRFdpiKJalfSbM78Vm8Q102+9thTeHm0X0uJPcLRIcb5hk4DkCL62cUdX+2BSyEAGY5vJq4n20HojxpfMZvNUeV6MaCDhxZe6d8BYr4098hN7WQSTyIvihKePL3CoUUB8BhI7P5+CjdVSCU8JtrYdFjDa82d2Q+Jb3ayokVI3rWcmyvTJxWYzB+Tw3Ynlqp+yqN8q1x7VqSnGIVZe+O4YsbvI+6y/FT5jKmkHvPzKIcXMZ3QgT9wXXdlPs/hrq2KlXbVNY5mlAdq7wbetZi7nSBNOR/1vRaPmm2mjMuJm/ENRFnqSBRa+lkK/KAWBXVqmpVOF2C/1dBbiUIDVDcq54esdTcwGTJ0z69x6iiR9tyd2pGgvDyjO/a5P110A8VGw5THowLol8lPeR2nClsx34IAo3f9sm5NpM4=
|
8
|
+
- secure: CXAnNzhkTf6fHXjsIPjHnRv8mcV3UH/JrhDCK8lKE9btIAYC3T5+YLNN5stZw85SDH+RJZhm4pEApK3NfnSHYJrAYSvbBK3NJOiOV0E8NWQJXxtzV1nJM00t3QdrFOQHGJ89aO5Tl18uN0u2bhKoR6EEXHhBrbwyDs7UnSP09+LJU1Z9n4pOCzBOKIch5x8ntq1U31Bj7ukO7DXpbkpQ5uPg8C2U8caitfkSM0LaDBjfzTHFlXzZbbugxdUMMPoBNHe4Jkb8ywyiUWx9BqKovrKf5lRS5v6sKOAPW4hDgKKiCrl5RrMwybzgKNY4rGSAwmmZBi9BOjh42pwghziaG8UEKnBY2npLmmPZNhuck1FJICPbLqklEITRV+uGQZMiJNpbORCnTxQgvlekhJAOFd5CE3ecm2IEU17o4N2ZvjhH1ShJwmUmYWrQRCkcxmtHUv6MAhHv8GyoczqadwTwVgq2iKtdAce1NTyVsWpbaZ4ts28X6K5GaaADI/SA6oPX0OQIWjYFIdjJfCMRJjI98MkIveuwuvzchqz2HEnhJxSBHhhEzp1GgootEhdppWu9yDRx5F5Y6gc/14BKnz0XWYSrqDTD4gsy5vAjbQpi4dQ7oPifwlO4FPfLd6pDMbp/+gR/uAr9GO4LJG9E42GtIStoDhIIWn3RZ1lmVom3yfs=
|
9
|
+
- secure: ExkeHK4548WGp8HhehwO1GtkrJkPkHlLs4cfcKXsh6P5aoD4LbUxL8oF6Cep+EEvLS5qQRQ7f4rnqqHOSi7uckEFT2E8P9wNtPumlmJXtwaCW/Ei4mO6uAVdVhS8WYDypel6k4bSkbEOojDiLy4+USA2Zz8b9QdeZ0AMYkmmZvPjwv3m4PO98AXid44DwrNiEMgahVq6ZUopjv3Am0+3Xx7nnHWt0vGbOovnA+KpekyqL699zq4IG5ygvq1B4K+D2DCw8qKBhR0B6KqOqFeq5PliljrAnmmxpHENdeVxoQGOksy+QdFnq9G093ZBhh/vBReiZr0f3QUM+Zg2ZRzgA7btU0KEcNZtFeDPG0/nwlq1GFUZKOiTfj73vgO5GM9MDhK+JOTh1eW93d5FC0fFC/X26FVc1sW/3OsoadOn5r41QltxItUSkIQU0CG2jVJBYNcFom9xtxFc14duXhavw2cOtaZhOsUfzQQVcAh1W0sWz3y599gPJhmtw9LyedeJeGH5+rVTiiSfRAb8ZeqzCIjQ4cdj2c6kchoe9rT+8XXPeSDtMQBt+Thlm9twusbz74TKaht6UDyCd3bpreACmXwB7JFHjCvD5WgtolzzXsfFC7JloojFny2S9iXdJoebP2Svz4Rq5K7KZCFJPwvP5lmT2hmuRWsWuWWuax8VpVk=
|
10
|
+
- secure: jwich42TwMeoed6WA2QSdZgwdbshxMCbnmfHif54lx2xCxAZ0i45VWHbjn+mOIW6UwX9h5TMVxKtWsJyYNGOB5ZfKQ8i6qgfCpJW5TUHvgYKmhnFcWCGgsRYBcmTHi5Wjoyag/tB4KcoJUzeeMjwJQWKJYM8MP3lOnEYtace6R45P4uaIh8UIw+8fhchivKUYaPJZuiW1NIBYmqMNV34X6GBnCvZFsnEDqbWXedeLiuLKhfJybThFdt7IT/quLTEVEQDBZwleb0jthNSRe2Wtze7ydDVX2YhpUWdStbsMovYlMnysMGmV8bsvPP2k3mqmOY4eLcjxf6EmHHiH95Eafp1j6VZi7rToMUEGwAi2Q8MFwJLtKMLOM/6Lpo9o8AKogyJKCY83CMhzP2GtGhiDAZ2jC4fiLTJuZR3YdF9mSRCJdCHidaKhEi5QvyQQuD5vJkEN9TQQ2HzypsbY2MfdudZqozG2wOFM62TqOeq9w3yvVyiSp6xiaU23v+7qbGwsgbvWBstCMbWmtZbtYLCY6dJrNn2SQTlDrSmh1DWResD/RV7EwF6op2HVtnuF5A8ZmWFhS0Gcor163IOXvFIYDjybIN3HMMa1Ri8wFya1SbdAv6+SY+mi1SQwqrdzqknI3xdUL4RoFbjzFBnqVwXrhKDDj1iSri60TJcwWJjeNI=
|
11
|
+
script:
|
12
|
+
- bundle exec rake test
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015
|
4
|
+
The Chancellor Masters and Scholars of the University of Oxford
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
14
|
+
copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
[![build](https://travis-ci.org/bodleian/datacite_mds.svg)](https://travis-ci.org/bodleian/datacite_mds)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/bodleian/datacite_mds/badge.svg?branch=master&service=github)](https://coveralls.io/github/bodleian/datacite_mds?branch=master)
|
3
|
+
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/bodleian/datacite_mds/blob/master/LICENSE.txt)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
## What is it?
|
8
|
+
|
9
|
+
This gem provides Ruby client connectivity to Datacite's [Metadata store](https://mds.datacite.org/) (MDS). The MDS is a service for data publishers to mint DOIs and register associated metadata. It is aimed mainly at scientific and research data publishers. This gem allows for simple and seamless interaction with the MDS service.
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'datacite_mds'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install datacite_mds
|
26
|
+
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
create an Mds object (explicit authorization)
|
31
|
+
|
32
|
+
mds = Datacite::Mds.new authorize: {usr: "joe bloggs", pwd: "password"}
|
33
|
+
|
34
|
+
create an Mds object (implicit authorization via DATACITE_USR, DATACITE_PWD environment variables)
|
35
|
+
|
36
|
+
mds = Datacite::Mds.new
|
37
|
+
|
38
|
+
create an Mds object for testing (implicit authorization)
|
39
|
+
|
40
|
+
mds = Datacite::Mds.new testing: true
|
41
|
+
|
42
|
+
resolve a DOI
|
43
|
+
|
44
|
+
res = mds.resolve '10.5072/existing-doi'
|
45
|
+
p res # => <Net::HTTPOK 200 OK readbody=true
|
46
|
+
|
47
|
+
upload metadata
|
48
|
+
|
49
|
+
res = mds.upload_metadata File.read('metadata.xml')
|
50
|
+
p res # => <Net::HTTPCreated 201 Created readbody=true>
|
51
|
+
|
52
|
+
|
53
|
+
mint a DOI
|
54
|
+
|
55
|
+
res = mds.mint '10.5072/non-existing-doi', 'http://ora.ox.ac.uk/objects/uuid:<an-existing-uuid>'
|
56
|
+
p res # => <Net::HTTPCreated 201 Created readbody=true>
|
57
|
+
|
58
|
+
|
59
|
+
update dataset for existing DOI
|
60
|
+
|
61
|
+
res = mds.mint '10.5072/existing-doi', 'http://ora.ox.ac.uk/objects/uuid:<new-uuid>'
|
62
|
+
p res # => <Net::HTTPCreated 201 Created readbody=true>
|
63
|
+
|
64
|
+
## Tests
|
65
|
+
|
66
|
+
Minitest is used for testing. To run all tests, you must set the DATACITE_USR, DATACITE_PWD environment variables and then:
|
67
|
+
|
68
|
+
$ rake test
|
69
|
+
|
70
|
+
**Note**: Some of the tests use DOIs and URLs issued to the Bodleian Libraries and can be accessed only by using the Bodleian datacentre authorisation credentials. It is recommended that you substitute these constant variables' values in the test file, with your own datacentre's DOIs and URLs.
|
71
|
+
|
72
|
+
|
73
|
+
## License
|
74
|
+
|
75
|
+
The gem is available as open source under the terms of the [MIT License](https://en.wikipedia.org/wiki/MIT_License), c/o The Chancellor Masters and Scholars of the University of Oxford.
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. Fork the repository
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create new Pull Request
|
84
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
task :console do
|
13
|
+
exec "irb -r datacite_mds -I ./lib"
|
14
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "datacite_mds"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'datacite_mds/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "datacite_mds"
|
8
|
+
spec.version = DataciteMds::VERSION
|
9
|
+
spec.authors = ["Fred Heath", "Michael Davis"]
|
10
|
+
spec.email = ["michael.davis@bodleian.ox.ac.uk"]
|
11
|
+
|
12
|
+
spec.summary = %q{This gem allows for Ruby client connectivity to Datacite's Metadata Store (https://mds.datacite.org/)}
|
13
|
+
spec.description = %q{The MDS is a service for data publishers to mint DOIs and register associated metadata. It is aimed mainly at scientific and research data publishers. This gem allows for simple and seamless interaction with this service.}
|
14
|
+
spec.homepage = "https://github.com/bodleian/datacite_mds"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
spec.add_development_dependency "yard"
|
26
|
+
spec.add_development_dependency "travis"
|
27
|
+
spec.add_development_dependency "coveralls"
|
28
|
+
end
|
data/lib/datacite_mds.rb
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
require "datacite_mds/version"
|
2
|
+
require 'net/http'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
module Datacite
|
6
|
+
|
7
|
+
ENDPOINT = 'https://mds.datacite.org/'
|
8
|
+
RESOURCES = { doi: '/doi', metadata: '/metadata', media: '/media' }
|
9
|
+
|
10
|
+
|
11
|
+
# Wraps up Mds functionality wihin an object
|
12
|
+
#
|
13
|
+
# @author Fred Heath
|
14
|
+
# @abstract
|
15
|
+
# @since 0.1.0
|
16
|
+
# @attr [String] username the Datacentre's authorised username
|
17
|
+
# @attr [String] passwd the Datacentre's authorised password
|
18
|
+
# @attr [Boolean] test_mode indicates whether to make APi calls
|
19
|
+
# in test mode
|
20
|
+
# @attr [URI] uri the object wrapping up the Datacite Endpoint
|
21
|
+
# @attr [Net::HTTP] http the object wrapping up the http
|
22
|
+
# connection to Datacite Endpoint
|
23
|
+
class Mds
|
24
|
+
|
25
|
+
# creates a new Mds object, passing an options hash
|
26
|
+
#
|
27
|
+
# @param options [Hash] the options to create an Mds objects with.
|
28
|
+
# @option options [Hash] :authorize Authorization includes two keys
|
29
|
+
# :usr [String], :pwd [String]
|
30
|
+
# @option options [String] :test_mode If true, all API calls to
|
31
|
+
# Datacite will occur in test mode
|
32
|
+
#
|
33
|
+
# @note If :authorize is not passed as an option , then the method
|
34
|
+
# will look for the usrname and password in environment variables
|
35
|
+
# DATACITE_USR and DATACITE_PWD.
|
36
|
+
#
|
37
|
+
def initialize(**options)
|
38
|
+
if options[:authorize]
|
39
|
+
@username = options[:authorize][:usr]
|
40
|
+
@passwd = options[:authorize][:pwd]
|
41
|
+
else
|
42
|
+
@username = ENV['DATACITE_USR']
|
43
|
+
@passwd = ENV['DATACITE_PWD']
|
44
|
+
end
|
45
|
+
@test_mode = options[:testing] ? '?testMode=true' : ''
|
46
|
+
@uri = URI.parse(ENDPOINT)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns a url associated with a given DOI
|
51
|
+
# @param doi [String] a Data Object identifier
|
52
|
+
# @return [Net::HTTPResponse] Succesful operation will
|
53
|
+
# return HTTPOK and the response body will contain
|
54
|
+
# the URL (String) representing the dataset.
|
55
|
+
def resolve(doi)
|
56
|
+
@uri.path = RESOURCES[:doi] + '/' + doi
|
57
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
58
|
+
request = Net::HTTP::Get.new(@uri.request_uri)
|
59
|
+
call_datacite(request)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns a list of all DOIs for the requesting datacentre
|
63
|
+
# @return [Net::HTTPResponse] Succesful operation will
|
64
|
+
# return HTTPOK and the response body will contain
|
65
|
+
# a list (String) of all relevant DOIs.
|
66
|
+
# @note There is no guaranteed order in the list of DOIs
|
67
|
+
def get_all_dois
|
68
|
+
@uri.path = RESOURCES[:doi]
|
69
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
70
|
+
request = Net::HTTP::Get.new(@uri.request_uri)
|
71
|
+
call_datacite(request)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Will mint new DOI if specified DOI doesn't exist. This method
|
75
|
+
# will attempt to update URL if you specify existing DOI.
|
76
|
+
# Standard domains and quota restrictions check will be
|
77
|
+
# performed by Datacite.
|
78
|
+
# @param doi [String] a Data Object Identifier
|
79
|
+
# @param url [String] the dataset's location
|
80
|
+
# @return [Net::HTTPResponse] Succesful operation will
|
81
|
+
# return HTTPCreated and the response body will
|
82
|
+
# provide a short explanation of the status code.
|
83
|
+
def mint(doi, url)
|
84
|
+
@uri.path = RESOURCES[:doi]
|
85
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
86
|
+
|
87
|
+
request = Net::HTTP::Post.new(@uri.request_uri)
|
88
|
+
@uri.query = @test_mode unless @test_mode.empty?
|
89
|
+
|
90
|
+
request.content_type = 'text/plain'
|
91
|
+
request.set_form_data({doi: doi, url: url})
|
92
|
+
|
93
|
+
call_datacite(request)
|
94
|
+
end
|
95
|
+
|
96
|
+
# Stores new version of metadata.
|
97
|
+
# @param xml_string [String] xml conforming to
|
98
|
+
# https://schema.datacite.org/
|
99
|
+
# @return [Net::HTTPResponse] Succesful operation will
|
100
|
+
# return HTTPCreated and the response body will
|
101
|
+
# provide a short explanation of the status code.
|
102
|
+
def upload_metadata(xml_string)
|
103
|
+
@uri.path = RESOURCES[:metadata]
|
104
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
105
|
+
|
106
|
+
@uri.query = @test_mode unless @test_mode.empty?
|
107
|
+
request = Net::HTTP::Post.new(@uri.request_uri)
|
108
|
+
request.content_type = 'application/xml'
|
109
|
+
request.body = xml_string
|
110
|
+
call_datacite(request)
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
# Returns the most recent version of metadata
|
115
|
+
# associated with the DOI.
|
116
|
+
# @param doi [String] a Data Object identifier
|
117
|
+
# @return [Net::HTTPResponse] Succesful operation will
|
118
|
+
# return HTTPOK and the response body will consist
|
119
|
+
# of XML representing a dataset's metadata.
|
120
|
+
def get_metadata(doi)
|
121
|
+
@uri.path = RESOURCES[:metadata] + '/' + doi
|
122
|
+
@http = Net::HTTP.new(@uri.host, @uri.port)
|
123
|
+
request = Net::HTTP::Get.new(@uri.request_uri)
|
124
|
+
call_datacite(request)
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
# Executes an http request, allowing for redirects (3xx codes)
|
130
|
+
# @private
|
131
|
+
# @param request [Net::HTTPRequest] the request
|
132
|
+
# @param request_limit [FixNum] the number of times to keep
|
133
|
+
# requesting after each redirect
|
134
|
+
# @return [Net::HTTPResponse] the response
|
135
|
+
def fetch(request, http, request_limit = 5)
|
136
|
+
r = http.request(request)
|
137
|
+
|
138
|
+
if r.instance_of? Net::HTTPRedirection
|
139
|
+
raise "Max number of redirects reached" if request_limit <= 0
|
140
|
+
r = fetch(URI.parse(r.header['location']), request_limit - 1)
|
141
|
+
end
|
142
|
+
r
|
143
|
+
end
|
144
|
+
|
145
|
+
# Sets SSL options on Http object
|
146
|
+
# @private
|
147
|
+
# @note this settings are required in order to use the Datacite
|
148
|
+
# API
|
149
|
+
def set_security
|
150
|
+
@http.use_ssl = true
|
151
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
# Will add authorization info to the request, if any exists.
|
156
|
+
# @private
|
157
|
+
# @param request_obj [Net::HTTPRequest] the request
|
158
|
+
def set_authorization(request_obj)
|
159
|
+
request_obj.basic_auth(@username, @passwd) if (@username && @passwd)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Sets security and authorization settings and then executes
|
163
|
+
# the http request.
|
164
|
+
# @private
|
165
|
+
# @param request [Net::HTTPRequest] the request
|
166
|
+
# @return [Net::HTTPResponse] the response
|
167
|
+
def call_datacite(request)
|
168
|
+
set_security
|
169
|
+
set_authorization(request)
|
170
|
+
fetch(request, @http)
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datacite_mds
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fred Heath
|
8
|
+
- Michael Davis
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.10'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.10'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: yard
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: travis
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: coveralls
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description: The MDS is a service for data publishers to mint DOIs and register associated
|
99
|
+
metadata. It is aimed mainly at scientific and research data publishers. This gem
|
100
|
+
allows for simple and seamless interaction with this service.
|
101
|
+
email:
|
102
|
+
- michael.davis@bodleian.ox.ac.uk
|
103
|
+
executables: []
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- ".coveralls.yml"
|
108
|
+
- ".gitignore"
|
109
|
+
- ".travis.yml"
|
110
|
+
- CHANGES.md
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/setup
|
117
|
+
- datacite_mds.gemspec
|
118
|
+
- lib/datacite_mds.rb
|
119
|
+
- lib/datacite_mds/version.rb
|
120
|
+
homepage: https://github.com/bodleian/datacite_mds
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.8
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: This gem allows for Ruby client connectivity to Datacite's Metadata Store
|
144
|
+
(https://mds.datacite.org/)
|
145
|
+
test_files: []
|
146
|
+
has_rdoc:
|