cirneco 0.3.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 967bbedde54c1865ed3ef418dfce7f6367de3ee8
4
- data.tar.gz: f681c1909b9575b57f085a59092bcb1566fba81c
3
+ metadata.gz: 659265c0ac952c44a8052b7db9f1091ebc050591
4
+ data.tar.gz: 6dc57c4bcd57f0ab1a4c40c32daea3f2ecfa2735
5
5
  SHA512:
6
- metadata.gz: 6e115a86cae2763c551c641b91feacfadd51b48e830b7a3fc854b01c665ff4b056f6fed0cde404278846ffd7ca075d208ff347dce5c829ad68bba123f99325a7
7
- data.tar.gz: 656bda3023b6a802352c4de759e2563a12c5ae3c27b01c4d5b2309384c896a8fe55849def63bc98f9e7dc2f57042055cfa65d5a5e07b76ff88aaf9a6aadc08ba
6
+ metadata.gz: 6c35f6d1e55fcdefd64f8097a6ec6c588bd7e76994d67143e3cbb76de77a26110403bf1d5723b7cfe8396ced125991510c07a1c55decc54254f8a5919d42605c
7
+ data.tar.gz: 91dac16457324d58348c96e42fca953c73c66d8129d4fe05043ba154a1545ddcdc0322168c05e45c402e1b57a584b8326b30c0054c11bbd037de7e36fed2b68e
data/.env.example ADDED
@@ -0,0 +1,3 @@
1
+ MDS_USERNAME=USER.USER
2
+ MDS_PASSWORD=opensesame
3
+ PREFIX=10.5555
data/0006.xml ADDED
@@ -0,0 +1,78 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <resource xmlns="http://datacite.org/schema/kernel-2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://datacite.org/schema/kernel-2.2 http://schema.datacite.org/meta/kernel-2.2/metadata.xsd">
3
+ <identifier identifierType="DOI">10.5438/0006</identifier>
4
+ <creators>
5
+ <creator>
6
+ <creatorName>DataCite Metadata Working Group</creatorName>
7
+ </creator>
8
+ </creators>
9
+ <titles>
10
+ <title>DataCite Metadata Schema for the Publication and Citation of Research Data</title>
11
+ </titles>
12
+ <publisher>DataCite e.V.</publisher>
13
+ <publicationYear>2011</publicationYear>
14
+ <contributors>
15
+ <contributor contributorType="ProjectLeader">
16
+ <contributorName>Starr, Joan</contributorName>
17
+ </contributor>
18
+ <contributor contributorType="Editor">
19
+ <contributorName>Ashton,Jan</contributorName>
20
+ </contributor>
21
+ <contributor contributorType="Editor">
22
+ <contributorName>Brase, Jan</contributorName>
23
+ </contributor>
24
+ <contributor contributorType="Editor">
25
+ <contributorName>Bracke, Paul</contributorName>
26
+ </contributor>
27
+ <contributor contributorType="Editor">
28
+ <contributorName>Gastl, Angela</contributorName>
29
+ </contributor>
30
+ <contributor contributorType="Editor">
31
+ <contributorName>Gillet, Jacqueline</contributorName>
32
+ </contributor>
33
+ <contributor contributorType="Editor">
34
+ <contributorName>Heller, Alfred</contributorName>
35
+ </contributor>
36
+ <contributor contributorType="Editor">
37
+ <contributorName>Krog,Birthe</contributorName>
38
+ </contributor>
39
+ <contributor contributorType="Editor">
40
+ <contributorName>McAvoy,Lynne</contributorName>
41
+ </contributor>
42
+ <contributor contributorType="Editor">
43
+ <contributorName>Morgenroth,Karen</contributorName>
44
+ </contributor>
45
+ <contributor contributorType="Editor">
46
+ <contributorName>Newbold, Elizabeth</contributorName>
47
+ </contributor>
48
+ <contributor contributorType="Editor">
49
+ <contributorName>Smaele,Madeleine de</contributorName>
50
+ </contributor>
51
+ <contributor contributorType="Editor">
52
+ <contributorName>Wilde, Anja</contributorName>
53
+ </contributor>
54
+ <contributor contributorType="Editor">
55
+ <contributorName>Yeadon, Scott</contributorName>
56
+ </contributor>
57
+ <contributor contributorType="Editor">
58
+ <contributorName>Zenk-Möltgen, Wolfgang</contributorName>
59
+ </contributor>
60
+ <contributor contributorType="Supervisor">
61
+ <contributorName>Ziedorn, Frauke</contributorName>
62
+ </contributor>
63
+ </contributors>
64
+ <dates>
65
+ <date dateType="Available">July 2011</date>
66
+ </dates>
67
+ <language>eng</language>
68
+ <resourceType resourceTypeGeneral="Text">XSD code</resourceType>
69
+ <relatedIdentifiers>
70
+ <relatedIdentifier relatedIdentifierType="DOI" relationType="IsDocumentedBy">10.5438/0005</relatedIdentifier>
71
+ <relatedIdentifier relatedIdentifierType="DOI" relationType="IsNewVersionOf">10.5438/0004</relatedIdentifier>
72
+ <relatedIdentifier relatedIdentifierType="DOI" relationType="IsNewVersionOf">10.5438/0002</relatedIdentifier>
73
+ </relatedIdentifiers>
74
+ <formats>
75
+ <format>application/xml</format>
76
+ </formats>
77
+ <version>2.2</version>
78
+ </resource>
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- cirneco (0.3.3)
10
+ cirneco (0.4)
11
11
  activesupport (~> 4.2, >= 4.2.5)
12
12
  builder (~> 3.2, >= 3.2.2)
13
13
  dotenv (~> 2.1, >= 2.1.1)
@@ -125,4 +125,4 @@ DEPENDENCIES
125
125
  webmock (~> 1.22, >= 1.22.3)
126
126
 
127
127
  BUNDLED WITH
128
- 1.13.6
128
+ 1.12.5
data/README.md CHANGED
@@ -13,7 +13,7 @@ The following functionality is supported:
13
13
 
14
14
  * the MDS API (DOI, Metadata and Media APIs) is fully supported
15
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
16
+ * generates a DOI name to be used for registration, using a random number that is [Base32 Crockford encoded](https://github.com/levinalex/base32) and includes a checksum
17
17
 
18
18
  ## Requirements
19
19
 
@@ -35,9 +35,56 @@ You can also install the gem system-wide in the usual way:
35
35
  gem install cirneco
36
36
  ```
37
37
 
38
- ## Use
38
+ ## Configuration
39
39
 
40
- TBD.
40
+ Configure ENV variables `MDS_USERNAME`, `MDS_PASSWORD` and `PREFIX`, e.g. by storing them in file `.env` in same folder (see `.env.xample`).
41
+
42
+ ## Commands
43
+
44
+ Return all DOIs registered for the data center
45
+ ```
46
+ cirneco doi get all
47
+ ```
48
+
49
+ Return URL registered for DOI in the handle system
50
+ ```
51
+ cirneco doi get 10.5555/1234
52
+ ```
53
+
54
+ Generate a random DOI in the format `xxxx-xxxy` where `y` is the checksum
55
+ ```
56
+ cirneco doi generate
57
+ ```
58
+
59
+ Check DOI for valid checksum
60
+ ```
61
+ cirneco doi check 10.5555/1234
62
+ ```
63
+
64
+ Save metadata for DOI into file `1234.xml` in same directory
65
+ ```
66
+ cirneco metadata get 10.5555/1234
67
+ ```
68
+
69
+ Post metadata from file `1234.xml` in same directory
70
+ ```
71
+ cirneco metadata post 1234.xml
72
+ ```
73
+
74
+ Delete metadata for DOI (set `is_active` flag to false)
75
+ ```
76
+ cirneco metadata delete 10.5555/1234
77
+ ```
78
+
79
+ Save media information for DOI into file `1234.txt` in same directory
80
+ ```
81
+ cirneco media get 10.5555/1234
82
+ ```
83
+
84
+ Post media information from file `1234.txt` in same directory
85
+ ```
86
+ cirneco media post 1234.xml
87
+ ```
41
88
 
42
89
  ## License
43
90
 
data/lib/cirneco/api.rb CHANGED
@@ -1,4 +1,5 @@
1
- require "uri"
1
+ require 'uri'
2
+ require 'maremma'
2
3
 
3
4
  module Cirneco
4
5
  module Api
@@ -63,7 +64,7 @@ module Cirneco
63
64
  def post_media(doi, media, options={})
64
65
  return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
65
66
 
66
- payload = media.map { |m| "#{m[:mime_type]}=#{m[:url]}" }.join("\n")
67
+ payload = options[:raw] ? media : media.map { |m| "#{m[:mime_type]}=#{m[:url]}" }.join("\n")
67
68
 
68
69
  mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
69
70
 
@@ -78,7 +79,7 @@ module Cirneco
78
79
 
79
80
  url = "#{mds_url}/media/#{doi}"
80
81
  response = Maremma.get(url, accept: 'application/xml', username: options[:username], password: options[:password])
81
- if response.body["data"].present?
82
+ if response.body["data"].present? && !options[:raw]
82
83
  response.body["data"] = response.body["data"].split("\n").map do |m|
83
84
  mime_type, url = m.split('=', 2)
84
85
  { mime_type: mime_type, url: url }
data/lib/cirneco/cli.rb CHANGED
@@ -12,6 +12,13 @@ module Cirneco
12
12
  include Cirneco::Api
13
13
  include Cirneco::Utils
14
14
 
15
+ # load ENV variables from .env file if it exists
16
+ env_file = File.expand_path("../../.env", __FILE__)
17
+ if File.exist?(env_file)
18
+ require 'dotenv'
19
+ Dotenv.load! env_file
20
+ end
21
+
15
22
  def self.exit_on_failure?
16
23
  true
17
24
  end
@@ -24,5 +31,11 @@ module Cirneco
24
31
 
25
32
  desc "parentcommand SUBCOMMAND", "Some Parent Command"
26
33
  subcommand "doi", Cirneco::Doi
34
+
35
+ desc "parentcommand SUBCOMMAND", "Some Parent Command"
36
+ subcommand "metadata", Cirneco::Metadata
37
+
38
+ desc "parentcommand SUBCOMMAND", "Some Parent Command"
39
+ subcommand "media", Cirneco::Media
27
40
  end
28
41
  end
data/lib/cirneco/doi.rb CHANGED
@@ -10,24 +10,42 @@ module Cirneco
10
10
  include Cirneco::Api
11
11
  include Cirneco::Utils
12
12
 
13
- method_option :sandbox, :type => :boolean
14
- method_option :prefix, :default => ENV['PREFIX']
13
+ desc "get DOI", "get handle url for DOI"
15
14
  method_option :username, :default => ENV['MDS_USERNAME']
16
15
  method_option :password, :default => ENV['MDS_PASSWORD']
17
-
18
- desc "get DOI", "get handle url for DOI"
16
+ method_option :sandbox, :type => :boolean, default: true
19
17
  def get(doi)
20
- get_doi(doi)
18
+ if doi == "all"
19
+ response = get_dois(options)
20
+ else
21
+ response = get_doi(doi, options)
22
+ end
23
+
24
+ if response.body["errors"]
25
+ puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
26
+ else
27
+ puts response.body["data"]
28
+ end
21
29
  end
22
30
 
23
- desc "encode NUMBER", "say hello to NAME"
24
- def encode(number)
25
- puts encode_doi(prefix, number)
31
+ desc "generate PREFIX", "generate a DOI name"
32
+ method_option :prefix, :default => ENV['PREFIX']
33
+ method_option :number, :type => :numeric, :aliases => '-n'
34
+ def generate
35
+ if options[:prefix]
36
+ puts encode_doi(options[:prefix], number: options[:number])
37
+ else
38
+ puts "No PREFIX provided. Use --prefix option or PREFIX ENV variable"
39
+ end
26
40
  end
27
41
 
28
- desc "command", "an example task"
29
- def command
30
- puts "I'm a thor task!"
42
+ desc "check DOI", "check DOI using Crockford base32 checksum"
43
+ def check(doi)
44
+ if decode_doi(doi) > 0
45
+ puts "Checksum for #{doi} is valid"
46
+ else
47
+ puts "Checksum for #{doi} is not valid"
48
+ end
31
49
  end
32
50
  end
33
51
  end
data/lib/cirneco/media.rb CHANGED
@@ -11,5 +11,40 @@ module Cirneco
11
11
  include Cirneco::Api
12
12
  include Cirneco::Utils
13
13
 
14
+ desc "get DOI", "get media for DOI"
15
+ method_option :username, :default => ENV['MDS_USERNAME']
16
+ method_option :password, :default => ENV['MDS_PASSWORD']
17
+ method_option :sandbox, :type => :boolean, default: true
18
+ def get(doi)
19
+ response = get_media(doi, options.merge(raw: true))
20
+
21
+ if response.body["errors"]
22
+ puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
23
+ else
24
+ filename = doi.split("/", 2).last + ".txt"
25
+ content = response.body["data"]
26
+ IO.write(filename, content)
27
+ puts "Media for #{doi} saved as #{filename}"
28
+ end
29
+ end
30
+
31
+ desc "post DOI", "post media for DOI"
32
+ method_option :username, :default => ENV['MDS_USERNAME']
33
+ method_option :password, :default => ENV['MDS_PASSWORD']
34
+ method_option :sandbox, :type => :boolean, default: true
35
+ method_option :file, :aliases => '-f'
36
+ def post(doi)
37
+ filename = options[:file] || doi.split("/", 2).last + ".txt"
38
+ data = IO.read(filename)
39
+ response = post_media(doi, data, options.merge(raw: true))
40
+
41
+ if response.body["errors"]
42
+ puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
43
+ else
44
+ puts response.body["data"]
45
+ end
46
+ end
47
+
48
+
14
49
  end
15
50
  end
@@ -11,5 +11,50 @@ module Cirneco
11
11
  include Cirneco::Api
12
12
  include Cirneco::Utils
13
13
 
14
+ desc "get DOI", "get metadata for DOI"
15
+ method_option :username, :default => ENV['MDS_USERNAME']
16
+ method_option :password, :default => ENV['MDS_PASSWORD']
17
+ method_option :sandbox, :type => :boolean, default: true
18
+ def get(doi)
19
+ response = get_metadata(doi, options)
20
+
21
+ if response.body["errors"]
22
+ puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
23
+ else
24
+ filename = doi.split("/", 2).last + ".xml"
25
+ content = response.body["data"]
26
+ IO.write(filename, content)
27
+ puts "Metadata for #{doi} saved as #{filename}"
28
+ end
29
+ end
30
+
31
+ desc "post DOI", "post metadata for DOI"
32
+ method_option :username, :default => ENV['MDS_USERNAME']
33
+ method_option :password, :default => ENV['MDS_PASSWORD']
34
+ method_option :sandbox, :type => :boolean, default: true
35
+ def post(file)
36
+ data = IO.read(file)
37
+ response = post_metadata(data, options)
38
+
39
+ if response.body["errors"]
40
+ puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
41
+ else
42
+ puts response.headers["Location"]
43
+ end
44
+ end
45
+
46
+ desc "delete DOI", "hide metadata for DOI"
47
+ method_option :username, :default => ENV['MDS_USERNAME']
48
+ method_option :password, :default => ENV['MDS_PASSWORD']
49
+ method_option :sandbox, :type => :boolean, default: true
50
+ def delete(doi)
51
+ response = delete_metadata(doi, options)
52
+
53
+ if response.body["errors"]
54
+ puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
55
+ else
56
+ puts response.body["data"]
57
+ end
58
+ end
14
59
  end
15
60
  end
@@ -1,3 +1,3 @@
1
1
  module Cirneco
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cirneco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
@@ -304,8 +304,10 @@ extensions: []
304
304
  extra_rdoc_files:
305
305
  - README.md
306
306
  files:
307
+ - ".env.example"
307
308
  - ".gitignore"
308
309
  - ".travis.yml"
310
+ - 0006.xml
309
311
  - Gemfile
310
312
  - Gemfile.lock
311
313
  - LICENSE.md