Class: Chimps::Commands::Upload
Constant Summary
collapse
- USAGE =
"usage: chimps upload [OPTIONS] ID_OR_SLUG [PATH|LINK] ..."
- HELP =
"\nCreate, modify, inspect, or submit an upload for the dataset with the\ngiven ID or slug on Infochimps.\n\nCheck the status of the current upload for 'my-dataset'\n\n $ chimps upload my-dataset\n\nIf this returns a \"404\" then it just means that the upload does not\nexist yet. You will also see whether the upload has started or not.\n\nAssuming the upload hasn't started, you can add files from your local\nmachine or links that you want Infochimps to scrape:\n\n $ chimps upload my-dataset /path/to/some/data.tsv\n $ chimps upload my-dataset http://www.cooldata.com/some/great/data.html\n $ chimps upload my-dataset s3://mybucket/some/open/data.xls\n\nYou can also pass more than one local file or link in each call to\n`chimps upload' if you wish.\n\nWhen you're ready to have Infochimps start processing the upload run\n\n $ chimps upload --start my-dataset\n\nYou can watch your upload's status by running\n\n $ chimps upload my-dataset\n\nat any time.\n"
Instance Attribute Summary
#config
Instance Method Summary
collapse
#initialize, name, #name
Instance Method Details
#execute! ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/chimps-cli/commands/upload.rb', line 50
def execute!
case
when config[:create]
upload.create
when config[:start]
upload.start.print
when config[:restart]
upload.restart.print
when config[:destroy]
upload.destroy.print
when objs_to_upload
links = []
upload.create if upload.show.error?
objs_to_upload.each do |obj|
if File.exist?(obj)
tok = upload.upload_token
upload.upload_file(obj, tok)
else
validate_link(obj)
links << obj
end
upload.create_links(*links) unless links.empty?
end
else
upload.show.print
end
end
|
#objs_to_upload ⇒ Object
46
47
48
|
# File 'lib/chimps-cli/commands/upload.rb', line 46
def objs_to_upload
config.argv[2..-1] if config.argv.size > 2
end
|
#upload ⇒ Object
40
41
42
43
44
|
# File 'lib/chimps-cli/commands/upload.rb', line 40
def upload
return @upload if @upload
raise CLIError.new(self.class::USAGE) if config.argv.size < 2 or config.argv[1].blank?
@upload = Chimps::Upload.new(config.argv[1])
end
|
#validate_link(link) ⇒ Object
78
79
80
81
|
# File 'lib/chimps-cli/commands/upload.rb', line 78
def validate_link link
scheme = link.split("://").first
raise UploadError.new("Infochimps only accepts links with a URI scheme (prefix) of http, https, ftp, or s3 -- you gave #{scheme}") unless ['http', 'https', 's3','ftp'].include?(scheme)
end
|