Class: Cirneco::Metadata
- Inherits:
-
Thor
- Object
- Thor
- Cirneco::Metadata
show all
- Includes:
- Bolognese::DoiUtils, Api, Base, Utils
- Defined in:
- lib/cirneco/metadata.rb
Constant Summary
Constants included
from Utils
Utils::UPPER_LIMIT
Instance Method Summary
collapse
Methods included from Utils
#decode_doi, #encode_doi, #generate_accession_number, #generate_state_change_template, #generate_transfer_template, #get_dois_by_prefix
Methods included from Api
#delete_metadata, #get_doi, #get_dois, #get_media, #get_metadata, #get_rest_doi, #post_media, #post_metadata, #put_doi, #put_metadata, #transfer_doi, #update_rest_doi
Instance Method Details
#delete(doi) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/cirneco/metadata.rb', line 76
def delete(doi)
response = delete_metadata(doi, options)
if response.body["errors"]
puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
else
puts response.body["data"]
end
end
|
#get(doi) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/cirneco/metadata.rb', line 20
def get(doi)
response = get_metadata(doi, options)
if response.body["errors"]
puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
else
filename = doi.split("/", 2).last + ".xml"
content = response.body["data"]
IO.write(filename, content)
puts "Metadata for #{doi} saved as #{filename}"
end
end
|
#post(file) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/cirneco/metadata.rb', line 37
def post(file)
data = IO.read(file)
response = post_metadata(data, options)
if response.body["errors"]
puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
else
puts response.["Location"]
end
end
|
#put(file) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/cirneco/metadata.rb', line 52
def put(file)
data = JSON.parse(IO.read(file))
count = 0
data.each do |json|
doi = doi_from_url(json["@id"])
next unless doi.present?
response = put_metadata(doi, options.merge(data: json.to_json))
if response.body["errors"]
puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
else
puts response.["Location"]
count += 1
end
end
puts "#{count} DOIs registered/updated."
end
|