Class: Quandl::Command::Tasks::Upload

Inherits:
Base
  • Object
show all
Defined in:
lib/quandl/command/tasks/upload.rb

Instance Attribute Summary

Attributes inherited from Base

#args, #options, #request_timer

Instance Method Summary collapse

Methods inherited from Base

#ask_yes_or_no, authenticated_users_only!, autoload_client_library, call, #call, command_name, configure, #current_user, #debug, description, disable!, disable_in_gem!, disabled?, #error, #fatal, #force_yes?, #info, inherited, #initialize, lang, language, #logger, options, #summarize, #summarize_hash, syntax, t, #table, #verbose?, warn_unauthenticated_users

Constructor Details

This class inherits a constructor from Quandl::Command::Tasks::Base

Instance Method Details

#executeObject



36
37
38
39
40
41
42
43
44
# File 'lib/quandl/command/tasks/upload.rb', line 36

def execute
  # datasets from file_path if given
  interface = file_path.present? ? File.open(file_path, "r") : $stdin
  # for each dataset streamed from interface
  Quandl::Format::Dataset.each_line(interface) do |dataset|
    pool.process{ upload( dataset ) }
  end
  pool.shutdown
end

#file_pathObject



66
67
68
# File 'lib/quandl/command/tasks/upload.rb', line 66

def file_path
  args.first
end

#report(dataset) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/quandl/command/tasks/upload.rb', line 55

def report(dataset)
  if [200,201].include?( dataset.client.status )
    info table dataset.client.human_status,
      dataset.client.elapsed_request_time_ms,
      dataset.client.full_url
  else
    error(dataset.human_errors)
  end
  debug "---"
end

#upload(dataset) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/quandl/command/tasks/upload.rb', line 46

def upload(dataset)
  # display debug info when verbose
  debug dataset.attributes.to_s
  # upload
  dataset.upload if dataset.valid?
  # output report to $stdout or $stderr
  report(dataset)
end