cirneco 0.6.9 → 0.6.10

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: 340962d18c91ee11a3722511c861fc49e0bb6e4e
4
- data.tar.gz: 91f07300e1859bbb79ca161c8305d133530c2cf1
3
+ metadata.gz: ce6afcc62d30c257c822973dece42aa9a6135ec4
4
+ data.tar.gz: 0e6193614e00ecec144969b52b2f09d1b679269d
5
5
  SHA512:
6
- metadata.gz: 9a6c516820e7ceadd04e6cbc62667e21c978e02a9f0d2479658905062296fcd15156911086fee8b8adb985b5bb3369d2aa6f8a15236496192ec78c28b7e58991
7
- data.tar.gz: 71e05301cc30f995cc2843edde2390aa909f1d23f443d067de7f49c498180cd17aba2f29a5b465753b6df474081eb859b6194007d336c1d0f5966391a2273f59
6
+ metadata.gz: 037e8115820da820333cfb6ee5a41a87234ed2226a4b2e590017a66ce5d195a03a23acd1e9332c29a6e1beb93aeb1c270307c8ba9b34d216e4832fd9d8cd963a
7
+ data.tar.gz: cdfd61cbe754c4651378c67e49bf9819ac1e064db49fcc45f615c4cc9d3811c13245a74db305b89b0bf72844c67b0feaf5aa347813b7b48fdbe0f9bb00d6557c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cirneco (0.6.9)
4
+ cirneco (0.6.10)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  base32-crockford-checksum (~> 0.2.2)
7
7
  bergamasco (~> 0.2)
data/Rakefile CHANGED
@@ -1,5 +1,31 @@
1
1
  #!/usr/bin/env rake
2
2
 
3
- # Get useful helper tasks from Bundler
4
- require "bundler/gem_tasks"
3
+ require 'bundler'
4
+ require 'rake'
5
+ require 'yaml'
6
+ require 'rspec/core/rake_task'
5
7
 
8
+ Bundler::GemHelper.install_tasks
9
+ RSpec::Core::RakeTask.new('spec')
10
+
11
+ namespace :repo do
12
+ desc "push files generated with cirneco to remote"
13
+ task :push do
14
+
15
+ # Configure git if this is run in Travis CI
16
+ if ENV["TRAVIS"]
17
+ sh "git config --global user.name '#{ENV['GIT_NAME']}'"
18
+ sh "git config --global user.email '#{ENV['GIT_EMAIL']}'"
19
+ sh "git config --global push.default simple"
20
+ end
21
+
22
+ # Commit and push to github
23
+ sh "git add --all ."
24
+ sh "git commit -m 'Committing changed files.'"
25
+ sh "git push https://${GH_TOKEN}@github.com/datacite/cirneco.rb master --quiet"
26
+ puts "Pushed changed files to repo"
27
+ end
28
+ end
29
+
30
+ # default task is running rspec tests
31
+ task :default => :spec
data/lib/cirneco/api.rb CHANGED
@@ -30,10 +30,10 @@ module Cirneco
30
30
  Maremma.delete(url, username: options[:username], password: options[:password])
31
31
  end
32
32
 
33
- def put_doi(doi, url, options={})
33
+ def put_doi(doi, options={})
34
34
  return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
35
35
 
36
- payload = "doi=#{doi}\nurl=#{url}"
36
+ payload = "doi=#{doi}\nurl=#{options[:url]}"
37
37
 
38
38
  mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
39
39
 
@@ -61,10 +61,10 @@ module Cirneco
61
61
  response
62
62
  end
63
63
 
64
- def post_media(doi, media, options={})
64
+ def post_media(doi, options={})
65
65
  return OpenStruct.new(body: { "errors" => [{ "title" => "Username or password missing" }] }) unless options[:username].present? && options[:password].present?
66
66
 
67
- payload = options[:raw] ? media : media.map { |m| "#{m[:mime_type]}=#{m[:url]}" }.join("\n")
67
+ payload = options[:raw] ? options[:media] : options[:media].map { |m| "#{m[:mime_type]}=#{m[:url]}" }.join("\n")
68
68
 
69
69
  mds_url = options[:sandbox] ? 'https://mds.test.datacite.org' : 'https://mds.datacite.org'
70
70
 
data/lib/cirneco/doi.rb CHANGED
@@ -28,6 +28,21 @@ module Cirneco
28
28
  end
29
29
  end
30
30
 
31
+ desc "put DOI", "put handle url for DOI"
32
+ method_option :username, :default => ENV['MDS_USERNAME']
33
+ method_option :password, :default => ENV['MDS_PASSWORD']
34
+ method_option :sandbox, :default => ENV['SANDBOX']
35
+ method_option :url
36
+ def put(doi)
37
+ response = put_doi(doi, options)
38
+
39
+ if response.body["errors"]
40
+ puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
41
+ else
42
+ puts response.body["data"]
43
+ end
44
+ end
45
+
31
46
  desc "generate DOI", "generate a DOI name"
32
47
  method_option :prefix, :default => ENV['PREFIX']
33
48
  method_option :number, :type => :numeric, :aliases => '-n'
@@ -1,3 +1,3 @@
1
1
  module Cirneco
2
- VERSION = "0.6.9"
2
+ VERSION = "0.6.10"
3
3
  end
data/spec/api_spec.rb CHANGED
@@ -22,20 +22,20 @@ describe Cirneco::Work, vcr: true, :order => :defined do
22
22
  let(:fixture_path) { "spec/fixtures/" }
23
23
  let(:samples_path) { "resources/kernel-4.0/samples/" }
24
24
 
25
- subject { Cirneco::Work.new(metadata,
26
- media: media,
27
- username: username,
28
- password: password) }
25
+ subject { Cirneco::Work.new(metadata,
26
+ media: media,
27
+ username: username,
28
+ password: password) }
29
29
 
30
30
  describe "Metadata API" do
31
- describe "get" do
31
+ context "get" do
32
32
  it 'should get metadata' do
33
33
  response = subject.get_metadata(doi, options)
34
34
  expect(response.body["data"]).to eq(subject.data)
35
35
  end
36
36
  end
37
37
 
38
- describe "delete" do
38
+ context "delete" do
39
39
  it 'should delete metadata' do
40
40
  response = subject.delete_metadata(doi, options)
41
41
  expect(response.body["data"]).to eq("OK")
@@ -43,7 +43,7 @@ describe Cirneco::Work, vcr: true, :order => :defined do
43
43
  end
44
44
  end
45
45
 
46
- describe "post" do
46
+ context "post" do
47
47
  it 'should post metadata' do
48
48
  response = subject.post_metadata(subject.data, options)
49
49
  expect(response.body["data"]).to eq("OK (10.23725/0000-03VC)")
@@ -56,7 +56,7 @@ describe Cirneco::Work, vcr: true, :order => :defined do
56
56
  describe "DOI API" do
57
57
  describe "put" do
58
58
  it 'should put doi' do
59
- response = subject.put_doi(doi, url, options)
59
+ response = subject.put_doi(doi, options.merge(url: url))
60
60
  expect(response.body["data"]).to eq("OK")
61
61
  expect(response.status).to eq(201)
62
62
  end
@@ -86,7 +86,7 @@ describe Cirneco::Work, vcr: true, :order => :defined do
86
86
  describe "Media API" do
87
87
  describe "post" do
88
88
  it 'should post media' do
89
- response = subject.post_media(doi, media, options)
89
+ response = subject.post_media(doi, options.merge(media: media))
90
90
  expect(response.body["data"]).to eq("OK")
91
91
  expect(response.status).to eq(200)
92
92
  end
data/spec/doi_spec.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+ require 'cirneco/cli'
3
+
4
+ describe Cirneco::Doi do
5
+ let(:subject) do
6
+ described_class.new
7
+ end
8
+
9
+ let(:number) { 123 }
10
+ let(:prefix) { ENV['PREFIX'] }
11
+ let(:doi) { "10.23725/0000-03VC" }
12
+ let(:url) { "http://www.datacite.org" }
13
+ let(:filename) { 'cool-dois.html.md' }
14
+ let(:filepath) { fixture_path + filename }
15
+ let(:username) { ENV['MDS_USERNAME'] }
16
+ let(:password) { ENV['MDS_PASSWORD'] }
17
+ let(:sandbox) { ENV['SANDBOX'] }
18
+ let(:api_options) { { username: username, password: password, sandbox: true } }
19
+
20
+ describe "MDS DOI API", vcr: true, :order => :defined do
21
+ context "put" do
22
+ it 'should put doi' do
23
+ subject.options = api_options.merge(url: url)
24
+ expect { subject.put doi }.to output("OK\n").to_stdout
25
+ end
26
+ end
27
+
28
+ context "get" do
29
+ it 'should get all dois' do
30
+ subject.options = api_options
31
+ expect { subject.get "all" }.to output("10.23725/0000-03VC\n10.23725/0000-0A53\n10.23725/GQZDGNZW\n10.23725/MDS-CLIENT-RUBY-TEST\n10.5438/0001\n10.5438/0002\n10.5438/0003\n10.5438/0004\n10.5438/0005\n10.5438/0006\n10.5438/EXAMPLE-FULL\n10.5438/MDS-CLIENT-RUBY-TEST\n").to_stdout
32
+ end
33
+
34
+ it 'should get doi' do
35
+ subject.options = api_options
36
+ expect { subject.get doi }.to output("http://www.datacite.org\n").to_stdout
37
+ end
38
+
39
+ it 'username missing' do
40
+ subject.options = { username: username, sandbox: true }
41
+ expect { subject.get doi }.to output("Error: Username or password missing\n").to_stdout
42
+ end
43
+ end
44
+ end
45
+
46
+ context "base32" do
47
+ it 'generates a doi' do
48
+ subject.options = { number: number, prefix: prefix }
49
+ expect { subject.generate }.to output("10.23725/0000-03VC\n").to_stdout
50
+ end
51
+
52
+ it 'requires a prefix' do
53
+ subject.options = { number: number }
54
+ expect { subject.generate }.to output("No PREFIX provided. Use --prefix option or PREFIX ENV variable\n").to_stdout
55
+ end
56
+
57
+ it 'checks a doi' do
58
+ expect { subject.check doi }.to output("Checksum for #{doi} is valid\n").to_stdout
59
+ end
60
+
61
+ it 'checks a doi invalid checksum' do
62
+ doi = "10.23725/0000-03VA"
63
+ expect { subject.check doi }.to output("Checksum for #{doi} is not valid\n").to_stdout
64
+ end
65
+ end
66
+
67
+ context "mint and hide DOIs", :order => :defined do
68
+ it 'mints a doi' do
69
+ expect { subject.mint filepath }.to output("DOI 10.23725/0000-03VC minted for #{filename}\n").to_stdout
70
+ end
71
+
72
+ it 'hides a doi' do
73
+ expect { subject.hide filepath }.to output("DOI 10.23725/0000-03VC hidden for #{filename}\n").to_stdout
74
+ end
75
+
76
+ it 'mints dois for contents of a folder' do
77
+ expect { subject.mint fixture_path }.to output("DOI 10.23725/0000-03VC minted for #{filename}\n").to_stdout
78
+ end
79
+
80
+ it 'hides dois for contents of a folder' do
81
+ expect { subject.hide fixture_path }.to output("DOI 10.23725/0000-03VC hidden for #{filename}\n").to_stdout
82
+ end
83
+
84
+ it 'should ignore non-markdown file for mint file' do
85
+ filename = 'cool-dois.yml'
86
+ expect { subject.mint fixture_path + filename }.to output("File #{filename} ignored: not a markdown file\n").to_stdout
87
+ end
88
+
89
+ it 'should ignore non-markdown file for hide file' do
90
+ filename = 'cool-dois.yml'
91
+ expect { subject.hide fixture_path + filename }.to output("File #{filename} ignored: not a markdown file\n").to_stdout
92
+ end
93
+ end
94
+ end
95
+
96
+
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://mds.test.datacite.org/doi
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Maremma - https://github.com/datacite/maremma
12
+ Accept:
13
+ - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5
14
+ Authorization:
15
+ - Basic <MDS_TOKEN>
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: ''
20
+ headers:
21
+ Server:
22
+ - nginx/1.4.6 (Ubuntu)
23
+ Date:
24
+ - Sun, 18 Dec 2016 21:24:43 GMT
25
+ Content-Type:
26
+ - text/html;charset=UTF-8
27
+ Connection:
28
+ - keep-alive
29
+ Pragma:
30
+ - no-cache
31
+ Expires:
32
+ - Thu, 01 Jan 1970 00:00:00 GMT
33
+ Cache-Control:
34
+ - no-cache, no-store
35
+ body:
36
+ encoding: UTF-8
37
+ string: |-
38
+ 10.23725/0000-03VC
39
+ 10.23725/0000-0A53
40
+ 10.23725/GQZDGNZW
41
+ 10.23725/MDS-CLIENT-RUBY-TEST
42
+ 10.5438/0001
43
+ 10.5438/0002
44
+ 10.5438/0003
45
+ 10.5438/0004
46
+ 10.5438/0005
47
+ 10.5438/0006
48
+ 10.5438/EXAMPLE-FULL
49
+ 10.5438/MDS-CLIENT-RUBY-TEST
50
+ http_version:
51
+ recorded_at: Sun, 18 Dec 2016 21:24:43 GMT
52
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://mds.test.datacite.org/doi/10.23725/0000-03VC
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Maremma - https://github.com/datacite/maremma
12
+ Accept:
13
+ - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5
14
+ Authorization:
15
+ - Basic <MDS_TOKEN>
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: ''
20
+ headers:
21
+ Server:
22
+ - nginx/1.4.6 (Ubuntu)
23
+ Date:
24
+ - Sun, 18 Dec 2016 21:24:43 GMT
25
+ Content-Type:
26
+ - text/html;charset=UTF-8
27
+ Connection:
28
+ - keep-alive
29
+ Pragma:
30
+ - no-cache
31
+ Expires:
32
+ - Thu, 01 Jan 1970 00:00:00 GMT
33
+ Cache-Control:
34
+ - no-cache, no-store
35
+ body:
36
+ encoding: UTF-8
37
+ string: http://www.datacite.org
38
+ http_version:
39
+ recorded_at: Sun, 18 Dec 2016 21:24:43 GMT
40
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: https://mds.test.datacite.org/doi/10.23725/0000-03VC
6
+ body:
7
+ encoding: UTF-8
8
+ string: |-
9
+ doi=10.23725/0000-03VC
10
+ url=http://www.datacite.org
11
+ headers:
12
+ User-Agent:
13
+ - Maremma - https://github.com/datacite/maremma
14
+ Content-Type:
15
+ - text/plain;charset=UTF-8
16
+ Accept:
17
+ - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5
18
+ Authorization:
19
+ - Basic <MDS_TOKEN>
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: ''
24
+ headers:
25
+ Server:
26
+ - nginx/1.4.6 (Ubuntu)
27
+ Date:
28
+ - Sun, 18 Dec 2016 21:24:42 GMT
29
+ Content-Type:
30
+ - text/html;charset=UTF-8
31
+ Connection:
32
+ - keep-alive
33
+ Pragma:
34
+ - no-cache
35
+ Expires:
36
+ - Thu, 01 Jan 1970 00:00:00 GMT
37
+ Cache-Control:
38
+ - no-cache, no-store
39
+ body:
40
+ encoding: UTF-8
41
+ string: OK
42
+ http_version:
43
+ recorded_at: Sun, 18 Dec 2016 21:24:42 GMT
44
+ recorded_with: VCR 3.0.3
data/spec/spec_helper.rb CHANGED
@@ -21,8 +21,64 @@ RSpec.configure do |config|
21
21
  config.expect_with :rspec do |c|
22
22
  c.syntax = :expect
23
23
  end
24
+
25
+ config.before do
26
+ ARGV.replace []
27
+ end
28
+ end
29
+
30
+ def fixture_path
31
+ File.expand_path("../fixtures", __FILE__) + '/'
24
32
  end
25
33
 
34
+ # This code was adapted from Thor, available under MIT-LICENSE
35
+ # Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
36
+ def capture(stream)
37
+ begin
38
+ stream = stream.to_s
39
+ eval "$#{stream} = StringIO.new"
40
+ yield
41
+ result = eval("$#{stream}").string
42
+ ensure
43
+ eval("$#{stream} = #{stream.upcase}")
44
+ end
45
+
46
+ result
47
+ end
48
+
49
+ def capture_stdout(&block)
50
+ original_stdout = $stdout
51
+ $stdout = fake = StringIO.new
52
+ begin
53
+ yield
54
+ ensure
55
+ $stdout = original_stdout
56
+ end
57
+ fake.string
58
+ end
59
+
60
+ def capture_stderr(&block)
61
+ original_stderr = $stderr
62
+ $stderr = fake = StringIO.new
63
+ begin
64
+ yield
65
+ ensure
66
+ $stderr = original_stderr
67
+ end
68
+ fake.string
69
+ end
70
+
71
+ # This code was adapted from Ruby on Rails, available under MIT-LICENSE
72
+ # Copyright (c) 2004-2013 David Heinemeier Hansson
73
+ def silence_warnings
74
+ old_verbose, $VERBOSE = $VERBOSE, nil
75
+ yield
76
+ ensure
77
+ $VERBOSE = old_verbose
78
+ end
79
+
80
+ alias silence capture
81
+
26
82
  VCR.configure do |c|
27
83
  mds_token = Base64.encode64("#{ENV['MDS_USERNAME']}:#{ENV['MDS_PASSWORD'].to_s}").rstrip
28
84
 
@@ -33,7 +89,3 @@ VCR.configure do |c|
33
89
  c.filter_sensitive_data("<MDS_TOKEN>") { mds_token }
34
90
  c.configure_rspec_metadata!
35
91
  end
36
-
37
- def fixture_path
38
- File.expand_path("../fixtures", __FILE__) + '/'
39
- end
data/spec/utils_spec.rb CHANGED
@@ -19,7 +19,7 @@ describe Cirneco::DataCenter, vcr: true, :order => :defined do
19
19
  end
20
20
  end
21
21
 
22
- describe "base32" do
22
+ context "base32" do
23
23
  it 'should decode doi' do
24
24
  doi = "10.23725/0000-03WD"
25
25
  expect(subject.decode_doi(doi)).to eq(124)
@@ -40,7 +40,7 @@ describe Cirneco::DataCenter, vcr: true, :order => :defined do
40
40
  end
41
41
  end
42
42
 
43
- describe "mint and hide DOIs" do
43
+ context "mint and hide DOIs" do
44
44
  it 'should mint for file' do
45
45
  filepath = fixture_path + 'cool-dois.html.md'
46
46
  number = 123
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.6.9
4
+ version: 0.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
@@ -341,6 +341,7 @@ files:
341
341
  - resources/kernel-4.0/samples/datacite-example-video-v4.0.xml
342
342
  - resources/kernel-4.0/samples/datacite-example-workflow-v4.0.xml
343
343
  - spec/api_spec.rb
344
+ - spec/doi_spec.rb
344
345
  - spec/fixtures/apa.csl
345
346
  - spec/fixtures/authors.yml
346
347
  - spec/fixtures/cool-dois.html.md
@@ -351,6 +352,9 @@ files:
351
352
  - spec/fixtures/vcr_cassettes/Cirneco_DataCenter/get/should_get_all_dois_by_prefix.yml
352
353
  - spec/fixtures/vcr_cassettes/Cirneco_DataCenter/get/should_get_next_doi.yml
353
354
  - spec/fixtures/vcr_cassettes/Cirneco_DataCenter/get/should_get_number_of_latest_doi.yml
355
+ - spec/fixtures/vcr_cassettes/Cirneco_Doi/MDS_DOI_API/get/should_get_all_dois.yml
356
+ - spec/fixtures/vcr_cassettes/Cirneco_Doi/MDS_DOI_API/get/should_get_doi.yml
357
+ - spec/fixtures/vcr_cassettes/Cirneco_Doi/MDS_DOI_API/put/should_put_doi.yml
354
358
  - spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_all_dois.yml
355
359
  - spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/get/should_get_doi.yml
356
360
  - spec/fixtures/vcr_cassettes/Cirneco_Work/DOI_API/put/should_put_doi.yml