Class: Cirneco::Media

Inherits:
Thor
  • Object
show all
Includes:
Api, Base, Utils
Defined in:
lib/cirneco/media.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

#get(doi) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cirneco/media.rb', line 18

def get(doi)
  response = get_media(doi, options.merge(raw: true))

  if response.body["errors"]
    puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
  else
    filename  = doi.split("/", 2).last + ".txt"
    content = response.body["data"]
    IO.write(filename, content)
    puts "Media for #{doi} saved as #{filename}"
  end
end

#post(doi) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cirneco/media.rb', line 36

def post(doi)
  filename  = options[:file] || doi.split("/", 2).last + ".txt"
  data = IO.read(filename)
  response = post_media(doi, data, options.merge(raw: true))

  if response.body["errors"]
    puts "Error: " + response.body["errors"].first.fetch("title", "An error occured")
  else
    puts response.body["data"]
  end
end