toccatore 0.2 → 0.2.2

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: 4a9e3668e6d812e727b1ccbeedfc424d773a6033
4
- data.tar.gz: 6b0d6168376296443570485308965df70de63026
3
+ metadata.gz: 42293b18d16efba366c96b902b4afdbda27e1c0c
4
+ data.tar.gz: 449ce93c8348885f619907c0eda997e3c51d079a
5
5
  SHA512:
6
- metadata.gz: 3dd61f043ee767072eb2d828bd34bd77a9f9c0a67bcc2e285e01a6d37d2699d8f7330d0fb2b097e704ece372a695e98d142268a5b9175d4bf9af2131218d1098
7
- data.tar.gz: 0ad6ae126d03d02e18a05a6ccd53d96591a2bbd6a0729445a05b9fda4433a70b8ff1d796fcee8e182ad2c7072c4e5a6b5530c5bbaffdd6ae525ca1784232a956
6
+ metadata.gz: 3f1992999cb94249db3d154025c587b6158449bb68111f3ac87e463cdb98025ebbddaa09a9945b0fadd43f5323f3bc92119738b1dee09d01b681a4a8fa37462e
7
+ data.tar.gz: 4eb82b6dd46ae1e7be78b87e44087d3c1ac41bc0fe64c5220e62a63a5117965e13d005b2c63ef7edbee62341f24c4d29b2a2bae146cb614fcc138257a1e0d8cf
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toccatore (0.2)
4
+ toccatore (0.2.2)
5
5
  activesupport (~> 4.2, >= 4.2.5)
6
6
  dotenv (~> 2.1, >= 2.1.1)
7
7
  gender_detector (~> 1.0)
@@ -23,7 +23,16 @@ module Toccatore
23
23
  def get_query_url(options={})
24
24
  updated = "updated:[#{options[:from_date]}T00:00:00Z TO #{options[:until_date]}T23:59:59Z]"
25
25
  fq = "#{updated} AND has_metadata:true AND is_active:true"
26
- q = options[:query].presence || query
26
+
27
+ if options[:doi].present?
28
+ q = "doi:#{options[:doi]}"
29
+ elsif options[:orcid].present?
30
+ q = "nameIdentifier:ORCID\\:#{options[:orcid]}"
31
+ elsif options[:query].present?
32
+ q = options[:query]
33
+ else
34
+ q = query
35
+ end
27
36
 
28
37
  params = { q: q,
29
38
  start: options[:offset],
@@ -358,6 +367,12 @@ module Toccatore
358
367
  def name_detector
359
368
  GenderDetector.new
360
369
  end
370
+
371
+ def unfreeze(hsh)
372
+ new_hash = {}
373
+ hsh.each_pair { |k,v| new_hash.merge!({k.downcase.to_sym => v}) }
374
+ new_hash
375
+ end
361
376
  end
362
377
  end
363
378
 
@@ -22,15 +22,13 @@ module Toccatore
22
22
  method_option :push_url, type: :string
23
23
  method_option :from_date, type: :string, default: (Time.now.to_date - 1.day).iso8601
24
24
  method_option :until_date, type: :string, default: Time.now.to_date.iso8601
25
- method_option :query, type: :string
25
+ method_option :q, type: :string
26
26
  method_option :orcid, type: :string
27
27
  method_option :doi, type: :string
28
+ method_option :claim_action, type: :string, default: "create"
28
29
  def orcid_update
29
- options[:query] = "doi:#{options[:doi]}" if options[:doi].present?
30
- options[:query] = "nameIdentifier:ORCID\\:#{options[:orcid]}" if options[:orcid].present?
31
-
32
30
  orcid_update = Toccatore::OrcidUpdate.new
33
- orcid_update.queue_jobs(options)
31
+ orcid_update.queue_jobs(orcid_update.unfreeze(options))
34
32
  end
35
33
  end
36
34
  end
@@ -14,12 +14,17 @@ module Toccatore
14
14
  return result.body.fetch("errors") if result.body.fetch("errors", nil).present?
15
15
 
16
16
  items = result.body.fetch("data", {}).fetch('response', {}).fetch('docs', nil)
17
+ claim_action = options[:claim_action].presence || "create"
17
18
 
18
19
  Array(items).reduce([]) do |sum, item|
19
20
  doi = item.fetch("doi")
21
+ related_identifiers = item.fetch("relatedIdentifier", [])
22
+ skip_doi = related_identifiers.any? do |related_identifier|
23
+ ["IsIdenticalTo", "IsPartOf"].include?(related_identifier.split(':', 3).first)
24
+ end
20
25
  name_identifiers = item.fetch("nameIdentifier", [])
21
26
 
22
- if name_identifiers.blank?
27
+ if name_identifiers.blank? || (skip_doi && claim_action == "create") || (!skip_doi && claim_action == "delete")
23
28
  sum
24
29
  else
25
30
  name_identifiers.each do |name_identifier|
@@ -31,7 +36,7 @@ module Toccatore
31
36
  sum << { "orcid" => orcid,
32
37
  "doi" => doi,
33
38
  "source_id" => source_id,
34
- "claim_action"=>"create" }
39
+ "claim_action"=> claim_action }
35
40
  end
36
41
  sum
37
42
  end
@@ -60,7 +65,8 @@ module Toccatore
60
65
  if response.body["data"].present?
61
66
  doi = response.body.fetch("data", {}).fetch("attributes", {}).fetch("doi", nil)
62
67
  orcid = response.body.fetch("data", {}).fetch("attributes", {}).fetch("orcid", nil)
63
- puts "DOI #{doi} for ORCID ID #{orcid} pushed to Profiles service."
68
+ claim_action = response.body.fetch("data", {}).fetch("attributes", {}).fetch("claim-action", nil)
69
+ puts "#{claim_action.titleize} DOI #{doi} for ORCID ID #{orcid} pushed to Profiles service."
64
70
  elsif response.body["errors"].present?
65
71
  puts "An error occured: #{response.body['errors'].first['title']}"
66
72
  end
@@ -1,3 +1,3 @@
1
1
  module Toccatore
2
- VERSION = "0.2"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -26,6 +26,11 @@ describe Toccatore::CLI do
26
26
  expect { subject.orcid_update }.to output(/DOI 10.5438\/6423 for ORCID ID 0000-0001-5331-6592 pushed to Profiles service.\n/).to_stdout
27
27
  end
28
28
 
29
+ it 'should delete' do
30
+ subject.options = cli_options.merge(doi: "10.6084/M9.FIGSHARE.4126869.V1", from_date: "2013-01-01", until_date: "2016-12-31", claim_action: "delete")
31
+ expect { subject.orcid_update }.to output(/Delete DOI 10.6084\/M9.FIGSHARE.4126869.V1 for ORCID ID 0000-0003-1013-1533 pushed to Profiles service.\n/).to_stdout
32
+ end
33
+
29
34
  it 'should query by ORCID ID' do
30
35
  subject.options = cli_options.merge(orcid: "0000-0002-3546-1048", from_date: "2013-01-01", until_date: "2016-12-31")
31
36
  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
@@ -0,0 +1,24 @@
1
+ {
2
+ "responseHeader": {
3
+ "status": 0,
4
+ "QTime": 0
5
+ },
6
+ "response": {
7
+ "numFound": 1,
8
+ "start": 0,
9
+ "docs": [{
10
+ "minted": "2016-10-28T21:43:49Z",
11
+ "datacentre_symbol": "FIGSHARE.ARS",
12
+ "xml": "PHJlc291cmNlIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtMyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtMyBodHRwOi8vc2NoZW1hLmRhdGFjaXRlLm9yZy9tZXRhL2tlcm5lbC0zL21ldGFkYXRhLnhzZCI+PGlkZW50aWZpZXIgaWRlbnRpZmllclR5cGU9IkRPSSI+MTAuNjA4NC9tOS5maWdzaGFyZS40MTI2ODY5LnYxPC9pZGVudGlmaWVyPjxjcmVhdG9ycz48Y3JlYXRvcj48Y3JlYXRvck5hbWU+U2hpcmxleSBaaGFvPC9jcmVhdG9yTmFtZT48bmFtZUlkZW50aWZpZXIgbmFtZUlkZW50aWZpZXJTY2hlbWU9Ik9SQ0lEIiBzY2hlbWVVUkk9Imh0dHA6Ly9vcmNpZC5vcmciPjAwMDAtMDAwMy0xMDEzLTE1MzM8L25hbWVJZGVudGlmaWVyPjwvY3JlYXRvcj48L2NyZWF0b3JzPjx0aXRsZXM+PHRpdGxlPkluZm9ybWF0aW9uIEVsZXZhdGVkJTNBIEpvaW4gdGhlIFV0YWggU29jaWV0eSBvZiBIZWFsdGggU2NpZW5jZXMgTGlicmFyaWFuczwvdGl0bGU+PC90aXRsZXM+PGRlc2NyaXB0aW9ucz48ZGVzY3JpcHRpb24gZGVzY3JpcHRpb25UeXBlPSJBYnN0cmFjdCI+VGhlIFV0YWggU29jaWV0eSBvZiBI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0aW9uVHlwZT0iSXNJZGVudGljYWxUbyI+MTAuNjA4NC9tOS5maWdzaGFyZS40MTI2ODY5PC9yZWxhdGVkSWRlbnRpZmllcj48L3JlbGF0ZWRJZGVudGlmaWVycz48cmlnaHRzTGlzdD48cmlnaHRzIHJpZ2h0c1VSST0iaHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LzQuMC8iPkNDLUJZPC9yaWdodHM+PC9yaWdodHNMaXN0PjwvcmVzb3VyY2U+",
13
+ "updated": "2016-10-28T21:44:42Z",
14
+ "doi": "10.6084/M9.FIGSHARE.4126869.V1",
15
+ "publisher": "Figshare",
16
+ "creator": ["Shirley Zhao"],
17
+ "title": ["Information Elevated%3A Join the Utah Society of Health Sciences Librarians"],
18
+ "resourceTypeGeneral": "Image",
19
+ "relatedIdentifier": ["IsIdenticalTo:DOI:10.6084/m9.figshare.4126869"],
20
+ "nameIdentifier": ["ORCID:0000-0003-1013-1533"],
21
+ "publicationYear": "2016"
22
+ }]
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "responseHeader": {
3
+ "status": 0,
4
+ "QTime": 2
5
+ },
6
+ "response": {
7
+ "numFound": 1,
8
+ "start": 0,
9
+ "docs": [{
10
+ "minted": "2016-12-17T09:20:41Z",
11
+ "datacentre_symbol": "BL.IMPERIAL",
12
+ "xml": "PHJlc291cmNlIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtNCIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtNCBodHRwOi8vc2NoZW1hLmRhdGFjaXRlLm9yZy9tZXRhL2tlcm5lbC00L21ldGFkYXRhLnhzZCI+CiAgPGlkZW50aWZpZXIgaWRlbnRpZmllclR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QnkiPjEwLjE0NDY5L2hwYy8xOTg2PC9yZWxhdGVkSWRlbnRpZmllcj4KICAgIDxyZWxhdGVkSWRlbnRpZmllciByZWxhdGVkSWRlbnRpZmllclR5cGU9IkRPSSIgcmVsYXRpb25UeXBlPSJJc1BhcnRPZiI+MTAuMTQ0NjkvaHBjLzE3NzwvcmVsYXRlZElkZW50aWZpZXI+CiAgPC9yZWxhdGVkSWRlbnRpZmllcnM+CiAgPHN1YmplY3RzLz4KICA8cmlnaHRzTGlzdD4KICAgIDxyaWdodHMgcmlnaHRzVVJJPSJodHRwczovL2NyZWF0aXZlY29tbW9ucy5vcmcvcHVibGljZG9tYWluL3plcm8vMS4wLyI+Q3JlYXRpdmUgQ29tbW9ucyBQdWJsaWMgRG9tYWluIERlZGljYXRpb24gKENDMCAxLjApPC9yaWdodHM+CiAgPC9yaWdodHNMaXN0PgogIDxyZXNvdXJjZVR5cGUgcmVzb3VyY2VUeXBlR2VuZXJhbD0iRGF0YXNldCIvPgo8L3Jlc291cmNlPgo=",
13
+ "updated": "2016-12-17T10:00:10Z",
14
+ "doi": "10.14469/HPC/1985",
15
+ "relatedIdentifier": ["HasMetadata:URL:https://data.hpc.imperial.ac.uk/resolve/?ore=1985", "HasPart:URL:https://data.hpc.imperial.ac.uk/resolve/?doi=1985&file=1", "HasPart:URL:https://data.hpc.imperial.ac.uk/resolve/?doi=1985&file=2", "HasPart:URL:https://data.hpc.imperial.ac.uk/resolve/?doi=1985&file=3", "IsReferencedBy:DOI:10.14469/hpc/1986", "IsPartOf:DOI:10.14469/hpc/177"],
16
+ "creator": ["Henry Rzepa"],
17
+ "publisher": "Imperial College London",
18
+ "title": ["CrN123: QTAIM analysis"],
19
+ "nameIdentifier": ["ORCID:0000-0002-8635-8390"],
20
+ "publicationYear": "2016",
21
+ "resourceTypeGeneral": "Dataset"
22
+ }]
23
+ }
24
+ }
@@ -0,0 +1,134 @@
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:%5B2013-01-01T00:00:00Z%20TO%202016-12-31T23:59:59Z%5D%20AND%20has_metadata:true%20AND%20is_active:true&q=doi:10.6084/M9.FIGSHARE.4126869.V1&rows=0&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
+ - Sat, 04 Feb 2017 07:15:42 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":1,"start":0,"docs":[]}}
34
+
35
+ '
36
+ http_version:
37
+ recorded_at: Sat, 04 Feb 2017 07:15:42 GMT
38
+ - request:
39
+ method: get
40
+ uri: https://search.datacite.org/api?fl=doi,creator,title,publisher,publicationYear,resourceTypeGeneral,datacentre_symbol,relatedIdentifier,nameIdentifier,xml,minted,updated&fq=updated:%5B2013-01-01T00:00:00Z%20TO%202016-12-31T23:59:59Z%5D%20AND%20has_metadata:true%20AND%20is_active:true&q=doi:10.6084/M9.FIGSHARE.4126869.V1&rows=1000&start=0&wt=json
41
+ body:
42
+ encoding: US-ASCII
43
+ string: ''
44
+ headers:
45
+ User-Agent:
46
+ - Maremma - https://github.com/datacite/maremma
47
+ Accept:
48
+ - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5
49
+ response:
50
+ status:
51
+ code: 200
52
+ message: ''
53
+ headers:
54
+ Server:
55
+ - openresty/1.11.2.1
56
+ Date:
57
+ - Sat, 04 Feb 2017 07:15:42 GMT
58
+ Content-Type:
59
+ - application/json;charset=UTF-8
60
+ Connection:
61
+ - keep-alive
62
+ Access-Control-Allow-Origin:
63
+ - "*"
64
+ Access-Control-Allow-Methods:
65
+ - GET, POST, OPTIONS
66
+ body:
67
+ encoding: UTF-8
68
+ string: '{"responseHeader":{"status":0,"QTime":2},"response":{"numFound":1,"start":0,"docs":[{"minted":"2016-10-28T21:43:49Z","datacentre_symbol":"FIGSHARE.ARS","xml":"PHJlc291cmNlIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtMyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtMyBodHRwOi8vc2NoZW1hLmRhdGFjaXRlLm9yZy9tZXRhL2tlcm5lbC0zL21ldGFkYXRhLnhzZCI+PGlkZW50aWZpZXIgaWRlbnRpZmllclR5cGU9IkRPSSI+MTAuNjA4NC9tOS5maWdzaGFyZS40MTI2ODY5LnYxPC9pZGVudGlmaWVyPjxjcmVhdG9ycz48Y3JlYXRvcj48Y3JlYXRvck5hbWU+U2hpcmxleSBaaGFvPC9jcmVhdG9yTmFtZT48bmFtZUlkZW50aWZpZXIgbmFtZUlkZW50aWZpZXJTY2hlbWU9Ik9SQ0lEIiBzY2hlbWVVUkk9Imh0dHA6Ly9vcmNpZC5vcmciPjAwMDAtMDAwMy0xMDEzLTE1MzM8L25hbWVJZGVudGlmaWVyPjwvY3JlYXRvcj48L2NyZWF0b3JzPjx0aXRsZXM+PHRpdGxlPkluZm9ybWF0aW9uIEVsZXZhdGVkJTNBIEpvaW4gdGhlIFV0YWggU29jaWV0eSBvZ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mNlVHlwZT48c2l6ZXM+PHNpemU+NTM1MzI5IEJ5dGVzPC9zaXplPjwvc2l6ZXM+PHJlbGF0ZWRJZGVudGlmaWVycz48cmVsYXRlZElkZW50aWZpZXIgcmVsYXRlZElkZW50aWZpZXJUeXBlPSJET0kiIHJlbGF0aW9uVHlwZT0iSXNJZGVudGljYWxUbyI+MTAuNjA4NC9tOS5maWdzaGFyZS40MTI2ODY5PC9yZWxhdGVkSWRlbnRpZmllcj48L3JlbGF0ZWRJZGVudGlmaWVycz48cmlnaHRzTGlzdD48cmlnaHRzIHJpZ2h0c1VSST0iaHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LzQuMC8iPkNDLUJZPC9yaWdodHM+PC9yaWdodHNMaXN0PjwvcmVzb3VyY2U+","updated":"2016-10-28T21:44:42Z","doi":"10.6084/M9.FIGSHARE.4126869.V1","publisher":"Figshare","creator":["Shirley
69
+ Zhao"],"title":["Information Elevated%3A Join the Utah Society of Health Sciences
70
+ Librarians"],"resourceTypeGeneral":"Image","relatedIdentifier":["IsIdenticalTo:DOI:10.6084/m9.figshare.4126869"],"nameIdentifier":["ORCID:0000-0003-1013-1533"],"publicationYear":"2016"}]}}
71
+
72
+ '
73
+ http_version:
74
+ recorded_at: Sat, 04 Feb 2017 07:15:42 GMT
75
+ - request:
76
+ method: post
77
+ uri: https://profiles.test.datacite.org/api/claims
78
+ body:
79
+ encoding: UTF-8
80
+ string: '{"claim":{"orcid":"0000-0003-1013-1533","doi":"10.6084/M9.FIGSHARE.4126869.V1","source_id":"orcid_update","claim_action":"delete"}}'
81
+ headers:
82
+ User-Agent:
83
+ - Maremma - https://github.com/datacite/maremma
84
+ Content-Type:
85
+ - application/json
86
+ Accept:
87
+ - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5
88
+ Authorization:
89
+ - Token token=<VOLPINO_TOKEN>
90
+ response:
91
+ status:
92
+ code: 202
93
+ message: ''
94
+ headers:
95
+ Server:
96
+ - openresty/1.11.2.1
97
+ Date:
98
+ - Sat, 04 Feb 2017 07:15:42 GMT
99
+ Content-Type:
100
+ - application/json; charset=utf-8
101
+ Connection:
102
+ - keep-alive
103
+ Status:
104
+ - 202 Accepted
105
+ Cache-Control:
106
+ - no-cache
107
+ Access-Control-Allow-Origin:
108
+ - "*"
109
+ Vary:
110
+ - Accept-Encoding
111
+ Access-Control-Max-Age:
112
+ - '1728000'
113
+ X-Xss-Protection:
114
+ - 1; mode=block
115
+ X-Request-Id:
116
+ - f2c75afc-f780-48cf-a92b-5663fd8b3e68
117
+ Access-Control-Allow-Headers:
118
+ - Origin, Content-Type, Accept, Authorization, Token
119
+ Access-Control-Allow-Methods:
120
+ - GET, POST, OPTIONS
121
+ X-Runtime:
122
+ - '0.084516'
123
+ X-Frame-Options:
124
+ - SAMEORIGIN
125
+ X-Content-Type-Options:
126
+ - nosniff
127
+ X-Powered-By:
128
+ - Phusion Passenger 5.1.2
129
+ body:
130
+ encoding: UTF-8
131
+ string: '{"data":{"id":"df624600-24c0-4d97-a85e-ca8fe165fe40","type":"claims","attributes":{"orcid":"0000-0003-1013-1533","doi":"10.6084/M9.FIGSHARE.4126869.V1","source-id":"orcid_update","state":"waiting","claim-action":"delete","claimed-at":null}}}'
132
+ http_version:
133
+ recorded_at: Sat, 04 Feb 2017 07:15:42 GMT
134
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://profiles.test.datacite.org/api/claims
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"claim":{"orcid":"0000-0003-1013-1533","doi":"10.6084/M9.FIGSHARE.4126869.V1","source_id":"orcid_update","claim_action":"delete"}}'
9
+ headers:
10
+ User-Agent:
11
+ - Maremma - https://github.com/datacite/maremma
12
+ Content-Type:
13
+ - application/json
14
+ Accept:
15
+ - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5
16
+ Authorization:
17
+ - Token token=<VOLPINO_TOKEN>
18
+ response:
19
+ status:
20
+ code: 202
21
+ message: ''
22
+ headers:
23
+ Server:
24
+ - openresty/1.11.2.1
25
+ Date:
26
+ - Sat, 04 Feb 2017 07:26:47 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Connection:
30
+ - keep-alive
31
+ Status:
32
+ - 202 Accepted
33
+ Cache-Control:
34
+ - no-cache
35
+ Access-Control-Allow-Origin:
36
+ - "*"
37
+ Vary:
38
+ - Accept-Encoding
39
+ Access-Control-Max-Age:
40
+ - '1728000'
41
+ X-Xss-Protection:
42
+ - 1; mode=block
43
+ X-Request-Id:
44
+ - 1f76ff9a-5012-467d-b187-dc044107faaa
45
+ Access-Control-Allow-Headers:
46
+ - Origin, Content-Type, Accept, Authorization, Token
47
+ Access-Control-Allow-Methods:
48
+ - GET, POST, OPTIONS
49
+ X-Runtime:
50
+ - '0.008897'
51
+ X-Frame-Options:
52
+ - SAMEORIGIN
53
+ X-Content-Type-Options:
54
+ - nosniff
55
+ X-Powered-By:
56
+ - Phusion Passenger 5.1.2
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"data":{"id":"df624600-24c0-4d97-a85e-ca8fe165fe40","type":"claims","attributes":{"orcid":"0000-0003-1013-1533","doi":"10.6084/M9.FIGSHARE.4126869.V1","source-id":"orcid_update","state":"failed","claim-action":"delete","claimed-at":null}}}'
60
+ http_version:
61
+ recorded_at: Tue, 07 Apr 2015 22:00:00 GMT
62
+ recorded_with: VCR 3.0.3
@@ -63,14 +63,14 @@ describe Toccatore::OrcidUpdate, vcr: true do
63
63
  end
64
64
 
65
65
  it "should allow queries by ORCID ID of the Datacite Metadata Search API" do
66
- response = subject.get_data({ query: "nameIdentifier:ORCID\\:0000-0002-3546-1048", from_date: "2013-01-01", until_date: "2016-12-31", rows: 1000, offset: 0 })
66
+ response = subject.get_data({ orcid: "0000-0002-3546-1048", from_date: "2013-01-01", until_date: "2016-12-31", rows: 1000, offset: 0 })
67
67
  expect(response.body["data"]["response"]["numFound"]).to eq(68)
68
68
  doc = response.body["data"]["response"]["docs"].first
69
69
  expect(doc["doi"]).to eq("10.6084/M9.FIGSHARE.1371005.V1")
70
70
  end
71
71
 
72
72
  it "should allow queries by DOI of the Datacite Metadata Search API" do
73
- response = subject.get_data({ query: "doi:10.5438/6423", from_date: "2013-01-01", until_date: "2016-12-31", rows: 1000, offset: 0 })
73
+ response = subject.get_data({ doi: "10.5438/6423", from_date: "2013-01-01", until_date: "2016-12-31", rows: 1000, offset: 0 })
74
74
  expect(response.body["data"]["response"]["numFound"]).to eq(1)
75
75
  doc = response.body["data"]["response"]["docs"].first
76
76
  name_identifiers = doc["nameIdentifier"]
@@ -105,6 +105,24 @@ describe Toccatore::OrcidUpdate, vcr: true do
105
105
  "claim_action" => "create")
106
106
  end
107
107
 
108
+ it "should report if there are works ignored because of an IsIdenticalTo relation" do
109
+ body = File.read(fixture_path + 'orcid_update_is_identical.json')
110
+ result = OpenStruct.new(body: { "data" => JSON.parse(body) })
111
+ expect(subject.parse_data(result)).to eq([])
112
+ end
113
+
114
+ it "should report if there are works ignored because of an IsPartOf relation" do
115
+ body = File.read(fixture_path + 'orcid_update_is_part.json')
116
+ result = OpenStruct.new(body: { "data" => JSON.parse(body) })
117
+ expect(subject.parse_data(result)).to eq([])
118
+ end
119
+
120
+ it "should report if there are works because of an IsIdenticalTo relation and delete action" do
121
+ body = File.read(fixture_path + 'orcid_update_is_identical.json')
122
+ result = OpenStruct.new(body: { "data" => JSON.parse(body) })
123
+ expect(subject.parse_data(result, claim_action: "delete")).to eq([{"orcid"=>"0000-0003-1013-1533", "doi"=>"10.6084/M9.FIGSHARE.4126869.V1", "source_id"=>"orcid_update", "claim_action"=>"delete"}])
124
+ end
125
+
108
126
  it "should catch timeout errors with the Datacite Metadata Search API" do
109
127
  result = OpenStruct.new(body: { "errors" => [{ "title" => "the server responded with status 408 for https://search.datacite.org", "status" => 408 }] })
110
128
  response = subject.parse_data(result)
@@ -123,7 +141,21 @@ describe Toccatore::OrcidUpdate, vcr: true do
123
141
  result = OpenStruct.new(body: { "data" => JSON.parse(body) })
124
142
  result = subject.parse_data(result)
125
143
  options = { push_url: ENV['VOLPINO_URL'], access_token: ENV['VOLPINO_TOKEN'] }
126
- expect { subject.push_data(result, options) }.to output(/DOI 10.6084\/M9.FIGSHARE.1041547 for ORCID ID 0000-0002-3546-1048 pushed to Profiles service.\n/).to_stdout
144
+ expect { subject.push_data(result, options) }.to output(/Create DOI 10.6084\/M9.FIGSHARE.1041547 for ORCID ID 0000-0002-3546-1048 pushed to Profiles service.\n/).to_stdout
145
+ end
146
+
147
+ it "should delete claims" do
148
+ body = File.read(fixture_path + 'orcid_update_is_identical.json')
149
+ result = OpenStruct.new(body: { "data" => JSON.parse(body) })
150
+ result = subject.parse_data(result, claim_action: "delete")
151
+ options = { push_url: ENV['VOLPINO_URL'], access_token: ENV['VOLPINO_TOKEN'], from_date: "2013-01-01", until_date: "2016-12-31", claim_action: "delete" }
152
+ expect { subject.push_data(result, options) }.to output(/Delete DOI 10.6084\/M9.FIGSHARE.4126869.V1 for ORCID ID 0000-0003-1013-1533 pushed to Profiles service.\n/).to_stdout
153
+ end
154
+ end
155
+
156
+ context "unfreeze" do
157
+ it "should unfreeze" do
158
+ expect(subject.unfreeze(query_options)).to eq(:from_date=>"2015-04-07", :until_date=>"2015-04-08", :rows=>1000, :offset=>0)
127
159
  end
128
160
  end
129
161
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toccatore
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
11
+ date: 2017-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: maremma
@@ -260,7 +260,10 @@ files:
260
260
  - lib/toccatore/version.rb
261
261
  - spec/cli_spec.rb
262
262
  - spec/fixtures/orcid_update.json
263
+ - spec/fixtures/orcid_update_is_identical.json
264
+ - spec/fixtures/orcid_update_is_part.json
263
265
  - spec/fixtures/orcid_update_nil.json
266
+ - spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_delete.yml
264
267
  - spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_fail.yml
265
268
  - spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_DOI.yml
266
269
  - spec/fixtures/vcr_cassettes/Toccatore_CLI/orcid_update/should_query_by_ORCID_ID.yml
@@ -273,6 +276,7 @@ files:
273
276
  - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml
274
277
  - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_total/with_no_works.yml
275
278
  - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/get_total/with_works.yml
279
+ - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/push_data/should_delete_claims.yml
276
280
  - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/push_data/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml
277
281
  - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/queue_jobs/should_report_if_there_are_no_works_returned_by_the_Datacite_Metadata_Search_API.yml
278
282
  - spec/fixtures/vcr_cassettes/Toccatore_OrcidUpdate/queue_jobs/should_report_if_there_are_works_returned_by_the_Datacite_Metadata_Search_API.yml