cirneco 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +57 -0
- data/.travis.yml +17 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +129 -0
- data/LICENSE.md +21 -0
- data/README.md +44 -0
- data/Rakefile +5 -0
- data/bin/cirneco.rb +5 -0
- data/cirneco.gemspec +41 -0
- data/lib/cirneco/api.rb +90 -0
- data/lib/cirneco/base.rb +21 -0
- data/lib/cirneco/cli.rb +28 -0
- data/lib/cirneco/data_center.rb +23 -0
- data/lib/cirneco/doi.rb +33 -0
- data/lib/cirneco/media.rb +15 -0
- data/lib/cirneco/metadata.rb +15 -0
- data/lib/cirneco/utils.rb +28 -0
- data/lib/cirneco/version.rb +3 -0
- data/lib/cirneco/work.rb +206 -0
- data/lib/cirneco.rb +7 -0
- data/resources/kernel-4.0/include/datacite-contributorType-v4.xsd +35 -0
- data/resources/kernel-4.0/include/datacite-dateType-v4.xsd +21 -0
- data/resources/kernel-4.0/include/datacite-descriptionType-v4.xsd +19 -0
- data/resources/kernel-4.0/include/datacite-funderIdentifierType-v4.xsd +15 -0
- data/resources/kernel-4.0/include/datacite-relatedIdentifierType-v4.xsd +32 -0
- data/resources/kernel-4.0/include/datacite-relationType-v4.xsd +39 -0
- data/resources/kernel-4.0/include/datacite-resourceType-v4.xsd +26 -0
- data/resources/kernel-4.0/include/datacite-titleType-v4.xsd +14 -0
- data/resources/kernel-4.0/metadata.xsd +470 -0
- data/resources/kernel-4.0/samples/datacite-example-Box_dateCollected_DataCollector-v4.0.xml +52 -0
- data/resources/kernel-4.0/samples/datacite-example-GeoLocation-v4.0.xml +66 -0
- data/resources/kernel-4.0/samples/datacite-example-HasMetadata-v4.0.xml +62 -0
- data/resources/kernel-4.0/samples/datacite-example-ResearchGroup_Methods-v4.0.xml +44 -0
- data/resources/kernel-4.0/samples/datacite-example-ResourceTypeGeneral_Collection-v4.0.xml +52 -0
- data/resources/kernel-4.0/samples/datacite-example-complicated-v4.0.xml +54 -0
- data/resources/kernel-4.0/samples/datacite-example-dataset-v4.0.xml +39 -0
- data/resources/kernel-4.0/samples/datacite-example-full-v4.0.xml +71 -0
- data/resources/kernel-4.0/samples/datacite-example-fundingReference-v.4.0.xml +59 -0
- data/resources/kernel-4.0/samples/datacite-example-relationTypeIsIdenticalTo-v4.0.xml +65 -0
- data/resources/kernel-4.0/samples/datacite-example-video-v4.0.xml +31 -0
- data/resources/kernel-4.0/samples/datacite-example-workflow-v4.0.xml +55 -0
- data/spec/api_spec.rb +103 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/get/should_get_all_dois_by_prefix.yml +52 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/get/should_get_next_doi.yml +52 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_DataCenter/get/should_get_number_of_latest_doi.yml +52 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_all_dois.yml +52 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_doi.yml +40 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/put/should_put_doi.yml +44 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_Work/Media_API/get/should_get_media.yml +44 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_Work/Media_API/post/should_post_media.yml +42 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/delete/should_delete_metadata.yml +40 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/get/should_get_metadata.yml +60 -0
- data/spec/fixtures/vcr_cassettes/Cirneco_Work/Metadata_API/post/should_post_metadata.yml +62 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/utils_spec.rb +42 -0
- data/spec/work_spec.rb +54 -0
- metadata +401 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91b2c099d3fade3b4caf760314e6c3b35fe09ec3
|
4
|
+
data.tar.gz: 940bf640c48072d50dcbd1f051f4ee42a54b8789
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84ebda4764d474fd4f090e45943c7e7e0d8a7992c5a540559362b1e922035c4fa27c2458ef1f2540055bb0e37f16b0e14044759fc63312be387217dde97b7c95
|
7
|
+
data.tar.gz: bfbf0bf90bbf230a18721c0ae1ca3b8129ce4afe68903c39564dba2e86d1807e030e01abb0a6a19be543ac4274f458f3204b11af95091e1d22c770f706d9d094
|
data/.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
## Specific to RubyMotion:
|
17
|
+
.dat*
|
18
|
+
.repl_history
|
19
|
+
build/
|
20
|
+
*.bridgesupport
|
21
|
+
build-iPhoneOS/
|
22
|
+
build-iPhoneSimulator/
|
23
|
+
|
24
|
+
## Specific to RubyMotion (use of CocoaPods):
|
25
|
+
#
|
26
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
27
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
28
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
29
|
+
#
|
30
|
+
# vendor/Pods/
|
31
|
+
|
32
|
+
## Documentation cache and generated files:
|
33
|
+
/.yardoc/
|
34
|
+
/_yardoc/
|
35
|
+
/doc/
|
36
|
+
/rdoc/
|
37
|
+
|
38
|
+
## Environment normalization:
|
39
|
+
/.bundle/
|
40
|
+
/vendor/bundle
|
41
|
+
/lib/bundler/man/
|
42
|
+
|
43
|
+
# for a library or gem, you might want to ignore these files since the code is
|
44
|
+
# intended to run in multiple environments; otherwise, check them in:
|
45
|
+
# Gemfile.lock
|
46
|
+
# .ruby-version
|
47
|
+
# .ruby-gemset
|
48
|
+
|
49
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
50
|
+
.rvmrc
|
51
|
+
|
52
|
+
coverage/
|
53
|
+
|
54
|
+
.env
|
55
|
+
.env.*
|
56
|
+
!.env.example
|
57
|
+
!.env.travis
|
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.3.1
|
4
|
+
install:
|
5
|
+
- travis_retry bundle install
|
6
|
+
script: bundle exec rspec
|
7
|
+
notifications:
|
8
|
+
slack: "$SLACK_TOKEN"
|
9
|
+
email: false
|
10
|
+
deploy:
|
11
|
+
provider: rubygems
|
12
|
+
api_key:
|
13
|
+
secure: MzTs9T5E7b6GoB6YP5/lzbNZm2EVGrjqM1QCqAAEDRnbUBLZhmuUI2ibcQeaL2QfzAHnbRKywt0UT8LWKqJ6uIS1XVGkWa9mPd2SoT1V3B8yGPqIp7xPCX9T6NeVDL7F5fAZB9k9uN8SbAY8CVN4gseLdYZuwtsTUpAyg87S2EkZvIHIfHeUQz87aDnCR7haN1d0CgcUuJLYDDGknYfkK7sHjJTehTMYEH2tByNhOVzmbmgO2uxUICUxrXpLVf2rXbWvuGqLtz5gf6GcQBIthOAKBGT3pYyHEQoSmu4FJro6lUpoOVEqdGRt2/LghUktuJzIdcfjAKn3YqVO+oFtXj9Kw+ON0H25pqhaEIhct9k9OjQRYHuDFAIHHAzG4+hz0rOvBlpGjiFkbZU4hkUJxnW/ATVNaghMzIjCkueKUplg1bkfpXeLMrb7IeULqOLfwmJirUaxcnVpf0hhVgDbtnaWwotxs9D4UWMZMSPmy2eumxu/NjfgFu5L8fYzm8z6/rbNcKTqQcSthIGCp+e/Sy6dtfd8SdZbtDJoSeA5FCWa6nQcN0lYO0evcAZ3+b6QfY17BEY15X4WHxt7fd6vnm0RjEZbftNFNfzZe08q5DdeRr8Y3DVNDWpqm1i5J3hobQ0lR3RkpLs4qinycaD6fRDBU/ZcvWUZtA+OdCT/YL8=
|
14
|
+
gem: cirneco
|
15
|
+
on:
|
16
|
+
tags: true
|
17
|
+
repo: datacite/cirneco
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/datacite/base32.git
|
3
|
+
revision: 6e80183adae3f98018687e79164fa4970cf4ccbe
|
4
|
+
specs:
|
5
|
+
base32-crockford (0.2.0)
|
6
|
+
|
7
|
+
PATH
|
8
|
+
remote: .
|
9
|
+
specs:
|
10
|
+
cirneco (0.3.1)
|
11
|
+
activesupport (~> 4.2, >= 4.2.5)
|
12
|
+
base32-crockford (~> 0.2.0)
|
13
|
+
builder (~> 3.2, >= 3.2.2)
|
14
|
+
dotenv (~> 2.1, >= 2.1.1)
|
15
|
+
maremma (~> 3.1)
|
16
|
+
namae (~> 0.10.1)
|
17
|
+
nokogiri (~> 1.6, >= 1.6.8)
|
18
|
+
sanitize (~> 4.0, >= 4.0.1)
|
19
|
+
thor (~> 0.19)
|
20
|
+
|
21
|
+
GEM
|
22
|
+
remote: https://rubygems.org/
|
23
|
+
specs:
|
24
|
+
activesupport (4.2.7.1)
|
25
|
+
i18n (~> 0.7)
|
26
|
+
json (~> 1.7, >= 1.7.7)
|
27
|
+
minitest (~> 5.1)
|
28
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
29
|
+
tzinfo (~> 1.1)
|
30
|
+
addressable (2.5.0)
|
31
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
32
|
+
builder (3.2.2)
|
33
|
+
codeclimate-test-reporter (1.0.3)
|
34
|
+
simplecov
|
35
|
+
crack (0.4.3)
|
36
|
+
safe_yaml (~> 1.0.0)
|
37
|
+
crass (1.0.2)
|
38
|
+
diff-lcs (1.2.5)
|
39
|
+
docile (1.1.5)
|
40
|
+
dotenv (2.1.1)
|
41
|
+
excon (0.45.4)
|
42
|
+
faraday (0.9.2)
|
43
|
+
multipart-post (>= 1.2, < 3)
|
44
|
+
faraday-encoding (0.0.4)
|
45
|
+
faraday
|
46
|
+
faraday_middleware (0.10.1)
|
47
|
+
faraday (>= 0.7.4, < 1.0)
|
48
|
+
hashdiff (0.3.1)
|
49
|
+
i18n (0.7.0)
|
50
|
+
json (1.8.3)
|
51
|
+
maremma (3.1)
|
52
|
+
activesupport (~> 4.2, >= 4.2.5)
|
53
|
+
builder (~> 3.2, >= 3.2.2)
|
54
|
+
excon (~> 0.45.0)
|
55
|
+
faraday (~> 0.9.2)
|
56
|
+
faraday-encoding (~> 0.0.1)
|
57
|
+
faraday_middleware (~> 0.10.0)
|
58
|
+
multi_json (~> 1.11.2)
|
59
|
+
nokogiri (~> 1.6.7)
|
60
|
+
oj (~> 2.13.1)
|
61
|
+
mini_portile2 (2.1.0)
|
62
|
+
minitest (5.10.1)
|
63
|
+
multi_json (1.11.3)
|
64
|
+
multipart-post (2.0.0)
|
65
|
+
namae (0.10.2)
|
66
|
+
nokogiri (1.6.8.1)
|
67
|
+
mini_portile2 (~> 2.1.0)
|
68
|
+
nokogumbo (1.4.10)
|
69
|
+
nokogiri
|
70
|
+
oj (2.13.1)
|
71
|
+
public_suffix (2.0.4)
|
72
|
+
rack (2.0.1)
|
73
|
+
rack-test (0.6.3)
|
74
|
+
rack (>= 1.0)
|
75
|
+
rake (12.0.0)
|
76
|
+
rspec (3.5.0)
|
77
|
+
rspec-core (~> 3.5.0)
|
78
|
+
rspec-expectations (~> 3.5.0)
|
79
|
+
rspec-mocks (~> 3.5.0)
|
80
|
+
rspec-core (3.5.4)
|
81
|
+
rspec-support (~> 3.5.0)
|
82
|
+
rspec-expectations (3.5.0)
|
83
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
84
|
+
rspec-support (~> 3.5.0)
|
85
|
+
rspec-mocks (3.5.0)
|
86
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
87
|
+
rspec-support (~> 3.5.0)
|
88
|
+
rspec-support (3.5.0)
|
89
|
+
rspec-xsd (0.1.0)
|
90
|
+
nokogiri (~> 1.6)
|
91
|
+
rspec (~> 3)
|
92
|
+
safe_yaml (1.0.4)
|
93
|
+
sanitize (4.4.0)
|
94
|
+
crass (~> 1.0.2)
|
95
|
+
nokogiri (>= 1.4.4)
|
96
|
+
nokogumbo (~> 1.4.1)
|
97
|
+
simplecov (0.12.0)
|
98
|
+
docile (~> 1.1.0)
|
99
|
+
json (>= 1.8, < 3)
|
100
|
+
simplecov-html (~> 0.10.0)
|
101
|
+
simplecov-html (0.10.0)
|
102
|
+
thor (0.19.4)
|
103
|
+
thread_safe (0.3.5)
|
104
|
+
tzinfo (1.2.2)
|
105
|
+
thread_safe (~> 0.1)
|
106
|
+
vcr (3.0.3)
|
107
|
+
webmock (1.24.6)
|
108
|
+
addressable (>= 2.3.6)
|
109
|
+
crack (>= 0.3.2)
|
110
|
+
hashdiff
|
111
|
+
|
112
|
+
PLATFORMS
|
113
|
+
ruby
|
114
|
+
|
115
|
+
DEPENDENCIES
|
116
|
+
base32-crockford!
|
117
|
+
bundler (~> 1.0)
|
118
|
+
cirneco!
|
119
|
+
codeclimate-test-reporter (~> 1.0, >= 1.0.0)
|
120
|
+
rack-test (~> 0)
|
121
|
+
rake (~> 12.0)
|
122
|
+
rspec (~> 3.4)
|
123
|
+
rspec-xsd (~> 0.1.0)
|
124
|
+
simplecov (~> 0.12.0)
|
125
|
+
vcr (~> 3.0, >= 3.0.3)
|
126
|
+
webmock (~> 1.22, >= 1.22.3)
|
127
|
+
|
128
|
+
BUNDLED WITH
|
129
|
+
1.13.6
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 DataCite
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Cirneco: command-line client for DataCite MDS
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/cirneco.svg)](https://badge.fury.io/rb/cirneco)
|
4
|
+
[![Build Status](https://travis-ci.org/datacite/cirneco.svg?branch=master)](https://travis-ci.org/datacite/cirneco)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/datacite/cirneco/badges/gpa.svg)](https://codeclimate.com/github/datacite/cirneco)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/datacite/cirneco/badges/coverage.svg)](https://codeclimate.com/github/datacite/cirneco/coverage)
|
7
|
+
|
8
|
+
Cirneco is a command-line client for the DataCite Metadata Store (MDS), written as Ruby gem. Uses the MDS API, and includes several utlity functions.
|
9
|
+
|
10
|
+
## Features
|
11
|
+
|
12
|
+
The following functionality is supported:
|
13
|
+
|
14
|
+
* the MDS API (DOI, Metadata and Media APIs) is fully supported
|
15
|
+
* generates valid metadata, using Schema 4.0 (currently only partial support of available metadata fields)
|
16
|
+
* generates a DOI name to be used for registration, using [Base32 Crockford encoded](https://github.com/levinalex/base32) sequential numbers that include a checksum
|
17
|
+
|
18
|
+
## Requirements
|
19
|
+
|
20
|
+
* valid username and password for DataCite MDS account (production and/or test system)
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
The usual way with Bundler: add the following to your `Gemfile` to install the current version of the gem:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'cirneco'
|
28
|
+
```
|
29
|
+
|
30
|
+
Then run `bundle install` to install into your environment.
|
31
|
+
|
32
|
+
You can also install the gem system-wide in the usual way:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
gem install cirneco
|
36
|
+
```
|
37
|
+
|
38
|
+
## Use
|
39
|
+
|
40
|
+
TBD.
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
[MIT](license.md)
|
data/Rakefile
ADDED
data/bin/cirneco.rb
ADDED
data/cirneco.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require "date"
|
2
|
+
require File.expand_path("../lib/cirneco/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.authors = "Martin Fenner"
|
6
|
+
s.email = "mfenner@datacite.org"
|
7
|
+
s.name = "cirneco"
|
8
|
+
s.homepage = "https://github.com/datacite/cirneco"
|
9
|
+
s.summary = "Ruby client library for the DataCite MDS"
|
10
|
+
s.date = Date.today
|
11
|
+
s.description = "Ruby client library for the DataCite Metadata Store (MDS) API."
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.version = Cirneco::VERSION
|
14
|
+
s.extra_rdoc_files = ["README.md"]
|
15
|
+
s.license = 'MIT'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.executables = ["cirneco.rb"]
|
21
|
+
|
22
|
+
# Declary dependencies here, rather than in the Gemfile
|
23
|
+
s.add_dependency 'maremma', '~> 3.1'
|
24
|
+
s.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
|
25
|
+
s.add_dependency 'builder', '~> 3.2', '>= 3.2.2'
|
26
|
+
s.add_dependency 'namae', '~> 0.10.1'
|
27
|
+
s.add_dependency 'activesupport', '~> 4.2', '>= 4.2.5'
|
28
|
+
s.add_dependency 'sanitize', '~> 4.0', '>= 4.0.1'
|
29
|
+
s.add_dependency 'dotenv', '~> 2.1', '>= 2.1.1'
|
30
|
+
s.add_dependency 'base32-crockford', '~> 0.2.0'
|
31
|
+
s.add_dependency 'thor', '~> 0.19'
|
32
|
+
s.add_development_dependency 'bundler', '~> 1.0'
|
33
|
+
s.add_development_dependency 'rspec', '~> 3.4'
|
34
|
+
s.add_development_dependency 'rspec-xsd', '~> 0.1.0'
|
35
|
+
s.add_development_dependency 'rake', '~> 12.0'
|
36
|
+
s.add_development_dependency 'rack-test', '~> 0'
|
37
|
+
s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
|
38
|
+
s.add_development_dependency 'webmock', '~> 1.22', '>= 1.22.3'
|
39
|
+
s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0', '>= 1.0.0'
|
40
|
+
s.add_development_dependency 'simplecov', '~> 0.12.0'
|
41
|
+
end
|
data/lib/cirneco/api.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
module Cirneco
|
4
|
+
module Api
|
5
|
+
def post_metadata(data, options={})
|
6
|
+
return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
|
7
|
+
|
8
|
+
mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
|
9
|
+
|
10
|
+
url = "#{mds_url}/metadata"
|
11
|
+
Maremma.post(url, content_type: 'application/xml;charset=UTF-8', data: data, username: options[:username], password: options[:password])
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_metadata(doi, options={})
|
15
|
+
return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
|
16
|
+
|
17
|
+
mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
|
18
|
+
|
19
|
+
url = "#{mds_url}/metadata/#{doi}"
|
20
|
+
Maremma.get(url, accept: 'application/xml', username: options[:username], password: options[:password], raw: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_metadata(doi, options={})
|
24
|
+
return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
|
25
|
+
|
26
|
+
mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
|
27
|
+
|
28
|
+
url = "#{mds_url}/metadata/#{doi}"
|
29
|
+
Maremma.delete(url, username: options[:username], password: options[:password])
|
30
|
+
end
|
31
|
+
|
32
|
+
def put_doi(doi, url, options={})
|
33
|
+
return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
|
34
|
+
|
35
|
+
payload = "doi=#{doi}\nurl=#{url}"
|
36
|
+
|
37
|
+
mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
|
38
|
+
|
39
|
+
url = "#{mds_url}/doi/#{doi}"
|
40
|
+
Maremma.put(url, content_type: 'text/plain;charset=UTF-8', data: payload, username: options[:username], password: options[:password])
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_doi(doi, options={})
|
44
|
+
return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
|
45
|
+
|
46
|
+
mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
|
47
|
+
|
48
|
+
url = "#{mds_url}/doi/#{doi}"
|
49
|
+
Maremma.get(url, username: options[:username], password: options[:password])
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_dois(options={})
|
53
|
+
return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
|
54
|
+
|
55
|
+
mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
|
56
|
+
|
57
|
+
url = "#{mds_url}/doi"
|
58
|
+
response = Maremma.get(url, username: options[:username], password: options[:password])
|
59
|
+
response.body["data"] = response.body["data"].split("\n") if response.body["data"].present?
|
60
|
+
response
|
61
|
+
end
|
62
|
+
|
63
|
+
def post_media(doi, media, options={})
|
64
|
+
return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
|
65
|
+
|
66
|
+
payload = media.map { |m| "#{m[:mime_type]}=#{m[:url]}" }.join("\n")
|
67
|
+
|
68
|
+
mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
|
69
|
+
|
70
|
+
url = "#{mds_url}/media/#{doi}"
|
71
|
+
Maremma.post(url, content_type: 'text/plain;charset=UTF-8', data: payload, username: options[:username], password: options[:password])
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_media(doi, options={})
|
75
|
+
return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
|
76
|
+
|
77
|
+
mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
|
78
|
+
|
79
|
+
url = "#{mds_url}/media/#{doi}"
|
80
|
+
response = Maremma.get(url, accept: 'application/xml', username: options[:username], password: options[:password])
|
81
|
+
if response.body["data"].present?
|
82
|
+
response.body["data"] = response.body["data"].split("\n").map do |m|
|
83
|
+
mime_type, url = m.split('=', 2)
|
84
|
+
{ mime_type: mime_type, url: url }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
response
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/cirneco/base.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Cirneco
|
2
|
+
module Base
|
3
|
+
# load ENV variables from .env file if it exists
|
4
|
+
env_file = File.expand_path("../../../.env", __FILE__)
|
5
|
+
if File.exist?(env_file)
|
6
|
+
require 'dotenv'
|
7
|
+
Dotenv.load! env_file
|
8
|
+
end
|
9
|
+
|
10
|
+
# load ENV variables from container environment if json file exists
|
11
|
+
# see https://github.com/phusion/baseimage-docker#envvar_dumps
|
12
|
+
env_json_file = "/etc/container_environment.json"
|
13
|
+
if File.exist?(env_json_file)
|
14
|
+
env_vars = JSON.parse(File.read(env_json_file))
|
15
|
+
env_vars.each { |k, v| ENV[k] = v }
|
16
|
+
end
|
17
|
+
|
18
|
+
# default values for some ENV variables
|
19
|
+
ENV['MDS_URL'] ||= "https://mds.test.datacite.org"
|
20
|
+
end
|
21
|
+
end
|
data/lib/cirneco/cli.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
|
5
|
+
require_relative 'doi'
|
6
|
+
require_relative 'media'
|
7
|
+
require_relative 'metadata'
|
8
|
+
|
9
|
+
module Cirneco
|
10
|
+
class CLI < Thor
|
11
|
+
include Cirneco::Base
|
12
|
+
include Cirneco::Api
|
13
|
+
include Cirneco::Utils
|
14
|
+
|
15
|
+
def self.exit_on_failure?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "hello NAME", "say hello to NAME"
|
20
|
+
def hello(name, from=nil)
|
21
|
+
puts "from: #{from}" if from
|
22
|
+
puts "Hello #{name}"
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "parentcommand SUBCOMMAND", "Some Parent Command"
|
26
|
+
subcommand "doi", Cirneco::Doi
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'sanitize'
|
4
|
+
|
5
|
+
require_relative 'api'
|
6
|
+
require_relative 'utils'
|
7
|
+
require_relative 'base'
|
8
|
+
|
9
|
+
module Cirneco
|
10
|
+
class DataCenter
|
11
|
+
include Cirneco::Base
|
12
|
+
include Cirneco::Api
|
13
|
+
include Cirneco::Utils
|
14
|
+
|
15
|
+
attr_accessor :prefix, :username, :password
|
16
|
+
|
17
|
+
def initialize(prefix:, username:, password:, **options)
|
18
|
+
@prefix = prefix
|
19
|
+
@username = username
|
20
|
+
@password = password
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/cirneco/doi.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
require_relative 'api'
|
4
|
+
require_relative 'utils'
|
5
|
+
require_relative 'base'
|
6
|
+
|
7
|
+
module Cirneco
|
8
|
+
class Doi < Thor
|
9
|
+
include Cirneco::Base
|
10
|
+
include Cirneco::Api
|
11
|
+
include Cirneco::Utils
|
12
|
+
|
13
|
+
method_option :sandbox, :type => :boolean
|
14
|
+
method_option :prefix, :default => ENV['PREFIX']
|
15
|
+
method_option :username, :default => ENV['MDS_USERNAME']
|
16
|
+
method_option :password, :default => ENV['MDS_PASSWORD']
|
17
|
+
|
18
|
+
desc "get DOI", "get handle url for DOI"
|
19
|
+
def get(doi)
|
20
|
+
get_doi(doi)
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "encode NUMBER", "say hello to NAME"
|
24
|
+
def encode(number)
|
25
|
+
puts encode_doi(prefix, number)
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "command", "an example task"
|
29
|
+
def command
|
30
|
+
puts "I'm a thor task!"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "thor"
|
2
|
+
require 'active_support/all'
|
3
|
+
|
4
|
+
require_relative 'api'
|
5
|
+
require_relative 'utils'
|
6
|
+
require_relative 'base'
|
7
|
+
|
8
|
+
module Cirneco
|
9
|
+
class Media < Thor
|
10
|
+
include Cirneco::Base
|
11
|
+
include Cirneco::Api
|
12
|
+
include Cirneco::Utils
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "thor"
|
2
|
+
require 'active_support/all'
|
3
|
+
|
4
|
+
require_relative 'api'
|
5
|
+
require_relative 'utils'
|
6
|
+
require_relative 'base'
|
7
|
+
|
8
|
+
module Cirneco
|
9
|
+
class Metadata < Thor
|
10
|
+
include Cirneco::Base
|
11
|
+
include Cirneco::Api
|
12
|
+
include Cirneco::Utils
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'base32/crockford'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module Cirneco
|
5
|
+
module Utils
|
6
|
+
# "ZZZZZZZ" decoded as number
|
7
|
+
UPPER_LIMIT = 34359738367
|
8
|
+
|
9
|
+
def get_dois_by_prefix(prefix, options={})
|
10
|
+
response = get_dois(options)
|
11
|
+
|
12
|
+
if response.body["data"].present?
|
13
|
+
response.body["data"] = response.body["data"].select { |doi| doi.start_with?(prefix) }
|
14
|
+
end
|
15
|
+
response
|
16
|
+
end
|
17
|
+
|
18
|
+
def decode_doi(doi)
|
19
|
+
prefix, string = doi.split('/', 2)
|
20
|
+
Base32::Crockford.decode(string, checksum: true).to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
def encode_doi(prefix, options={})
|
24
|
+
number = options[:number] || SecureRandom.random_number(UPPER_LIMIT)
|
25
|
+
prefix + "/" + Base32::Crockford.encode(number, split: 4, length: 8, checksum: true)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|