Sha256: d6586275d2fcd15795dc413bd88c8e7d402a5a2f8ef3ad7272790565974095ee

Contents?: true

Size: 1.83 KB

Versions: 34

Compression:

Stored size: 1.83 KB

Contents

require "thor"
require 'active_support/all'

require_relative 'api'
require_relative 'utils'
require_relative 'base'

module Cirneco
  class Metadata < Thor
    include Cirneco::Base
    include Cirneco::Api
    include Cirneco::Utils

    desc "get DOI", "get metadata for DOI"
    method_option :username, :default => ENV['MDS_USERNAME']
    method_option :password, :default => ENV['MDS_PASSWORD']
    method_option :sandbox, :type => :boolean, :force => false
    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

    desc "post DOI", "post metadata for DOI"
    method_option :username, :default => ENV['MDS_USERNAME']
    method_option :password, :default => ENV['MDS_PASSWORD']
    method_option :sandbox, :type => :boolean, :force => false
    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.headers["Location"]
      end
    end

    desc "delete DOI", "hide metadata for DOI"
    method_option :username, :default => ENV['MDS_USERNAME']
    method_option :password, :default => ENV['MDS_PASSWORD']
    method_option :sandbox, :type => :boolean, :force => false
    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
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
cirneco-0.9.20 lib/cirneco/metadata.rb
cirneco-0.9.19 lib/cirneco/metadata.rb
cirneco-0.9.18 lib/cirneco/metadata.rb
cirneco-0.9.17 lib/cirneco/metadata.rb
cirneco-0.9.13 lib/cirneco/metadata.rb
cirneco-0.9.12 lib/cirneco/metadata.rb
cirneco-0.9.11 lib/cirneco/metadata.rb
cirneco-0.9.10 lib/cirneco/metadata.rb
cirneco-0.9.9 lib/cirneco/metadata.rb
cirneco-0.9.8 lib/cirneco/metadata.rb
cirneco-0.9.7 lib/cirneco/metadata.rb
cirneco-0.9.6 lib/cirneco/metadata.rb
cirneco-0.9.5 lib/cirneco/metadata.rb
cirneco-0.9.4 lib/cirneco/metadata.rb
cirneco-0.9.3 lib/cirneco/metadata.rb
cirneco-0.9.2 lib/cirneco/metadata.rb
cirneco-0.9.1 lib/cirneco/metadata.rb
cirneco-0.9 lib/cirneco/metadata.rb
cirneco-0.8.12 lib/cirneco/metadata.rb
cirneco-0.8.11 lib/cirneco/metadata.rb