salesforce_bulk2 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module SalesforceBulk
2
2
  class Batch
3
- attr_accessor :connection
3
+ attr_accessor :session_id
4
4
 
5
5
  attr_reader :apex_processing_time
6
6
  attr_reader :api_active_processing_time
@@ -14,18 +14,29 @@ module SalesforceBulk
14
14
  attr_reader :total_processing_time
15
15
  attr_reader :data
16
16
 
17
- @@max_records = 10000
17
+ @@batch_size = 10000
18
18
 
19
- def self.max_records
20
- @@max_records
19
+ def self.batch_size
20
+ @@batch_size
21
21
  end
22
-
23
- #This is not the way this is going to run
24
- def initialize(data, job_id, client = nil)
25
- update(data)
26
- @client = client
22
+
23
+ def self.new_from_xml xml_data, session_id = nil
24
+ batch = Batch.new
25
+ batch.update(data)
26
+ batch.session_id = session_id
27
+ batch
28
+ end
29
+
30
+ def self.find job_id, batch_id, session_id
31
+ batch = Batch.new
32
+ batch.id = batch_id
33
+ batch.job_id = job_id
34
+ batch.session_id = session_id
35
+ batch.refresh
36
+ batch
27
37
  end
28
38
 
39
+
29
40
  def update(data)
30
41
  @data = data
31
42
 
@@ -41,6 +52,10 @@ module SalesforceBulk
41
52
  @apex_processing_time = data['apex_processing_time'].to_i
42
53
  end
43
54
 
55
+ def job
56
+ @job ||= Job.find(@job_id, @session_id) if @session_id
57
+ end
58
+
44
59
  ### State Information ###
45
60
  def in_progress?
46
61
  state? 'InProgress'
@@ -79,7 +94,7 @@ module SalesforceBulk
79
94
  end
80
95
 
81
96
  def refresh
82
- xml_data = http_get_xml("job/#{jobId}/batch/#{batchId}")
97
+ xml_data = @connection.http_get_xml("job/#{jobId}/batch/#{batchId}")
83
98
  update(xml_data)
84
99
  end
85
100
  end
@@ -16,12 +16,12 @@ module SalesforceBulk
16
16
  @connection.disconnect
17
17
  end
18
18
 
19
- def connect
20
- @connection.connect
19
+ def connect options = {}
20
+ @connection.connect(options)
21
21
  end
22
22
 
23
- def create_job operation, sobject, options = {}
24
- Job.new add_job(operation, sobject, options), self
23
+ def new_job operation, sobject, options = {}
24
+ Job.new(add_job(operation, sobject, options), self)
25
25
  end
26
26
 
27
27
  def add_job operation, sobject, options={}
@@ -39,7 +39,7 @@ module SalesforceBulk
39
39
  xml = '<?xml version="1.0" encoding="utf-8"?>'
40
40
  xml += '<jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">'
41
41
  xml += " <operation>#{operation}</operation>"
42
- xml += " <object>#{sobject}</object>"
42
+ xml += " <object>#{sobject}</object>" if sobject
43
43
  xml += " <externalIdFieldName>#{options[:external_id_field_name]}</externalIdFieldName>" if options[:external_id_field_name]
44
44
  xml += " <concurrencyMode>#{options[:concurrency_mode]}</concurrencyMode>" if options[:concurrency_mode]
45
45
  xml += " <contentType>CSV</contentType>"
@@ -66,11 +66,11 @@ module SalesforceBulk
66
66
  @connection.http_post_xml("job/#{job_id}", xml)
67
67
  end
68
68
 
69
- def get_job job_id
69
+ def get_job_info job_id
70
70
  @connection.http_get_xml("job/#{job_id}")
71
71
  end
72
72
 
73
- def get_batch job_id, batch_id
73
+ def get_batch_info job_id, batch_id
74
74
  @connection.http_get_xml("job/#{jobId}/batch/#{batchId}")
75
75
  end
76
76
 
@@ -190,9 +190,9 @@ module SalesforceBulk
190
190
  end
191
191
 
192
192
  def perform_operation(operation, sobject, data, external_id = nil, batch_size = nil)
193
- job = create_job(operation, sobject, :external_id_field_name => external_id)
193
+ job = new_job(operation, sobject, :external_id_field_name => external_id)
194
194
 
195
- data.each_slice(batch_size || Batch.max_records) do |records|
195
+ data.each_slice(batch_size || Batch.batch_size) do |records|
196
196
  job.add_batch(records)
197
197
  end
198
198
 
@@ -44,7 +44,13 @@ module SalesforceBulk
44
44
  @debugging = options[:debugging] || @@debugging
45
45
  end
46
46
 
47
- def connect
47
+ def connect options = {}
48
+ raise Error.new("Already connected") if connected?
49
+
50
+ @username = options[:username] || @username
51
+ @password = options[:password] || @password
52
+ @version = options[:version] || @version
53
+
48
54
  xml = '<?xml version="1.0" encoding="utf-8"?>'
49
55
  xml += '<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
50
56
  xml += ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
@@ -7,10 +7,11 @@ module SalesforceBulk
7
7
  attr_reader :data
8
8
 
9
9
  @@fields = [:id, :operation, :object, :createdById, :state, :createdDate,
10
- :systemModstamp, :externalIdFieldName, :concurrencyMode, :contentType, :numberBatchesQueued,
11
- :numberBatchesInProgress, :numberBatchesCompleted, :numberBatchesFailed, :totalBatches,
12
- :retries, :numberRecordsProcessed, :numberRecordsFailed, :totalProcessingTime,
13
- :apiActiveProcessingTime, :apexProcessingTime, :apiVersion]
10
+ :systemModstamp, :externalIdFieldName, :concurrencyMode, :contentType,
11
+ :numberBatchesQueued, :numberBatchesInProgress, :numberBatchesCompleted,
12
+ :numberBatchesFailed, :totalBatches, :retries, :numberRecordsProcessed,
13
+ :numberRecordsFailed, :totalProcessingTime, :apiActiveProcessingTime,
14
+ :apexProcessingTime, :apiVersion]
14
15
 
15
16
  @@valid_operations = [:delete, :insert, :update, :upsert, :query]
16
17
  @@valid_concurrency_modes = ['Parallel', 'Serial']
@@ -28,9 +29,10 @@ module SalesforceBulk
28
29
  @@valid_concurrency_modes.include?(concurrency_mode)
29
30
  end
30
31
 
31
- def initialize xml_data, client
32
- update(xml_data)
33
- @client = client
32
+ def new_from_xml xml_data, client = nil
33
+ job = Job.new
34
+ job.update(xml_data)
35
+ job.client = client
34
36
  end
35
37
 
36
38
  def update xml_data
@@ -45,7 +47,7 @@ module SalesforceBulk
45
47
  instance_variable_set(field, xml_data[field])
46
48
  end
47
49
 
48
- #Special cases/formats
50
+ #Special cases and data formats
49
51
  @created_date = DateTime.parse(xml_data['createdDate'])
50
52
  @system_modstamp = DateTime.parse(xml_data['systemModstamp'])
51
53
 
@@ -76,26 +78,26 @@ module SalesforceBulk
76
78
  end
77
79
 
78
80
  def close
79
- update(@client.close(@id))
81
+ update(@client.close_job(@id))
80
82
  end
81
83
 
82
84
  def abort
83
- update(@client.abort(@id))
85
+ update(@client.abort_job(@id))
84
86
  end
85
87
 
86
88
  def refresh
87
- update(@client.get_job(@id))
88
- end
89
-
90
- #Statuses
91
- def batches_finished?
92
- @number_batches_queued == 0 and
93
- @number_batches_in_progress == 0
89
+ update(@client.get_job_info(@id))
94
90
  end
95
91
 
96
92
  def get_results
97
93
  batch_list.map(&:result).flatten
98
94
  end
95
+
96
+ #Statuses
97
+ def batches_finished?
98
+ (@number_batches_queued == 0) and
99
+ (@number_batches_in_progress == 0)
100
+ end
99
101
 
100
102
  def finished?
101
103
  failed? or
@@ -1,3 +1,3 @@
1
1
  module SalesforceBulk
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -14,4 +14,7 @@ require 'salesforce_bulk/job'
14
14
  require 'salesforce_bulk/batch'
15
15
  require 'salesforce_bulk/batch_result'
16
16
  require 'salesforce_bulk/batch_result_collection'
17
- require 'salesforce_bulk/query_result_collection'
17
+ require 'salesforce_bulk/query_result_collection'
18
+
19
+ module SalesforceBulk
20
+ end
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = "salesforce_bulk2"
7
7
  s.version = SalesforceBulk::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Adam Kerr", "Jorge Valdivia","Javier Julio"]
10
- s.email = ["ajrkerr@gmail.com", "jorge@valdivia.me","jjfutbol@gmail.com"]
9
+ s.authors = ["Adam Kerr", "Jorge Valdivia", "Javier Julio"]
10
+ s.email = ["ajrkerr@gmail.com", "jorge@valdivia.me", "jjfutbol@gmail.com"]
11
11
  s.homepage = "https://github.com/ajrkerr/salesforce_bulk"
12
12
  s.summary = %q{Ruby support for the Salesforce Bulk API}
13
13
  s.description = %q{This gem is a simple interface to the Salesforce Bulk API providing support for insert, update, upsert, delete, and query.}
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency "active_support"
20
+ s.add_dependency "activesupport"
21
21
  s.add_dependency "xml-simple"
22
22
 
23
23
  s.add_development_dependency "mocha"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_bulk2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,10 +11,10 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-07-31 00:00:00.000000000 Z
14
+ date: 2012-08-01 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: active_support
17
+ name: activesupport
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
@@ -134,7 +134,7 @@ files:
134
134
  - lib/salesforce_bulk/query_result_collection.rb
135
135
  - lib/salesforce_bulk/salesforce_error.rb
136
136
  - lib/salesforce_bulk/version.rb
137
- - salesforce_bulk.gemspec
137
+ - salesforce_bulk2.gemspec
138
138
  - test/fixtures/batch_create_request.csv
139
139
  - test/fixtures/batch_create_response.xml
140
140
  - test/fixtures/batch_info_list_response.xml