salesforcebulk 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/salesforce_bulk/batch.rb +9 -7
- data/lib/salesforce_bulk/version.rb +1 -1
- data/test/fixtures/batch_info_response.xml +1 -0
- data/test/lib/test_batch.rb +56 -55
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6f6595658ab7d407acd1f74cb96b8b40ae9a303
|
4
|
+
data.tar.gz: d9750c85f6cad1d42a6c81f108d6de8fb1558748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abe409976e507aa19ff46d3519088e84656f039aa1521def05daa495f114fe4c04bf4835f47baabcc69bf12da52ee3198cd1a950a0fd30eb472bea336acf2dab
|
7
|
+
data.tar.gz: 87ec0fa2cd572bdf23f624099bfa6ea43c512835672bff6e2aead8be09f4d05a7dce574fcbfaa9cc2285d99c18aaa2a39ff8469eb2726be02aad74636607993e
|
data/README.md
CHANGED
@@ -153,6 +153,10 @@ Note: By reviewing the API docs and response format my understanding was that th
|
|
153
153
|
|
154
154
|
## Version History
|
155
155
|
|
156
|
+
**1.4.0** (June 1, 2014)
|
157
|
+
|
158
|
+
* Added state_message to Batch class (#11 - thanks [@bethesque](https://github.com/bethesque))
|
159
|
+
|
156
160
|
**1.3.0** (April 28, 2014)
|
157
161
|
|
158
162
|
* Added support for multiple subdomains (#10 - thanks [@lucianapazos](https://github.com/lucianapazos))
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SalesforceBulk
|
2
2
|
class Batch
|
3
|
-
|
3
|
+
|
4
4
|
attr_accessor :apex_processing_time
|
5
5
|
attr_accessor :api_active_processing_time
|
6
6
|
attr_accessor :completed_at
|
@@ -10,13 +10,15 @@ module SalesforceBulk
|
|
10
10
|
attr_accessor :job_id
|
11
11
|
attr_accessor :processed_records
|
12
12
|
attr_accessor :state
|
13
|
+
attr_accessor :state_message
|
13
14
|
attr_accessor :total_processing_time
|
14
|
-
|
15
|
+
|
15
16
|
def self.new_from_xml(data)
|
16
17
|
batch = self.new
|
17
18
|
batch.id = data['id']
|
18
19
|
batch.job_id = data['jobId']
|
19
20
|
batch.state = data['state']
|
21
|
+
batch.state_message = data['stateMessage']
|
20
22
|
batch.created_at = DateTime.parse(data['createdDate'])
|
21
23
|
batch.completed_at = DateTime.parse(data['systemModstamp'])
|
22
24
|
batch.processed_records = data['numberRecordsProcessed'].to_i
|
@@ -26,23 +28,23 @@ module SalesforceBulk
|
|
26
28
|
batch.apex_processing_time = data['apex_processing_time'].to_i
|
27
29
|
batch
|
28
30
|
end
|
29
|
-
|
31
|
+
|
30
32
|
def in_progress?
|
31
33
|
state? 'InProgress'
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
def queued?
|
35
37
|
state? 'Queued'
|
36
38
|
end
|
37
|
-
|
39
|
+
|
38
40
|
def completed?
|
39
41
|
state? 'Completed'
|
40
42
|
end
|
41
|
-
|
43
|
+
|
42
44
|
def failed?
|
43
45
|
state? 'Failed'
|
44
46
|
end
|
45
|
-
|
47
|
+
|
46
48
|
def state?(value)
|
47
49
|
self.state.present? && self.state.casecmp(value) == 0
|
48
50
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
<id>751E00000004ZRbIAM</id>
|
4
4
|
<jobId>750E00000004N97IAE</jobId>
|
5
5
|
<state>Completed</state>
|
6
|
+
<stateMessage>Success</stateMessage>
|
6
7
|
<createdDate>2012-05-31T01:22:47.000Z</createdDate>
|
7
8
|
<systemModstamp>2012-05-31T01:22:47.000Z</systemModstamp>
|
8
9
|
<numberRecordsProcessed>2</numberRecordsProcessed>
|
data/test/lib/test_batch.rb
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class TestBatch < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
def setup
|
6
6
|
options = {
|
7
|
-
:username => 'myusername',
|
7
|
+
:username => 'myusername',
|
8
8
|
:password => 'mypassword'
|
9
9
|
}
|
10
|
-
|
10
|
+
|
11
11
|
@client = SalesforceBulk::Client.new(options)
|
12
12
|
bypass_authentication(@client)
|
13
13
|
@batch = SalesforceBulk::Batch.new
|
14
14
|
@headers = {"Content-Type" => "text/csv; charset=UTF-8", 'X-Sfdc-Session' => '123456789'}
|
15
15
|
@headersWithXml = {'Content-Type' => 'application/xml', 'X-Sfdc-Session' => '123456789'}
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
test "initialize from XML" do
|
19
19
|
xml = fixture("batch_info_response.xml")
|
20
20
|
batch = SalesforceBulk::Batch.new_from_xml(XmlSimple.xml_in(xml, 'ForceArray' => false))
|
21
|
-
|
21
|
+
|
22
22
|
assert_equal batch.id, '751E00000004ZRbIAM'
|
23
23
|
assert_equal batch.job_id, '750E00000004N97IAE'
|
24
24
|
assert_equal batch.state, 'Completed'
|
25
|
+
assert_equal batch.state_message, 'Success'
|
25
26
|
assert_equal batch.created_at, DateTime.parse('2012-05-31T01:22:47.000Z')
|
26
27
|
assert_equal batch.completed_at, DateTime.parse('2012-05-31T01:22:47.000Z')
|
27
28
|
assert_equal batch.processed_records, 2
|
@@ -30,50 +31,50 @@ class TestBatch < Test::Unit::TestCase
|
|
30
31
|
assert_equal batch.api_active_processing_time, 28
|
31
32
|
assert_equal batch.apex_processing_time, 0
|
32
33
|
end
|
33
|
-
|
34
|
+
|
34
35
|
test "state?" do
|
35
36
|
@batch.state = "Completed"
|
36
37
|
assert @batch.state?('Completed')
|
37
|
-
|
38
|
+
|
38
39
|
@batch.state = "COMPLETED"
|
39
40
|
assert @batch.state?('completed')
|
40
|
-
|
41
|
+
|
41
42
|
@batch.state = "Failed"
|
42
43
|
assert !@batch.state?('Queued')
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
test "state is marked queued" do
|
46
47
|
@batch.state = "Queued"
|
47
48
|
assert @batch.queued?
|
48
|
-
|
49
|
+
|
49
50
|
@batch.state = nil
|
50
51
|
assert !@batch.queued?
|
51
52
|
end
|
52
|
-
|
53
|
+
|
53
54
|
test "state is marked in progress" do
|
54
55
|
@batch.state = "InProgress"
|
55
56
|
assert @batch.in_progress?
|
56
|
-
|
57
|
+
|
57
58
|
@batch.state = nil
|
58
59
|
assert !@batch.in_progress?
|
59
60
|
end
|
60
|
-
|
61
|
+
|
61
62
|
test "state is marked completed" do
|
62
63
|
@batch.state = "Completed"
|
63
64
|
assert @batch.completed?
|
64
|
-
|
65
|
+
|
65
66
|
@batch.state = nil
|
66
67
|
assert !@batch.completed?
|
67
68
|
end
|
68
|
-
|
69
|
+
|
69
70
|
test "state is marked failed" do
|
70
71
|
@batch.state = "Failed"
|
71
72
|
assert @batch.failed?
|
72
|
-
|
73
|
+
|
73
74
|
@batch.state = nil
|
74
75
|
assert !@batch.failed?
|
75
76
|
end
|
76
|
-
|
77
|
+
|
77
78
|
test "should add a batch to a job and return a successful response" do
|
78
79
|
request = fixture("batch_create_request.csv")
|
79
80
|
response = fixture("batch_create_response.xml")
|
@@ -87,13 +88,13 @@ class TestBatch < Test::Unit::TestCase
|
|
87
88
|
if RUBY_VERSION < '1.9'
|
88
89
|
data.first.stubs(:keys).returns([:Id__c, :Title__c, :IsPreview__c])
|
89
90
|
end
|
90
|
-
|
91
|
+
|
91
92
|
stub_request(:post, "#{api_url(@client)}job/#{job_id}/batch").with(:body => request, :headers => @headers).to_return(:body => response, :status => 200)
|
92
|
-
|
93
|
+
|
93
94
|
batch = @client.add_batch(job_id, data)
|
94
|
-
|
95
|
+
|
95
96
|
assert_requested :post, "#{api_url(@client)}job/#{job_id}/batch", :body => request, :headers => @headers, :times => 1
|
96
|
-
|
97
|
+
|
97
98
|
assert_equal batch.id, batch_id
|
98
99
|
assert_equal batch.job_id, job_id
|
99
100
|
assert_equal batch.state, 'Queued'
|
@@ -105,29 +106,29 @@ class TestBatch < Test::Unit::TestCase
|
|
105
106
|
assert_equal batch.api_active_processing_time, 0
|
106
107
|
assert_equal batch.apex_processing_time, 0
|
107
108
|
end
|
108
|
-
|
109
|
+
|
109
110
|
test "should raise ArgumentError when given data array length exceeding 10000" do
|
110
111
|
data = (1..10100).map { |index| {:Id => index} }
|
111
|
-
|
112
|
+
|
112
113
|
assert_raise ArgumentError do
|
113
114
|
@client.add_batch("750E00000004NRfIAM", data)
|
114
115
|
end
|
115
116
|
end
|
116
|
-
|
117
|
+
|
117
118
|
test "should retrieve info for all batches in a job in a single request" do
|
118
119
|
response = fixture("batch_info_list_response.xml")
|
119
120
|
job_id = "750E00000004N97IAE"
|
120
|
-
|
121
|
+
|
121
122
|
stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch").with(:headers => @headersWithXml).to_return(:body => response, :status => 200)
|
122
|
-
|
123
|
+
|
123
124
|
batches = @client.batch_info_list(job_id)
|
124
|
-
|
125
|
+
|
125
126
|
assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch", :headers => @headersWithXml, :times => 1
|
126
|
-
|
127
|
+
|
127
128
|
assert_kind_of Array, batches
|
128
129
|
assert_kind_of SalesforceBulk::Batch, batches.first
|
129
130
|
assert_equal batches.length, 2
|
130
|
-
|
131
|
+
|
131
132
|
batch = batches.first
|
132
133
|
assert_equal batch.id, "751E00000004ZRbIAM"
|
133
134
|
assert_equal batch.job_id, job_id
|
@@ -139,7 +140,7 @@ class TestBatch < Test::Unit::TestCase
|
|
139
140
|
assert_equal batch.total_processing_time, 72
|
140
141
|
assert_equal batch.api_active_processing_time, 28
|
141
142
|
assert_equal batch.apex_processing_time, 0
|
142
|
-
|
143
|
+
|
143
144
|
batch = batches.last
|
144
145
|
assert_equal batch.id, "751E00000004ZQsIAM"
|
145
146
|
assert_equal batch.job_id, job_id
|
@@ -152,18 +153,18 @@ class TestBatch < Test::Unit::TestCase
|
|
152
153
|
assert_equal batch.api_active_processing_time, 28
|
153
154
|
assert_equal batch.apex_processing_time, 0
|
154
155
|
end
|
155
|
-
|
156
|
+
|
156
157
|
test "should retrieve batch info" do
|
157
158
|
response = fixture("batch_info_response.xml")
|
158
159
|
job_id = "750E00000004N97IAE"
|
159
160
|
batch_id = "751E00000004ZRbIAM"
|
160
|
-
|
161
|
+
|
161
162
|
stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}").with(:headers => @headersWithXml).to_return(:body => response, :status => 200)
|
162
|
-
|
163
|
+
|
163
164
|
batch = @client.batch_info(job_id, batch_id)
|
164
|
-
|
165
|
+
|
165
166
|
assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}", :headers => @headersWithXml, :times => 1
|
166
|
-
|
167
|
+
|
167
168
|
assert_equal batch.id, batch_id
|
168
169
|
assert_equal batch.job_id, job_id
|
169
170
|
assert_equal batch.state, 'Completed'
|
@@ -175,22 +176,22 @@ class TestBatch < Test::Unit::TestCase
|
|
175
176
|
assert_equal batch.api_active_processing_time, 28
|
176
177
|
assert_equal batch.apex_processing_time, 0
|
177
178
|
end
|
178
|
-
|
179
|
+
|
179
180
|
test "should return batch result for a non-querying job" do
|
180
181
|
response = fixture("batch_result_list_response.csv")
|
181
182
|
job_id = "750E00000004NRa"
|
182
183
|
batch_id = "751E00000004ZmK"
|
183
|
-
|
184
|
-
# Batches that are created using CSV will always return
|
184
|
+
|
185
|
+
# Batches that are created using CSV will always return
|
185
186
|
# results in CSV format despite requesting with XML content type.
|
186
187
|
# Thus the content type header is ignored.
|
187
|
-
|
188
|
+
|
188
189
|
stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result").to_return(:body => response, :status => 200)
|
189
|
-
|
190
|
+
|
190
191
|
results = @client.batch_result(job_id, batch_id)
|
191
|
-
|
192
|
+
|
192
193
|
assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result", :times => 1
|
193
|
-
|
194
|
+
|
194
195
|
assert_kind_of SalesforceBulk::BatchResultCollection, results
|
195
196
|
assert_kind_of Array, results
|
196
197
|
assert_equal results.length, 2
|
@@ -201,51 +202,51 @@ class TestBatch < Test::Unit::TestCase
|
|
201
202
|
assert_equal results.first.error?, false
|
202
203
|
assert_equal results.first.error, ''
|
203
204
|
end
|
204
|
-
|
205
|
+
|
205
206
|
test "retrieve result id for a query operation" do
|
206
207
|
response = fixture("query_result_list_response.xml")
|
207
208
|
job_id = "750E00000004NnR"
|
208
209
|
batch_id = "751E00000004aEY"
|
209
210
|
result_id = "752E0000000TNaq"
|
210
|
-
|
211
|
+
|
211
212
|
stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result").with(:headers => @headersWithXml).to_return(:body => response, :status => 200)
|
212
|
-
|
213
|
+
|
213
214
|
@client.expects(:query_result).with(job_id, batch_id, result_id).returns([])
|
214
|
-
|
215
|
+
|
215
216
|
result = @client.batch_result(job_id, batch_id)
|
216
|
-
|
217
|
+
|
217
218
|
assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result", :headers => @headersWithXml, :times => 1
|
218
219
|
assert_kind_of SalesforceBulk::QueryResultCollection, result
|
219
220
|
assert_equal result.job_id, job_id
|
220
221
|
assert_equal result.batch_id, batch_id
|
221
222
|
assert_equal result.result_id, result_id
|
222
223
|
end
|
223
|
-
|
224
|
+
|
224
225
|
test "retrieve and parse a query result successfully" do
|
225
226
|
response = fixture("query_result_response.csv")
|
226
227
|
job_id = "750E00000004NnR"
|
227
228
|
batch_id = "751E00000004aEY"
|
228
229
|
result_id = "752E0000000TNaq"
|
229
|
-
|
230
|
+
|
230
231
|
stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result/#{result_id}").with(:headers => @headers).to_return(:body => response, :status => 200)
|
231
|
-
|
232
|
+
|
232
233
|
result = @client.query_result(job_id, batch_id, result_id)
|
233
|
-
|
234
|
+
|
234
235
|
assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result/#{result_id}", :headers => @headers, :times => 1
|
235
236
|
assert_kind_of Array, result
|
236
237
|
assert result.length == 4
|
237
238
|
end
|
238
|
-
|
239
|
+
|
239
240
|
test "should raise SalesforceError on invalid batch response" do
|
240
241
|
response = fixture("invalid_batch_error.xml")
|
241
242
|
job_id = "750E00000004NnR"
|
242
243
|
batch_id = "751E00000004aEY"
|
243
|
-
|
244
|
+
|
244
245
|
stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result").with(:headers => @headersWithXml).to_return(:body => response, :status => 400)
|
245
|
-
|
246
|
+
|
246
247
|
assert_raise SalesforceBulk::SalesforceError do
|
247
248
|
@client.batch_result(job_id, batch_id)
|
248
249
|
end
|
249
250
|
end
|
250
|
-
|
251
|
+
|
251
252
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesforcebulk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Julio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|