Class: Restforce::Bulk::Batch

Inherits:
Object
  • Object
show all
Includes:
Attributes
Defined in:
lib/restforce/bulk/batch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes

#assign_attributes

Constructor Details

#initialize(attributes = {}) ⇒ Batch

Returns a new instance of Batch.



26
27
28
# File 'lib/restforce/bulk/batch.rb', line 26

def initialize(attributes={})
  assign_attributes(attributes)
end

Instance Attribute Details

#created_dateObject

Returns the value of attribute created_date.



24
25
26
# File 'lib/restforce/bulk/batch.rb', line 24

def created_date
  @created_date
end

#idObject

Returns the value of attribute id.



24
25
26
# File 'lib/restforce/bulk/batch.rb', line 24

def id
  @id
end

#job_idObject

Returns the value of attribute job_id.



24
25
26
# File 'lib/restforce/bulk/batch.rb', line 24

def job_id
  @job_id
end

#number_records_processedObject

Returns the value of attribute number_records_processed.



24
25
26
# File 'lib/restforce/bulk/batch.rb', line 24

def number_records_processed
  @number_records_processed
end

#stateObject

Returns the value of attribute state.



24
25
26
# File 'lib/restforce/bulk/batch.rb', line 24

def state
  @state
end

#system_modstampObject

Returns the value of attribute system_modstamp.



24
25
26
# File 'lib/restforce/bulk/batch.rb', line 24

def system_modstamp
  @system_modstamp
end

Class Method Details

.builder_class_for(content_type) ⇒ Object



19
20
21
# File 'lib/restforce/bulk/batch.rb', line 19

def builder_class_for(content_type)
  Restforce::Bulk::Builder.const_get(content_type.to_s.camelize)
end

.create(job_id, data, operation, content_type = :xml) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/restforce/bulk/batch.rb', line 7

def create(job_id, data, operation, content_type=:xml)
  builder  = builder_class_for(content_type).new(operation)

  response = Restforce::Bulk.client.perform_request(:post, "job/#{job_id}/batch", builder.transform(data, operation, content_type), content_type)

  new(response.body.batchInfo)
end

.find(job_id, id) ⇒ Object



15
16
17
# File 'lib/restforce/bulk/batch.rb', line 15

def find(job_id, id)
  new(job_id: job_id, id: id).tap(&:refresh)
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/restforce/bulk/batch.rb', line 38

def completed?
  state == 'Completed'
end

#failed?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/restforce/bulk/batch.rb', line 42

def failed?
  state == 'Failed'
end

#in_progress?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/restforce/bulk/batch.rb', line 34

def in_progress?
  state == 'InProgress'
end

#not_processed?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/restforce/bulk/batch.rb', line 46

def not_processed?
  state == 'Not Processed'
end

#queued?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/restforce/bulk/batch.rb', line 30

def queued?
  state == 'Queued'
end

#refreshObject



50
51
52
53
54
# File 'lib/restforce/bulk/batch.rb', line 50

def refresh
  response = Restforce::Bulk.client.perform_request(:get, "job/#{job_id}/batch/#{id}")

  assign_attributes(response.body.batchInfo)
end

#resultsObject



56
57
58
59
60
61
62
63
# File 'lib/restforce/bulk/batch.rb', line 56

def results
  response = Restforce::Bulk.client.perform_request(:get, "job/#{job_id}/batch/#{id}/result")
  parser   = results_parser_for(response.body).new

  parser.results_on(response.body).map do |result|
    Restforce::Bulk::Result.new({job_id: job_id, batch_id: id}.merge(result))
  end
end