Sha256: fa3dc6c58ce5bcc2b87e05c356488e2d673c84bd4f1a73e69e657c8e5eded702

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require "thor"

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

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

    desc "get DOI", "get handle url for DOI"
    method_option :username, :default => ENV['MDS_USERNAME']
    method_option :password, :default => ENV['MDS_PASSWORD']
    method_option :sandbox, :default => ENV['SANDBOX']
    def get(doi)
      if doi == "all"
        response = get_dois(options)
      else
        response = get_doi(doi, options)
      end

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

    desc "generate PREFIX", "generate a DOI name"
    method_option :prefix, :default => ENV['PREFIX']
    method_option :number, :type => :numeric, :aliases => '-n'
    def generate
      if options[:prefix]
        puts encode_doi(options[:prefix], number: options[:number])
      else
        puts "No PREFIX provided. Use --prefix option or PREFIX ENV variable"
      end
    end

    desc "check DOI", "check DOI using Crockford base32 checksum"
    def check(doi)
      if decode_doi(doi) > 0
        puts "Checksum for #{doi} is valid"
      else
        puts "Checksum for #{doi} is not valid"
      end
    end

    desc "register DOCUMENTS", "register documents"
    method_option :username, :default => ENV['MDS_USERNAME']
    method_option :password, :default => ENV['MDS_PASSWORD']
    method_option :sandbox, :default => ENV['SANDBOX']
    def register(filepath)

      if File.directory?(filepath)
        response = register_all_files(filepath, options)
      else
        response = register_file(filepath, options)
      end

      puts response
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cirneco-0.5.3 lib/cirneco/doi.rb