Class: Salesforce::Bulk::Batch
- Inherits:
-
Object
- Object
- Salesforce::Bulk::Batch
- Includes:
- Blockenspiel::DSL, Attributes
- Defined in:
- lib/salesforce/bulk/batch.rb
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#csv ⇒ Object
Returns the value of attribute csv.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#id ⇒ Object
Returns the value of attribute id.
-
#job ⇒ Object
Returns the value of attribute job.
-
#number_records_failed ⇒ Object
Returns the value of attribute number_records_failed.
-
#number_records_processed ⇒ Object
Returns the value of attribute number_records_processed.
-
#state ⇒ Object
Returns the value of attribute state.
-
#state_message ⇒ Object
Returns the value of attribute state_message.
-
#total_time_processed ⇒ Object
Returns the value of attribute total_time_processed.
Instance Method Summary collapse
- #create! ⇒ Object
-
#initialize(job) ⇒ Batch
constructor
A new instance of Batch.
- #ordered_values(record) ⇒ Object
- #record(record) ⇒ Object
- #results ⇒ Object
- #temporary_csv_file ⇒ Object
- #update_status ⇒ Object
Methods included from Attributes
Constructor Details
Instance Attribute Details
#csv ⇒ Object
Returns the value of attribute csv.
11 12 13 |
# File 'lib/salesforce/bulk/batch.rb', line 11 def csv @csv end |
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/salesforce/bulk/batch.rb', line 11 def filename @filename end |
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/salesforce/bulk/batch.rb', line 11 def id @id end |
#job ⇒ Object
Returns the value of attribute job.
11 12 13 |
# File 'lib/salesforce/bulk/batch.rb', line 11 def job @job end |
#number_records_failed ⇒ Object
Returns the value of attribute number_records_failed.
11 12 13 |
# File 'lib/salesforce/bulk/batch.rb', line 11 def number_records_failed @number_records_failed end |
#number_records_processed ⇒ Object
Returns the value of attribute number_records_processed.
11 12 13 |
# File 'lib/salesforce/bulk/batch.rb', line 11 def number_records_processed @number_records_processed end |
#state ⇒ Object
Returns the value of attribute state.
11 12 13 |
# File 'lib/salesforce/bulk/batch.rb', line 11 def state @state end |
#state_message ⇒ Object
Returns the value of attribute state_message.
11 12 13 |
# File 'lib/salesforce/bulk/batch.rb', line 11 def @state_message end |
#total_time_processed ⇒ Object
Returns the value of attribute total_time_processed.
11 12 13 |
# File 'lib/salesforce/bulk/batch.rb', line 11 def total_time_processed @total_time_processed end |
Instance Method Details
#create! ⇒ Object
37 38 39 40 41 |
# File 'lib/salesforce/bulk/batch.rb', line 37 def create! self.csv.close response = ::Salesforce.connection.async_post("job/#{job.id}/batch", File.read(self.filename), :format => :xml, :content_type => 'text/csv') assign_attributes!(response) end |
#ordered_values(record) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/salesforce/bulk/batch.rb', line 30 def ordered_values(record) job.csv_columns.map do |col| raw_value = record[col.name.to_sym] Column.to_csv_value Column.typecast(col.type, raw_value) end end |
#record(record) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/salesforce/bulk/batch.rb', line 22 def record(record) if record.is_a?(Hash) self.csv << ordered_values(record) else self.csv << ordered_values(record.attributes) end end |
#results ⇒ Object
49 50 51 |
# File 'lib/salesforce/bulk/batch.rb', line 49 def results parse_csv_results ::Salesforce.connection.async_get("job/#{job.id}/batch/#{id}/result") end |
#temporary_csv_file ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/salesforce/bulk/batch.rb', line 59 def temporary_csv_file if Object.const_defined?(:Rails) && Rails.respond_to?(:root) && Rails.root.present? Rails.root.join('tmp', 'files', "#{ Time.now.to_i}#{rand(10000)}.csv") else File.join("/tmp/#{ Time.now.to_i}#{rand(10000)}.csv") end end |
#update_status ⇒ Object
43 44 45 46 47 |
# File 'lib/salesforce/bulk/batch.rb', line 43 def update_status return state if completed? response = ::Salesforce.connection.async_get("job/#{job.id}/batch/#{id}", :format => :xml) self.state = response[:state] end |