toccatore 0.1 → 0.1.1

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: 13870f2c02d23ff37a9f4de7af84bfa353af388d
4
- data.tar.gz: a356318891ee353f9dab772c9f74b1629a21b6dc
3
+ metadata.gz: 53ede9be3b0700d3355c2c77084cdc23a2107f05
4
+ data.tar.gz: f5ba51ea0e1541d3fd03678f1d724672d444d79a
5
5
  SHA512:
6
- metadata.gz: 63cd648459e66ce0bda3434ec311e35b12fd66d617882cb59c78a1c9091a6448c9ff2f43c0bd187d1b27c8e0cfabfd861f11325d73de8245be8419f3f79a6086
7
- data.tar.gz: c0a6a5c484535dace3a5a677e73c97858f3f27bcab2383917d9d7ea631242abd869ed85b6d5eca275a87ab55ac072938b2a6c96093e50cdc13d3b259fea2573c
6
+ metadata.gz: 9d194a51974f6896f8ea00fb50895ad510612e788e7d84fb3a1b399e2ff727aa2a6d8978c8be3cc2dfff29bd8676743d8ddd8416813ccd0e64c8f3dc5a2c0769
7
+ data.tar.gz: 9276f36b39523aef67e1075034ac804811441da779aaddaf0ee576d8f93bcaf0424a671550061c1268fd9eb3e7c5fde32291e3e0a5baec4d0d28d62d9cc3f62b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toccatore (0.1)
4
+ toccatore (0.1.1)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  dotenv (~> 2.1, >= 2.1.1)
7
7
  gender_detector (~> 1.0)
@@ -1,3 +1,5 @@
1
+ require 'maremma'
2
+ require 'active_support/all'
1
3
  require 'namae'
2
4
  require 'gender_detector'
3
5
 
@@ -63,8 +65,8 @@ module Toccatore
63
65
  data = get_data(options.merge(timeout: timeout, source_id: source_id))
64
66
  data = parse_data(data, options.merge(source_id: source_id))
65
67
 
66
- # push to deposit API if no error and we have collected works and/or events
67
- # returns hash with number of deposits created, e.g. { total: 10 }
68
+ return [OpenStruct.new(body: { "data" => [] })] if data.empty?
69
+
68
70
  push_data(data, options)
69
71
  end
70
72
 
data/lib/toccatore/cli.rb CHANGED
@@ -19,18 +19,27 @@ module Toccatore
19
19
 
20
20
  desc "orcid_update", "push ORCID IDs from DataCite MDS to ORCID"
21
21
  method_option :access_token, type: :string, required: true
22
- method_option :from_date, type: :string
23
- method_option :until_date, type: :string
22
+ method_option :from_date, type: :string, default: (Time.now.to_date - 1.day).iso8601
23
+ method_option :until_date, type: :string, default: Time.now.to_date.iso8601
24
24
  method_option :push_url, type: :string
25
25
  def orcid_update
26
26
  orcid_update = Toccatore::OrcidUpdate.new
27
- orcid_update.process_data(options).each do |response|
28
- if response.body["data"].present?
29
- doi = response.body.fetch("data", {}).fetch("attributes", {}).fetch("doi", nil)
30
- orcid = response.body.fetch("data", {}).fetch("attributes", {}).fetch("orcid", nil)
31
- puts "DOI #{doi} for ORCID ID #{orcid} pushed to Profiles service."
32
- elsif response.body["errors"].present?
33
- puts "An error occured: #{response.body['errors'].first['title']}"
27
+
28
+ data = orcid_update.get_data(options.merge(timeout: orcid_update.timeout, source_id: orcid_update.source_id))
29
+ data = orcid_update.parse_data(data, options.merge(source_id: orcid_update.source_id))
30
+
31
+ if data.empty?
32
+ puts "No works found for date range #{options[:from_date]} - #{options[:until_date]}."
33
+ else
34
+ data.each do |item|
35
+ response = orcid_update.push_item(item, options)
36
+ if response.body["data"].present?
37
+ doi = response.body.fetch("data", {}).fetch("attributes", {}).fetch("doi", nil)
38
+ orcid = response.body.fetch("data", {}).fetch("attributes", {}).fetch("orcid", nil)
39
+ puts "DOI #{doi} for ORCID ID #{orcid} pushed to Profiles service."
40
+ elsif response.body["errors"].present?
41
+ puts "An error occured: #{response.body['errors'].first['title']}"
42
+ end
34
43
  end
35
44
  end
36
45
  end
@@ -40,17 +40,17 @@ module Toccatore
40
40
 
41
41
  # push to Volpino API if no error and we have collected works
42
42
  def push_data(items, options={})
43
- push_url = (options[:push_url].presence || "https://profiles.datacite.org/api") + "/claims"
44
- access_token = options[:access_token]
43
+ Array(items).map { |item| push_item(item, options) }
44
+ end
45
45
 
46
- return [] if items.empty?
47
- return [OpenStruct.new(body: { "errors" => [{ "title" => "Access token missing" }] })] if access_token.blank?
46
+ def push_item(item, options={})
47
+ return OpenStruct.new(body: { "errors" => [{ "title" => "Access token missing." }] }) if options[:access_token].blank?
48
48
 
49
- Array(items).map do |item|
50
- Maremma.post(push_url, data: { "claim" => item }.to_json,
51
- token: access_token,
52
- content_type: 'json')
53
- end
49
+ push_url = (options[:push_url].presence || "https://profiles.datacite.org/api") + "/claims"
50
+
51
+ Maremma.post(push_url, data: { "claim" => item }.to_json,
52
+ token: options[:access_token],
53
+ content_type: 'json')
54
54
  end
55
55
  end
56
56
  end
@@ -1,3 +1,3 @@
1
1
  module Toccatore
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/toccatore.rb CHANGED
@@ -1 +1,2 @@
1
1
  require "toccatore/orcid_update"
2
+ require "toccatore/cli"
data/spec/cli_spec.rb CHANGED
@@ -21,9 +21,19 @@ describe Toccatore::CLI do
21
21
  expect { subject.orcid_update }.to output(/DOI 10.6084\/M9.FIGSHARE.1041547 for ORCID ID 0000-0002-3546-1048 pushed to Profiles service.\n/).to_stdout
22
22
  end
23
23
 
24
+ it 'should succeed with no works' do
25
+ from_date = "2009-04-07"
26
+ until_date = "2009-04-08"
27
+ subject.options = { push_url: push_url,
28
+ access_token: access_token,
29
+ from_date: from_date,
30
+ until_date: until_date }
31
+ expect { subject.orcid_update }.to output("No works found for date range 2009-04-07 - 2009-04-08.\n").to_stdout
32
+ end
33
+
24
34
  it 'should fail' do
25
35
  subject.options = cli_options.except(:access_token)
26
- expect { subject.orcid_update }.to output("An error occured: Access token missing\n").to_stdout
36
+ expect { subject.orcid_update }.to output(/An error occured: Access token missing.\n/).to_stdout
27
37
  end
28
38
  end
29
39
  end
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://search.datacite.org/api?fl=doi,creator,title,publisher,publicationYear,resourceTypeGeneral,datacentre_symbol,relatedIdentifier,nameIdentifier,xml,minted,updated&fq=updated:%5B2009-04-07T00:00:00Z%20TO%202009-04-08T23:59:59Z%5D%20AND%20has_metadata:true%20AND%20is_active:true&q=nameIdentifier:ORCID%5C:*&rows=1000&start=0&wt=json
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
+ response:
15
+ status:
16
+ code: 200
17
+ message: ''
18
+ headers:
19
+ Server:
20
+ - openresty/1.11.2.1
21
+ Date:
22
+ - Mon, 30 Jan 2017 09:15:48 GMT
23
+ Content-Type:
24
+ - application/json;charset=UTF-8
25
+ Connection:
26
+ - keep-alive
27
+ Access-Control-Allow-Origin:
28
+ - "*"
29
+ Access-Control-Allow-Methods:
30
+ - GET, POST, OPTIONS
31
+ body:
32
+ encoding: UTF-8
33
+ string: '{"responseHeader":{"status":0,"QTime":1},"response":{"numFound":0,"start":0,"docs":[]}}
34
+
35
+ '
36
+ http_version:
37
+ recorded_at: Mon, 30 Jan 2017 09:15:48 GMT
38
+ recorded_with: VCR 3.0.3
@@ -97,7 +97,8 @@ describe Toccatore::OrcidUpdate, vcr: true do
97
97
  context "push_data" do
98
98
  it "should report if there are no works returned by the Datacite Metadata Search API" do
99
99
  result = []
100
- expect(subject.push_data(result)).to be_empty
100
+ response = subject.push_data(result)
101
+ expect(response.count).to eq(0)
101
102
  end
102
103
 
103
104
  it "should report if there are works returned by the Datacite Metadata Search API" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toccatore
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
@@ -262,6 +262,7 @@ files:
262
262
  - spec/fixtures/orcid_update_nil.json
263
263
  - spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_fail.yml
264
264
  - spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed.yml
265
+ - spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed_with_no_works.yml
265
266
  - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_report_if_there_are_no_works_returned_by_the_Datacite_Metadata_Search_API.yml
266
267
  - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml
267
268
  - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_total/with_no_works.yml
@@ -292,23 +293,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
293
  version: '0'
293
294
  requirements: []
294
295
  rubyforge_project:
295
- rubygems_version: 2.6.8
296
+ rubygems_version: 2.4.5
296
297
  signing_key:
297
298
  specification_version: 4
298
299
  summary: Ruby library to find ORCID IDs in the DataCite Solr index
299
- test_files:
300
- - spec/cli_spec.rb
301
- - spec/fixtures/orcid_update.json
302
- - spec/fixtures/orcid_update_nil.json
303
- - spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_fail.yml
304
- - spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_succeed.yml
305
- - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_report_if_there_are_no_works_returned_by_the_Datacite_Metadata_Search_API.yml
306
- - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml
307
- - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_total/with_no_works.yml
308
- - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_total/with_works.yml
309
- - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/push_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml
310
- - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/queue_jobs/should_report_if_there_are_no_works_returned_by_the_Datacite_Metadata_Search_API.yml
311
- - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/queue_jobs/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml
312
- - spec/orcid_update_spec.rb
313
- - spec/spec_helper.rb
314
- has_rdoc:
300
+ test_files: []