Class: Restforce::Bulk::Job

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

Constant Summary collapse

JOB_CONTENT_TYPE_MAPPING =
{
  csv: 'CSV',
  xml: 'XML',
  zip_csv: 'ZIP_CSV',
  zip_xml: 'ZIP_XML'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes

#assign_attributes

Constructor Details

#initialize(attributes = {}) ⇒ Job

Returns a new instance of Job.



33
34
35
36
37
# File 'lib/restforce/bulk/job.rb', line 33

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

  @batches = []
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



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

def content_type
  @content_type
end

#created_by_idObject

Returns the value of attribute created_by_id.



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

def created_by_id
  @created_by_id
end

#created_dateObject

Returns the value of attribute created_date.



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

def created_date
  @created_date
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#objectObject

Returns the value of attribute object.



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

def object
  @object
end

#operationObject

Returns the value of attribute operation.



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

def operation
  @operation
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#system_modstampObject

Returns the value of attribute system_modstamp.



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

def system_modstamp
  @system_modstamp
end

Class Method Details

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



14
15
16
17
18
19
20
21
# File 'lib/restforce/bulk/job.rb', line 14

def create(operation, object_name, content_type=:xml)
  builder  = Restforce::Bulk::Builder::Xml.new(operation)
  data     = builder.job(object_name, JOB_CONTENT_TYPE_MAPPING[content_type.to_sym])

  response = Restforce::Bulk.client.perform_request(:post, 'job', data)

  new(response.body.jobInfo)
end

.find(id) ⇒ Object



23
24
25
26
27
# File 'lib/restforce/bulk/job.rb', line 23

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

  new(response.body.jobInfo)
end

Instance Method Details

#abortObject



70
71
72
73
74
75
76
# File 'lib/restforce/bulk/job.rb', line 70

def abort
  builder = Restforce::Bulk::Builder::Xml.new(operation)

  response = Restforce::Bulk.client.perform_request(:post, "job/#{id}", builder.abort)

  assign_attributes(response.body.jobInfo)
end

#add_batch(data) ⇒ Object



56
57
58
59
60
# File 'lib/restforce/bulk/job.rb', line 56

def add_batch(data)
  Restforce::Bulk::Batch.create(id, data, operation, content_type).tap do |batch|
    batches << batch
  end
end

#batchesObject



43
44
45
# File 'lib/restforce/bulk/job.rb', line 43

def batches
  @batches
end

#closeObject



62
63
64
65
66
67
68
# File 'lib/restforce/bulk/job.rb', line 62

def close
  builder = Restforce::Bulk::Builder::Xml.new(operation)

  response = Restforce::Bulk.client.perform_request(:post, "job/#{id}", builder.close)

  assign_attributes(response.body.jobInfo)
end

#reload_batchesObject



47
48
49
50
51
52
53
54
# File 'lib/restforce/bulk/job.rb', line 47

def reload_batches
  response = Restforce::Bulk.client.perform_request(:get, "job/#{id}/batch")
  parser   = Restforce::Bulk::Parser::Xml.new

  @batches = parser.batches(response.body).map do |batch_info|
    Restforce::Bulk::Batch.new(batch_info)
  end
end