class SalesforceChunker::ManualChunkingBreakpointQuery

Public Class Methods

new(connection:, object:, operation:, query:, **options) click to toggle source
Calls superclass method SalesforceChunker::Job::new
# File lib/salesforce_chunker/manual_chunking_breakpoint_query.rb, line 4
def initialize(connection:, object:, operation:, query:, **options)
  @batch_size = options[:batch_size] || 100000
  super(connection: connection, object: object, operation: operation, **options)

  create_batch(query)
  @batches_count = 1

  close
end

Public Instance Methods

create_batch(payload) click to toggle source
# File lib/salesforce_chunker/manual_chunking_breakpoint_query.rb, line 37
def create_batch(payload)
  @log.info "Creating Id Batch: \"#{payload.gsub(/\n/, " ").strip}\""
  response = @connection.post("job/#{@job_id}/batch", payload.to_s, {"Content-Type": "text/csv"})
  response["batchInfo"]["id"]
end
create_job(object, options) click to toggle source
Calls superclass method SalesforceChunker::Job#create_job
# File lib/salesforce_chunker/manual_chunking_breakpoint_query.rb, line 58
def create_job(object, options)
  super(object, options.merge(content_type: "CSV"))
end
get_batch_results(batch_id) { |result| ... } click to toggle source
# File lib/salesforce_chunker/manual_chunking_breakpoint_query.rb, line 14
def get_batch_results(batch_id)
  retrieve_batch_results(batch_id).each_with_index do |result_id, result_index|
    results = retrieve_raw_results(batch_id, result_id)

    @log.info "Generating breakpoints from CSV results"
    process_csv_results(results, result_index > 0) { |result| yield result }
  end
end
get_batch_statuses() click to toggle source
# File lib/salesforce_chunker/manual_chunking_breakpoint_query.rb, line 53
def get_batch_statuses
  # XML to JSON wrangling
  [@connection.get_json("job/#{@job_id}/batch")["batchInfoList"]["batchInfo"]]
end
process_csv_results(input, include_first_element) { |peek.gsub("\"", "")| ... } click to toggle source
# File lib/salesforce_chunker/manual_chunking_breakpoint_query.rb, line 23
def process_csv_results(input, include_first_element)
  lines = input.each_line
  headers = lines.next

  yield(lines.peek.chomp.gsub("\"", "")) if include_first_element

  loop do
    @batch_size.times { lines.next }
    yield(lines.peek.chomp.gsub("\"", ""))
  end
rescue StopIteration
  nil
end
retrieve_batch_results(batch_id) click to toggle source
# File lib/salesforce_chunker/manual_chunking_breakpoint_query.rb, line 43
def retrieve_batch_results(batch_id)
  # XML to JSON wrangling
  response = super(batch_id)
  if response["result_list"]["result"].is_a? Array
    response["result_list"]["result"]
  else
    [response["result_list"]["result"]]
  end
end