Sha256: 50264e6c5eb64134f967881aad210cd8bca6cc1534877a3a7ee888ae771b3a4f

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

class Quandl::Command::Tasks::Delete < Quandl::Command::Tasks::Base
  autoload_client_library
  
  syntax "quandl #{command_name} (SOURCE_CODE/)CODE"
  description "Delete a dataset by its quandl code."
  
  authenticated_users_only!
    
  def execute
    # download using arguments when present
    return delete_each_argument if args.first.present?
    # otherwise delete using stdin
    delete_each_stdin
  end
  
  def delete_each_argument
    args.each do |code| 
      pool.process{ delete( code ) }
    end
    pool.shutdown
  end
  
  def delete_each_stdin
    return error("Cannot delete datasets from STDIN unless --force-yes is set!") unless force_yes?
    $stdin.each_line do |code|
      pool.process{ delete( code.strip.rstrip ) }
    end
    pool.shutdown
  end
  
  def delete(code)
    return error("You must provide a code!") if code.blank?
    # find by code
    dataset = Quandl::Client::Dataset.find(code)
    # fail fast if dataset does not exist
    return error(table(Quandl::Client::HTTP_STATUS_CODES[404], code)) if dataset.nil?
    return report(dataset) unless dataset.exists?
    # confirm deletion
    return error("You must confirm deletion!") unless confirmed?(dataset)
    # delete if exists
    dataset.destroy if dataset.exists?
    # output status
    report(dataset)
  end
  
  def report(dataset)
    # message
    m = table dataset.elapsed_request_time_ms, dataset.full_code
    # report
    dataset.status == 200 ? info(table("Deleted", m)) : error(table(dataset.human_status, m))
  end
  
  def confirmed?(dataset)
    return true if force_yes?
    info summarize dataset.attributes.slice('source_code', 'code', 'name', 'from_date', 'to_date', 'column_names', 'created_at')
    ask_yes_or_no
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
quandl-0.2.25 lib/quandl/command/tasks/delete.rb
quandl-0.2.24 lib/quandl/command/tasks/delete.rb