Class: Toccatore::OrcidUpdate
- Inherits:
-
Base
- Object
- Base
- Toccatore::OrcidUpdate
show all
- Defined in:
- lib/toccatore/orcid_update.rb
Instance Method Summary
collapse
Methods inherited from Base
#clean_doi, #cleanup_author, #config_fields, #doi_as_url, #doi_from_url, #get_authors, #get_contributions, #get_data, #get_doi_relations, #get_github_relations, #get_hashed_authors, #get_name_identifier, #get_one_author, #get_one_hashed_author, #get_query_url, #get_relations_with_related_works, #get_total, #is_personal_name?, #job_batch_size, #name_detector, #orcid_as_url, #orcid_from_url, #process_data, #queue_jobs, #timeout, #url, #validate_orcid
Instance Method Details
#parse_data(result, options = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/toccatore/orcid_update.rb', line 13
def parse_data(result, options={})
return result.body.fetch("errors") if result.body.fetch("errors", nil).present?
items = result.body.fetch("data", {}).fetch('response', {}).fetch('docs', nil)
Array(items).reduce([]) do |sum, item|
doi = item.fetch("doi")
name_identifiers = item.fetch("nameIdentifier", [])
if name_identifiers.blank?
sum
else
name_identifiers.each do |name_identifier|
orcid = name_identifier.split(':', 2).last
orcid = validate_orcid(orcid)
next if orcid.blank?
sum << { "orcid" => orcid,
"doi" => doi,
"source_id" => source_id,
"claim_action"=>"create" }
end
sum
end
end
end
|
#push_data(items, options = {}) ⇒ Object
push to Volpino API if no error and we have collected works
42
43
44
45
46
47
48
49
50
|
# File 'lib/toccatore/orcid_update.rb', line 42
def push_data(items, options={})
if items.empty?
puts "No works found for date range #{options[:from_date]} - #{options[:until_date]}."
elsif options[:access_token].blank?
puts "An error occured: Access token missing."
else
Array(items).each { |item| push_item(item, options) }
end
end
|
#push_item(item, options = {}) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/toccatore/orcid_update.rb', line 52
def push_item(item, options={})
return OpenStruct.new(body: { "errors" => [{ "title" => "Access token missing." }] }) if options[:access_token].blank?
push_url = (options[:push_url].presence || "https://profiles.datacite.org/api") + "/claims"
response = Maremma.post(push_url, data: { "claim" => item }.to_json,
token: options[:access_token],
content_type: 'json')
if response.body["data"].present?
doi = response.body.fetch("data", {}).fetch("attributes", {}).fetch("doi", nil)
orcid = response.body.fetch("data", {}).fetch("attributes", {}).fetch("orcid", nil)
puts "DOI #{doi} for ORCID ID #{orcid} pushed to Profiles service."
elsif response.body["errors"].present?
puts "An error occured: #{response.body['errors'].first['title']}"
end
end
|
#query ⇒ Object
9
10
11
|
# File 'lib/toccatore/orcid_update.rb', line 9
def query
"nameIdentifier:ORCID\\:*"
end
|
#source_id ⇒ Object
5
6
7
|
# File 'lib/toccatore/orcid_update.rb', line 5
def source_id
"orcid_update"
end
|