Class: Chimps::Commands::Upload

Inherits:
Chimps::Command show all
Defined in:
lib/chimps/commands/upload.rb

Overview

A command for uploading data to Infochimps.

Constant Summary collapse

"usage: chimps upload [OPTIONS] ID_OR_HANDLE PATH [PATH] ..."
HELP =
<<EOF

Upload data from your local machine for an existing dataset identified
by ID_OR_HANDLE on Infochimps.

chimps will package all paths supplied into a local archive and then
upload this archive to Infochimps.  The local archive defaults to a
sensible name in the current directory but can also be customized.

If the only file to be packaged is already a package (.zip, .tar,
.tar.gz, &c.) then it will not be packaged again.

Supplied paths are allowed to be remote files so someting like

  chimps upload my-dataset path/to/local/file.txt http://my-site.com/path/to/remote/file.txt

will work.
EOF

Instance Attribute Summary collapse

Attributes inherited from Chimps::Command

#argv

Instance Method Summary collapse

Methods inherited from Chimps::Command

#initialize, name, #name

Constructor Details

This class inherits a constructor from Chimps::Command

Instance Attribute Details

#archiveObject (readonly)

The path to the archive



28
29
30
# File 'lib/chimps/commands/upload.rb', line 28

def archive
  @archive
end

#fmtObject (readonly)

The data format to annotate the upload with.

Chimps will try to guess if this isn’t given.



33
34
35
# File 'lib/chimps/commands/upload.rb', line 33

def fmt
  @fmt
end

Instance Method Details

#datasetString

The ID or handle of the dataset to upload data for.

Returns:

Raises:



38
39
40
41
# File 'lib/chimps/commands/upload.rb', line 38

def dataset
  raise CLIError.new("Must provide an ID or URL-escaped handle as the first argument") if argv.first.blank?
  argv.first
end

#define_upload_optionsObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/chimps/commands/upload.rb', line 51

def define_upload_options
  on_tail("-a", "--archive-path", "Path to the archive to be created.  Defaults to a timestamped ZIP file named after the dataset in the current directory.") do |path|
    @archive = path
  end

  on_tail("-f", "--format FORMAT", "Data format to annotate upload with.  Tries to guess if not given.") do |f|
    @fmt = f
  end
    
end

#execute!Object

Upload the data.



63
64
65
# File 'lib/chimps/commands/upload.rb', line 63

def execute!
  Chimps::Workflows::Up.new(:dataset => dataset, :archive => archive, :paths => paths, :fmt => fmt).execute!.print
end

#pathsArray<String>

A list of paths to upload.

Returns:

Raises:



46
47
48
49
# File 'lib/chimps/commands/upload.rb', line 46

def paths
  raise CLIError.new("Must provide some paths to upload") if argv.length < 2
  argv[1..-1]
end