salesforcebulk 2.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +81 -124
- data/lib/salesforce_bulk.rb +1 -5
- data/lib/salesforce_bulk/batch.rb +1 -1
- data/lib/salesforce_bulk/batch_result.rb +11 -11
- data/lib/salesforce_bulk/client.rb +37 -13
- data/lib/salesforce_bulk/job.rb +8 -8
- data/lib/salesforce_bulk/query_result_collection.rb +11 -11
- data/lib/salesforce_bulk/version.rb +1 -1
- metadata +7 -71
- data/lib/salesforce_bulk/core_extensions/string.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f032203ffa9c8c7b62236b41582b120f71ea8db3d61c47225d9e50c8c0cd5df6
|
4
|
+
data.tar.gz: f2af5753284c05df4280f2b170b03cce923c2a229e9c86eb6c2573843d2a3fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7a8a9ea7f98d8dba1f482482b6dd693f76978a01069b206d6bda1c1e6a681e59384b4ed8a493586520fb45941689b2479051f0af55df0e3104b2796f3427a0f
|
7
|
+
data.tar.gz: f1f7a957d188f22704c8ae6d756435faa70344b4c65ae76ea27223202f6e2159078b58c866c073ec3b48dce14323616710a4b5833ac25007f329f3e7f720fd96
|
data/README.md
CHANGED
@@ -1,33 +1,34 @@
|
|
1
1
|
# SalesforceBulk
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/salesforcebulk.svg)](https://badge.fury.io/rb/salesforcebulk)
|
4
|
+
[![Tests](https://github.com/javierjulio/salesforce_bulk/actions/workflows/ci.yml/badge.svg)](https://github.com/javierjulio/salesforce_bulk/actions/workflows/ci.yml)
|
5
|
+
|
3
6
|
## Overview
|
4
7
|
|
5
|
-
SalesforceBulk is an easy to use Ruby gem for connecting to and using the [Salesforce Bulk API](http://www.salesforce.com/us/developer/docs/api_asynch/index.htm). This is a rewrite and separate release of Jorge Valdivia's salesforce_bulk gem (renamed `salesforcebulk`) with full unit tests and full API capability (e.g. adding multiple batches per job).
|
8
|
+
SalesforceBulk is an easy to use Ruby gem for connecting to and using the [Salesforce Bulk API](http://www.salesforce.com/us/developer/docs/api_asynch/index.htm). This is a rewrite and separate release of Jorge Valdivia's salesforce_bulk gem (renamed `salesforcebulk`) with full unit tests and full API capability (e.g. adding multiple batches per job).
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
9
12
|
Install SalesforceBulk from RubyGems:
|
10
13
|
|
11
|
-
|
14
|
+
```
|
15
|
+
gem install salesforcebulk
|
16
|
+
```
|
12
17
|
|
13
18
|
Or include it in your project's `Gemfile` with Bundler:
|
14
19
|
|
15
|
-
|
20
|
+
```ruby
|
21
|
+
gem 'salesforcebulk'
|
22
|
+
```
|
16
23
|
|
17
24
|
## Contribute
|
18
25
|
|
19
|
-
To contribute, fork this repo, create a topic branch,
|
20
|
-
|
21
|
-
bundle install
|
22
|
-
rake
|
23
|
-
|
24
|
-
To run the test suite on all gemfiles with your current ruby version, use:
|
25
|
-
|
26
|
-
bundle exec rake wwtd:local
|
26
|
+
To contribute, fork this repo, create a topic branch, add changes and tests, then send a pull request. To setup the project and run tests in your fork, just do:
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
```
|
29
|
+
bundle install
|
30
|
+
bundle exec rake
|
31
|
+
```
|
31
32
|
|
32
33
|
## Configuration and Initialization
|
33
34
|
|
@@ -35,87 +36,84 @@ To run the full test suite with different gemfiles and ruby versions, use:
|
|
35
36
|
|
36
37
|
When retrieving a password you will also be given a security token. Combine the two into a single value as the API treats this as your real password.
|
37
38
|
|
38
|
-
|
39
|
+
```ruby
|
40
|
+
require 'salesforce_bulk'
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
client = SalesforceBulk::Client.new(username: 'MyUsername', password: 'MyPasswordWithSecurtyToken')
|
43
|
+
client.authenticate
|
44
|
+
```
|
42
45
|
|
43
46
|
Optional keys include `login_host` (default is 'login.salesforce.com') and `version` (default is '24.0').
|
44
47
|
|
45
|
-
### Configuring from a YAML file
|
46
|
-
|
47
|
-
Create a YAML file with the content below. Only `username` and `password` is required.
|
48
|
-
|
49
|
-
---
|
50
|
-
username: MyUsername
|
51
|
-
password: MyPassword
|
52
|
-
login_host: login.salesforce.com # default
|
53
|
-
version: 24.0 # default
|
54
|
-
|
55
|
-
Then in a Ruby script:
|
56
|
-
|
57
|
-
require 'salesforce_bulk'
|
58
|
-
|
59
|
-
client = SalesforceBulk::Client.new("config/salesforce_bulk.yml")
|
60
|
-
client.authenticate
|
61
|
-
|
62
48
|
## Usage Examples
|
63
49
|
|
64
50
|
An important note about the data in any of the examples below: each hash in a data set must have the same set of keys. If you need to have logic to not include certain values simply specify a nil value for a key rather than not including the key-value pair.
|
65
51
|
|
66
52
|
### Basic Overall Example
|
67
53
|
|
68
|
-
|
69
|
-
|
54
|
+
```ruby
|
55
|
+
data1 = [{:Name__c => 'Test 1'}, {:Name__c => 'Test 2'}]
|
56
|
+
data2 = [{:Name__c => 'Test 3'}, {:Name__c => 'Test 4'}]
|
70
57
|
|
71
|
-
|
58
|
+
job = client.add_job(:insert, :MyObject__c)
|
72
59
|
|
73
|
-
|
74
|
-
|
75
|
-
|
60
|
+
# easily add multiple batches to a job
|
61
|
+
batch = client.add_batch(job.id, data1)
|
62
|
+
batch = client.add_batch(job.id, data2)
|
76
63
|
|
77
|
-
|
64
|
+
job = client.close_job(job.id) # or use the abort_job(id) method
|
65
|
+
```
|
78
66
|
|
79
67
|
### Adding a Job
|
80
68
|
|
81
69
|
When adding a job you can specify the following operations for the first argument:
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
86
|
-
-
|
70
|
+
- `:delete`
|
71
|
+
- `:insert`
|
72
|
+
- `:update`
|
73
|
+
- `:upsert`
|
74
|
+
- `:query`
|
87
75
|
|
88
76
|
When using the :upsert operation you must specify an external ID field name:
|
89
77
|
|
90
|
-
|
78
|
+
```ruby
|
79
|
+
job = client.add_job(:upsert, :MyObject__c, :external_id_field_name => :MyId__c)
|
80
|
+
```
|
91
81
|
|
92
82
|
For any operation you should be able to specify a concurrency mode. The default is `Parallel`. The only other choice is `Serial`.
|
93
83
|
|
94
|
-
|
84
|
+
```ruby
|
85
|
+
job = client.add_job(:upsert, :MyObject__c, :concurrency_mode => :Serial, :external_id_field_name => :MyId__c)
|
86
|
+
```
|
95
87
|
|
96
88
|
### Retrieving Job Information (e.g. Status)
|
97
89
|
|
98
90
|
The Job object has various properties such as status, created time, number of completed and failed batches and various other values.
|
99
91
|
|
100
|
-
|
92
|
+
```ruby
|
93
|
+
job = client.job_info(jobId) # returns a Job object
|
101
94
|
|
102
|
-
|
95
|
+
puts "Job #{job.id} is closed." if job.closed? # other: open?, aborted?
|
96
|
+
```
|
103
97
|
|
104
98
|
### Retrieving Info for a single Batch
|
105
99
|
|
106
100
|
The Batch object has various properties such as status, created time, number of processed and failed records and various other values.
|
107
101
|
|
108
|
-
|
102
|
+
```ruby
|
103
|
+
batch = client.batch_info(jobId, batchId) # returns a Batch object
|
109
104
|
|
110
|
-
|
105
|
+
puts "Batch #{batch.id} is in progress." if batch.in_progress?
|
106
|
+
```
|
111
107
|
|
112
108
|
### Retrieving Info for all Batches
|
113
109
|
|
114
|
-
|
110
|
+
```ruby
|
111
|
+
batches = client.batch_info_list(jobId) # returns an Array of Batch objects
|
115
112
|
|
116
|
-
|
117
|
-
|
118
|
-
|
113
|
+
batches.each do |batch|
|
114
|
+
puts "Batch #{batch.id} completed." if batch.completed? # other: failed?, in_progress?, queued?
|
115
|
+
end
|
116
|
+
```
|
119
117
|
|
120
118
|
### Retrieving Batch Results (for Delete, Insert, Update and Upsert)
|
121
119
|
|
@@ -123,11 +121,13 @@ To verify that a batch completed successfully or failed call the `batch_info` or
|
|
123
121
|
|
124
122
|
The object returned from the following example only applies to the operations: `delete`, `insert`, `update` and `upsert`. Query results are handled differently.
|
125
123
|
|
126
|
-
|
124
|
+
```ruby
|
125
|
+
results = client.batch_result(jobId, batchId) # returns an Array of BatchResult objects
|
127
126
|
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
results.each do |result|
|
128
|
+
puts "Item #{result.id} had an error of: #{result.error}" if result.error?
|
129
|
+
end
|
130
|
+
```
|
131
131
|
|
132
132
|
### Retrieving Query based Batch Results
|
133
133
|
|
@@ -135,87 +135,44 @@ To verify that a batch completed successfully or failed call the `batch_info` or
|
|
135
135
|
|
136
136
|
Query results are handled differently as its possible that a single batch could return multiple results if objects returned are large enough. Note: I haven't been able to replicate this behavior but in a fork by @WWJacob has [discovered that multiple results can be returned](https://github.com/WWJacob/salesforce_bulk/commit/8f9e68c390230e885823e45cd2616ac3159697ef).
|
137
137
|
|
138
|
-
|
139
|
-
|
138
|
+
```ruby
|
139
|
+
# returns a QueryResultCollection object (an Array)
|
140
|
+
results = client.batch_result(jobId, batchId)
|
140
141
|
|
141
|
-
|
142
|
+
while results.any?
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
144
|
+
# Assuming query was: SELECT Id, Name, CustomField__c FROM Account
|
145
|
+
results.each do |result|
|
146
|
+
puts result[:Id], result[:Name], result[:CustomField__c]
|
147
|
+
end
|
147
148
|
|
148
|
-
|
149
|
+
puts "Another set is available." if results.next?
|
149
150
|
|
150
|
-
|
151
|
+
results.next
|
151
152
|
|
152
|
-
|
153
|
+
end
|
154
|
+
```
|
153
155
|
|
154
156
|
Note: By reviewing the API docs and response format my understanding was that the API would return multiple results sets for a single batch if the query was to large but this does not seem to be the case in my live testing. It seems to be capped at 10000 records (as it when inserting data) but I haven't been able to verify through the documentation. If you know anything about that your input is appreciated. In the meantime the gem was built to support multiple result sets for a query batch but seems that will change which will simplify that method.
|
155
157
|
|
158
|
+
## Releasing
|
159
|
+
|
160
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
161
|
+
|
156
162
|
## Contribution Suggestions/Ideas
|
157
163
|
|
158
164
|
- Support for other Ruby platforms
|
159
165
|
- Clean up/reorganize tests better
|
160
166
|
- Rdocs
|
161
167
|
|
162
|
-
|
163
|
-
|
164
|
-
**2.0.0** (April 25, 2015)
|
165
|
-
|
166
|
-
* Dropped support for Ruby 1.8 and Ruby 1.9
|
167
|
-
* Added support for Ruby 2.0, 2.1 and 2.2
|
168
|
-
* Added support for Rails 4.0, 4.1 an 4.2
|
169
|
-
* Changed test_helper to avoid requiring test_unit (removed in Ruby 2.2)
|
170
|
-
* Replaced Test::Unit::TestCase with ActiveSupport::TestCase
|
171
|
-
* Bumped shoulda and losen dependencies on minitest
|
172
|
-
* All changes in PR's #13, #14, #15, #16 - thanks [@pschambacher](https://github.com/pschambacher)
|
173
|
-
|
174
|
-
**1.4.0** (June 1, 2014)
|
175
|
-
|
176
|
-
* Added state_message to Batch class (#11 - thanks [@bethesque](https://github.com/bethesque))
|
177
|
-
|
178
|
-
**1.3.0** (April 28, 2014)
|
168
|
+
### Releasing
|
179
169
|
|
180
|
-
|
181
|
-
* Added dependency version requirements to gemspec
|
170
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
182
171
|
|
183
|
-
|
172
|
+
## Contributing
|
184
173
|
|
185
|
-
|
186
|
-
|
187
|
-
**1.1.0** (August 20, 2012)
|
188
|
-
|
189
|
-
* Added travis setup. Support for Ruby 1.9.2 and 1.9.3 specified.
|
190
|
-
* Removed `token` property on Client object. Specify token in `password` field.
|
191
|
-
* Accepted pull request for 1.9.3 improvements.
|
192
|
-
* Description updates in README.
|
193
|
-
|
194
|
-
**1.0.0** (August 17, 2012)
|
195
|
-
|
196
|
-
* Initial public release.
|
174
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/javierjulio/salesforce_bulk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
197
175
|
|
198
176
|
## License
|
199
177
|
|
200
|
-
|
201
|
-
|
202
|
-
Copyright (c) 2012 Javier Julio
|
203
|
-
|
204
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
205
|
-
a copy of this software and associated documentation files (the
|
206
|
-
"Software"), to deal in the Software without restriction, including
|
207
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
208
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
209
|
-
permit persons to whom the Software is furnished to do so, subject to
|
210
|
-
the following conditions:
|
211
|
-
|
212
|
-
The above copyright notice and this permission notice shall be
|
213
|
-
included in all copies or substantial portions of the Software.
|
214
|
-
|
215
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
216
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
217
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
218
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
219
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
220
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
221
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
178
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/salesforce_bulk.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
require 'net/
|
1
|
+
require 'net/http'
|
2
2
|
require 'xmlsimple'
|
3
3
|
require 'csv'
|
4
|
-
require 'active_support'
|
5
|
-
require 'active_support/core_ext/object/blank'
|
6
|
-
require 'active_support/core_ext/hash/keys'
|
7
4
|
require 'salesforce_bulk/version'
|
8
|
-
require 'salesforce_bulk/core_extensions/string'
|
9
5
|
require 'salesforce_bulk/salesforce_error'
|
10
6
|
require 'salesforce_bulk/client'
|
11
7
|
require 'salesforce_bulk/job'
|
@@ -1,37 +1,37 @@
|
|
1
1
|
module SalesforceBulk
|
2
2
|
class BatchResult
|
3
|
-
|
3
|
+
|
4
4
|
# A boolean indicating if record was created. If updated value is false.
|
5
5
|
attr_accessor :created
|
6
|
-
|
6
|
+
|
7
7
|
# The error message.
|
8
8
|
attr_accessor :error
|
9
|
-
|
9
|
+
|
10
10
|
# The record's unique id.
|
11
11
|
attr_accessor :id
|
12
|
-
|
13
|
-
# If record was created successfully. If false then an error message is provided.
|
12
|
+
|
13
|
+
# If record was created successfully. If false then an error message is provided.
|
14
14
|
attr_accessor :success
|
15
|
-
|
15
|
+
|
16
16
|
def initialize(id, success, created, error)
|
17
17
|
@id = id
|
18
18
|
@success = success
|
19
19
|
@created = created
|
20
20
|
@error = error
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def error?
|
24
|
-
error.
|
24
|
+
!error.nil? && error.respond_to?(:empty?) && !error.empty?
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def created?
|
28
28
|
created
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def successful?
|
32
32
|
success
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def updated?
|
36
36
|
!created && success
|
37
37
|
end
|
@@ -17,15 +17,13 @@ module SalesforceBulk
|
|
17
17
|
# The API version the client is using. Defaults to 24.0.
|
18
18
|
attr_accessor :version
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
options = YAML.load_file(options)
|
23
|
-
options.symbolize_keys!
|
24
|
-
end
|
20
|
+
# The ID for authenticated session
|
21
|
+
attr_reader :session_id
|
25
22
|
|
23
|
+
def initialize(options={})
|
26
24
|
options = {:login_host => 'login.salesforce.com', :version => 24.0}.merge(options)
|
27
25
|
|
28
|
-
|
26
|
+
assert_valid_keys(options, :username, :password, :login_host, :version)
|
29
27
|
|
30
28
|
self.username = options[:username]
|
31
29
|
self.password = "#{options[:password]}"
|
@@ -38,6 +36,10 @@ module SalesforceBulk
|
|
38
36
|
end
|
39
37
|
|
40
38
|
def authenticate
|
39
|
+
# Clear session attributes just in case client already had a session
|
40
|
+
@session_id = nil
|
41
|
+
self.instance_host = nil
|
42
|
+
|
41
43
|
xml = '<?xml version="1.0" encoding="utf-8"?>'
|
42
44
|
xml += '<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
|
43
45
|
xml += ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
|
@@ -45,7 +47,7 @@ module SalesforceBulk
|
|
45
47
|
xml += "<env:Body>"
|
46
48
|
xml += '<n1:login xmlns:n1="urn:partner.soap.sforce.com">'
|
47
49
|
xml += "<n1:username>#{username}</n1:username>"
|
48
|
-
xml += "<n1:password>#{password}</n1:password>"
|
50
|
+
xml += "<n1:password>#{password.encode(xml: :text)}</n1:password>"
|
49
51
|
xml += "</n1:login>"
|
50
52
|
xml += "</env:Body>"
|
51
53
|
xml += "</env:Envelope>\n"
|
@@ -99,7 +101,7 @@ module SalesforceBulk
|
|
99
101
|
|
100
102
|
raise ArgumentError.new("Invalid operation: #{operation}") unless @valid_operations.include?(operation)
|
101
103
|
|
102
|
-
|
104
|
+
assert_valid_keys(options, :external_id_field_name, :concurrency_mode)
|
103
105
|
|
104
106
|
if options[:concurrency_mode]
|
105
107
|
concurrency_mode = options[:concurrency_mode].capitalize
|
@@ -117,7 +119,7 @@ module SalesforceBulk
|
|
117
119
|
|
118
120
|
response = http_post("job", xml)
|
119
121
|
data = XmlSimple.xml_in(response.body, 'ForceArray' => false)
|
120
|
-
|
122
|
+
Job.new_from_xml(data)
|
121
123
|
end
|
122
124
|
|
123
125
|
def batch_info_list(jobId)
|
@@ -142,10 +144,10 @@ module SalesforceBulk
|
|
142
144
|
def batch_result(jobId, batchId)
|
143
145
|
response = http_get("job/#{jobId}/batch/#{batchId}/result")
|
144
146
|
|
145
|
-
if response.
|
147
|
+
if ['application/xml', 'text/xml'].include? response.content_type
|
146
148
|
result = XmlSimple.xml_in(response.body)
|
147
149
|
|
148
|
-
if result['result'].
|
150
|
+
if !result['result'].nil? && !result['result'].empty?
|
149
151
|
results = query_result(jobId, batchId, result['result'].first)
|
150
152
|
|
151
153
|
collection = QueryResultCollection.new(self, jobId, batchId, result['result'].first, result['result'])
|
@@ -155,7 +157,7 @@ module SalesforceBulk
|
|
155
157
|
result = BatchResultCollection.new(jobId, batchId)
|
156
158
|
|
157
159
|
CSV.parse(response.body, :headers => true) do |row|
|
158
|
-
result << BatchResult.new(row[0], row[1]
|
160
|
+
result << BatchResult.new(row[0], to_boolean(row[1]), to_boolean(row[2]), row[3])
|
159
161
|
end
|
160
162
|
|
161
163
|
result
|
@@ -171,7 +173,7 @@ module SalesforceBulk
|
|
171
173
|
|
172
174
|
result = []
|
173
175
|
|
174
|
-
#CSV.parse(lines.join, :headers => headers, :converters => [:all, lambda{|s| s
|
176
|
+
#CSV.parse(lines.join, :headers => headers, :converters => [:all, lambda{|s| to_boolean(s) if s.kind_of? String }]) do |row|
|
175
177
|
CSV.parse(lines.join, :headers => headers) do |row|
|
176
178
|
result << Hash[row.headers.zip(row.fields)]
|
177
179
|
end
|
@@ -244,5 +246,27 @@ module SalesforceBulk
|
|
244
246
|
def instance_id(url)
|
245
247
|
url.match(/:\/\/([a-zA-Z0-9\-\.]{2,}).salesforce/)[1]
|
246
248
|
end
|
249
|
+
|
250
|
+
private
|
251
|
+
|
252
|
+
def assert_valid_keys(options, *valid_keys)
|
253
|
+
valid_keys.flatten!
|
254
|
+
options.each_key do |k|
|
255
|
+
unless valid_keys.include?(k)
|
256
|
+
raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}")
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def to_boolean(value)
|
262
|
+
if !value.nil?
|
263
|
+
if value.strip.casecmp("true") == 0
|
264
|
+
return true
|
265
|
+
elsif value.strip.casecmp("false") == 0
|
266
|
+
return false
|
267
|
+
end
|
268
|
+
end
|
269
|
+
value
|
270
|
+
end
|
247
271
|
end
|
248
272
|
end
|
data/lib/salesforce_bulk/job.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module SalesforceBulk
|
2
2
|
class Job
|
3
|
-
|
3
|
+
|
4
4
|
attr_accessor :concurrency_mode
|
5
5
|
attr_accessor :external_id_field_name
|
6
6
|
attr_accessor :id
|
@@ -23,7 +23,7 @@ module SalesforceBulk
|
|
23
23
|
attr_accessor :api_active_processing_time
|
24
24
|
attr_accessor :total_processing_time
|
25
25
|
attr_accessor :api_version
|
26
|
-
|
26
|
+
|
27
27
|
def self.new_from_xml(data)
|
28
28
|
job = self.new
|
29
29
|
job.id = data['id']
|
@@ -40,7 +40,7 @@ module SalesforceBulk
|
|
40
40
|
job.in_progress_batches = data['numberBatchesInProgress'].to_i
|
41
41
|
job.completed_batches = data['numberBatchesCompleted'].to_i
|
42
42
|
job.failed_batches = data['numberBatchesFailed'].to_i
|
43
|
-
job.total_batches = data['
|
43
|
+
job.total_batches = data['numberBatchesTotal'].to_i
|
44
44
|
job.retries = data['retries'].to_i
|
45
45
|
job.processed_records = data['numberRecordsProcessed'].to_i
|
46
46
|
job.failed_records = data['numberRecordsFailed'].to_i
|
@@ -50,21 +50,21 @@ module SalesforceBulk
|
|
50
50
|
job.api_version = data['apiVersion'].to_i
|
51
51
|
job
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def aborted?
|
55
55
|
state? 'Aborted'
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def closed?
|
59
59
|
state? 'Closed'
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def open?
|
63
63
|
state? 'Open'
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def state?(value)
|
67
|
-
self.state.
|
67
|
+
!self.state.nil? && self.state.casecmp(value) == 0
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module SalesforceBulk
|
2
2
|
class QueryResultCollection < Array
|
3
|
-
|
3
|
+
|
4
4
|
attr_reader :client
|
5
5
|
attr_reader :batch_id
|
6
6
|
attr_reader :job_id
|
7
7
|
attr_reader :result_id
|
8
8
|
attr_reader :result_ids
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(client, job_id, batch_id, result_id=nil, result_ids=[])
|
11
11
|
@client = client
|
12
12
|
@job_id = job_id
|
@@ -15,34 +15,34 @@ module SalesforceBulk
|
|
15
15
|
@result_ids = result_ids
|
16
16
|
@current_index = result_ids.index(result_id) || 0
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def next?
|
20
|
-
|
20
|
+
!@result_ids.nil? && !@result_ids.empty? && @current_index < @result_ids.length - 1
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def next
|
24
24
|
if next?
|
25
25
|
replace(@client.query_result(job_id, batch_id, result_ids[@current_index + 1]))
|
26
26
|
@current_index += 1
|
27
27
|
@result_id = @result_ids[@current_index]
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
self
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def previous?
|
34
|
-
|
34
|
+
!@result_ids.nil? && !@result_ids.empty? && @current_index > 0
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def previous
|
38
38
|
if previous?
|
39
39
|
replace(@client.query_result(job_id, batch_id, result_ids[@current_index - 1]))
|
40
40
|
@current_index -= 1
|
41
41
|
@result_id = @result_ids[@current_index]
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
self
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
end
|
48
48
|
end
|
metadata
CHANGED
@@ -1,35 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesforcebulk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Julio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 3.2.0
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '5.0'
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 3.2.0
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '5.0'
|
33
13
|
- !ruby/object:Gem::Dependency
|
34
14
|
name: xml-simple
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,7 +39,7 @@ dependencies:
|
|
59
39
|
- !ruby/object:Gem::Version
|
60
40
|
version: '0'
|
61
41
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
42
|
+
name: mocha
|
63
43
|
requirement: !ruby/object:Gem::Requirement
|
64
44
|
requirements:
|
65
45
|
- - ">="
|
@@ -72,50 +52,8 @@ dependencies:
|
|
72
52
|
- - ">="
|
73
53
|
- !ruby/object:Gem::Version
|
74
54
|
version: '0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: mocha
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: 0.13.0
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - "~>"
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: 0.13.0
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: shoulda
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 3.5.0
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 3.5.0
|
103
55
|
- !ruby/object:Gem::Dependency
|
104
56
|
name: webmock
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 1.8.11
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: 1.8.11
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: minitest
|
119
57
|
requirement: !ruby/object:Gem::Requirement
|
120
58
|
requirements:
|
121
59
|
- - ">="
|
@@ -129,7 +67,7 @@ dependencies:
|
|
129
67
|
- !ruby/object:Gem::Version
|
130
68
|
version: '0'
|
131
69
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
70
|
+
name: minitest
|
133
71
|
requirement: !ruby/object:Gem::Requirement
|
134
72
|
requirements:
|
135
73
|
- - ">="
|
@@ -143,7 +81,7 @@ dependencies:
|
|
143
81
|
- !ruby/object:Gem::Version
|
144
82
|
version: '0'
|
145
83
|
- !ruby/object:Gem::Dependency
|
146
|
-
name:
|
84
|
+
name: minitest-reporters
|
147
85
|
requirement: !ruby/object:Gem::Requirement
|
148
86
|
requirements:
|
149
87
|
- - ">="
|
@@ -170,7 +108,6 @@ files:
|
|
170
108
|
- lib/salesforce_bulk/batch_result.rb
|
171
109
|
- lib/salesforce_bulk/batch_result_collection.rb
|
172
110
|
- lib/salesforce_bulk/client.rb
|
173
|
-
- lib/salesforce_bulk/core_extensions/string.rb
|
174
111
|
- lib/salesforce_bulk/job.rb
|
175
112
|
- lib/salesforce_bulk/query_result_collection.rb
|
176
113
|
- lib/salesforce_bulk/salesforce_error.rb
|
@@ -186,15 +123,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
123
|
requirements:
|
187
124
|
- - ">="
|
188
125
|
- !ruby/object:Gem::Version
|
189
|
-
version: '
|
126
|
+
version: '2.3'
|
190
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
128
|
requirements:
|
192
129
|
- - ">="
|
193
130
|
- !ruby/object:Gem::Version
|
194
131
|
version: '0'
|
195
132
|
requirements: []
|
196
|
-
|
197
|
-
rubygems_version: 2.4.6
|
133
|
+
rubygems_version: 3.1.4
|
198
134
|
signing_key:
|
199
135
|
specification_version: 4
|
200
136
|
summary: Full capability support for the Salesforce Bulk API.
|
@@ -1,14 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
# For converting "true" and "false" string values returned
|
3
|
-
# by Salesforce Bulk API in batch results to real booleans.
|
4
|
-
def to_b
|
5
|
-
if present?
|
6
|
-
if lstrip.rstrip.casecmp("true") == 0
|
7
|
-
return true
|
8
|
-
elsif lstrip.rstrip.casecmp("false") == 0
|
9
|
-
return false
|
10
|
-
end
|
11
|
-
end
|
12
|
-
self
|
13
|
-
end
|
14
|
-
end
|