Class: Chimps::Commands::Batch

Inherits:
Chimps::Command show all
Includes:
Utils::UsesYamlData
Defined in:
lib/chimps/commands/batch.rb

Overview

A command for performing batch updates.

Constant Summary collapse

"usage: chimps batch [OPTIONS] [INPUT_PATH] ..."
HELP =
"\nPerform a batch operation on Infochimps by reading YAML input files.\n\nThe input files should collectively define an array of resources to\nmake create or update requests on.  Each request in the array is\ntreated separately (even though the entire array is processed as one\nPOST request) and so it is possible that some will succeed and others\nfail.\n\nIt is also possible to upload data in this batch process.  Each\n(successful) request which defined a 'local_paths' property in the\noriginal input files will have the data at these paths uploaded to\nInfochimps.  These uploads will proceed one at a time following the\ninitial batch POST request.\n\nThe format of the YAML input files is given at\n\n  http://infochimps.org/api\n"

Instance Attribute Summary collapse

Attributes included from Utils::UsesYamlData

#data_file

Attributes inherited from Chimps::Command

#argv

Instance Method Summary collapse

Methods included from Utils::UsesYamlData

#data, #ignore_first_arg_on_command_line, #ignore_yaml_files_on_command_line

Methods inherited from Chimps::Command

#initialize, name, #name

Constructor Details

This class inherits a constructor from Chimps::Command

Instance Attribute Details

#fmtObject (readonly)

The data format to annotate the upload with.

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



36
37
38
# File 'lib/chimps/commands/batch.rb', line 36

def fmt
  @fmt
end

#output_pathObject

A path to store the intermediate batch response. Useful for debugging.



31
32
33
# File 'lib/chimps/commands/batch.rb', line 31

def output_path
  @output_path
end

#upload_even_if_errorsObject

Whether to continue to upload even if some of the resources had errors on update/create.



40
41
42
# File 'lib/chimps/commands/batch.rb', line 40

def upload_even_if_errors
  @upload_even_if_errors
end

Instance Method Details

#define_optionsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chimps/commands/batch.rb', line 44

def define_options
  on_tail("-o", "--output PATH", "Store the response from the server at PATH") do |o|
    @output_path = File.expand_path(o)
  end

  on_tail("-e", "--force", "Attempt to upload data even when there were errors in the batch update request") do |e|
    @upload_even_if_errors = e
  end

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

#execute!Object

Perform the batch update and upload.



60
61
62
63
# File 'lib/chimps/commands/batch.rb', line 60

def execute!
  ensure_data_is_present!
  Chimps::Workflows::BatchUpdater.new(data, :output_path => output_path, :upload_even_if_errors => upload_even_if_errors, :fmt => fmt).execute!
end