Sha256: 3f9b5351d853dbe07e0eea2819220d0a85d448bb54e18cb1ad61de0d986173f0

Contents?: true

Size: 1.48 KB

Versions: 34

Compression:

Stored size: 1.48 KB

Contents

require "thor"
require 'active_support/all'

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

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

    desc "get DOI", "get media 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_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

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


  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

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