salesforce_bulk2 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +2 -0
- data/README.md +143 -0
- data/Rakefile +22 -0
- data/lib/salesforce_bulk/batch.rb +86 -0
- data/lib/salesforce_bulk/batch_result.rb +39 -0
- data/lib/salesforce_bulk/batch_result_collection.rb +29 -0
- data/lib/salesforce_bulk/client.rb +209 -0
- data/lib/salesforce_bulk/connection.rb +155 -0
- data/lib/salesforce_bulk/core_extensions/string.rb +14 -0
- data/lib/salesforce_bulk/job.rb +126 -0
- data/lib/salesforce_bulk/query_result_collection.rb +48 -0
- data/lib/salesforce_bulk/salesforce_error.rb +30 -0
- data/lib/salesforce_bulk/version.rb +3 -0
- data/lib/salesforce_bulk.rb +17 -0
- data/salesforce_bulk.gemspec +27 -0
- data/test/fixtures/batch_create_request.csv +3 -0
- data/test/fixtures/batch_create_response.xml +13 -0
- data/test/fixtures/batch_info_list_response.xml +27 -0
- data/test/fixtures/batch_info_response.xml +13 -0
- data/test/fixtures/batch_result_list_response.csv +3 -0
- data/test/fixtures/config.yml +7 -0
- data/test/fixtures/invalid_batch_error.xml +5 -0
- data/test/fixtures/invalid_error.xml +5 -0
- data/test/fixtures/invalid_job_error.xml +5 -0
- data/test/fixtures/invalid_session_error.xml +5 -0
- data/test/fixtures/job_abort_request.xml +1 -0
- data/test/fixtures/job_abort_response.xml +25 -0
- data/test/fixtures/job_close_request.xml +1 -0
- data/test/fixtures/job_close_response.xml +25 -0
- data/test/fixtures/job_create_request.xml +1 -0
- data/test/fixtures/job_create_response.xml +25 -0
- data/test/fixtures/job_info_response.xml +25 -0
- data/test/fixtures/login_error.xml +1 -0
- data/test/fixtures/login_request.xml +1 -0
- data/test/fixtures/login_response.xml +39 -0
- data/test/fixtures/query_result_list_response.xml +1 -0
- data/test/fixtures/query_result_response.csv +5 -0
- data/test/lib/test_batch.rb +258 -0
- data/test/lib/test_batch_result.rb +40 -0
- data/test/lib/test_core_extensions.rb +15 -0
- data/test/lib/test_initialization.rb +86 -0
- data/test/lib/test_job.rb +256 -0
- data/test/lib/test_query_result_collection.rb +87 -0
- data/test/lib/test_simple_api.rb +79 -0
- data/test/test_helper.rb +32 -0
- metadata +222 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestQueryResultCollection < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
options = {
|
7
|
+
:username => 'myusername',
|
8
|
+
:password => 'mypassword',
|
9
|
+
:token => "somelongtoken"
|
10
|
+
}
|
11
|
+
|
12
|
+
@client = SalesforceBulk::Client.new(options)
|
13
|
+
@job_id = "123"
|
14
|
+
@batch_id = "234"
|
15
|
+
@result_ids = ["12","23","34"]
|
16
|
+
@result_id = @result_ids[1]
|
17
|
+
@collection = SalesforceBulk::QueryResultCollection.new(@client, @job_id, @batch_id, @result_id, @result_ids)
|
18
|
+
end
|
19
|
+
|
20
|
+
test "initilize using defaults" do
|
21
|
+
collection = SalesforceBulk::QueryResultCollection.new(@client, @job_id, @batch_id)
|
22
|
+
|
23
|
+
assert_equal collection.client, @client
|
24
|
+
assert_equal collection.job_id, @job_id
|
25
|
+
assert_equal collection.batch_id, @batch_id
|
26
|
+
assert_nil collection.result_id
|
27
|
+
assert_equal collection.result_ids, []
|
28
|
+
assert_equal collection.instance_variable_get('@current_index'), 0
|
29
|
+
end
|
30
|
+
|
31
|
+
test "initilize with all values" do
|
32
|
+
assert_equal @collection.client, @client
|
33
|
+
assert_equal @collection.job_id, @job_id
|
34
|
+
assert_equal @collection.batch_id, @batch_id
|
35
|
+
assert_equal @collection.result_id, @result_id
|
36
|
+
assert_equal @collection.result_ids, @result_ids
|
37
|
+
end
|
38
|
+
|
39
|
+
test "next?" do
|
40
|
+
assert @collection.next?
|
41
|
+
|
42
|
+
@collection.instance_variable_set('@current_index', @result_ids.length - 1)
|
43
|
+
assert !@collection.next?
|
44
|
+
|
45
|
+
@collection.instance_variable_set('@result_ids', [])
|
46
|
+
assert !@collection.next?
|
47
|
+
|
48
|
+
@collection.instance_variable_set('@result_ids', nil)
|
49
|
+
assert !@collection.next?
|
50
|
+
end
|
51
|
+
|
52
|
+
test "next" do
|
53
|
+
@client.expects(:query_result).once.with(@job_id, @batch_id, @result_ids.last).returns([])
|
54
|
+
|
55
|
+
@collection.next
|
56
|
+
|
57
|
+
assert_kind_of SalesforceBulk::QueryResultCollection, @collection
|
58
|
+
assert @collection.previous?
|
59
|
+
assert !@collection.next?
|
60
|
+
assert !@collection.next.any?
|
61
|
+
end
|
62
|
+
|
63
|
+
test "previous?" do
|
64
|
+
assert @collection.previous?
|
65
|
+
|
66
|
+
@collection.instance_variable_set('@current_index', 0)
|
67
|
+
assert !@collection.previous?
|
68
|
+
|
69
|
+
@collection.instance_variable_set('@result_ids', [])
|
70
|
+
assert !@collection.previous?
|
71
|
+
|
72
|
+
@collection.instance_variable_set('@result_ids', nil)
|
73
|
+
assert !@collection.previous?
|
74
|
+
end
|
75
|
+
|
76
|
+
test "previous" do
|
77
|
+
@client.expects(:query_result).once.with(@job_id, @batch_id, @result_ids.first).returns([])
|
78
|
+
|
79
|
+
@collection.previous
|
80
|
+
|
81
|
+
assert_kind_of SalesforceBulk::QueryResultCollection, @collection
|
82
|
+
assert @collection.next?
|
83
|
+
assert !@collection.previous?
|
84
|
+
assert !@collection.previous.any?
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestSimpleApi < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
options = {
|
7
|
+
:username => 'myusername',
|
8
|
+
:password => 'mypassword',
|
9
|
+
:token => "somelongtoken"
|
10
|
+
}
|
11
|
+
|
12
|
+
@client = SalesforceBulk::Client.new(options)
|
13
|
+
@job = SalesforceBulk::Job.new
|
14
|
+
@job.id = "123"
|
15
|
+
@batch = SalesforceBulk::Batch.new
|
16
|
+
@batch.id = "456"
|
17
|
+
end
|
18
|
+
|
19
|
+
test "delete" do
|
20
|
+
data = [{:Id => '123123'}, {:Id => '234234'}]
|
21
|
+
|
22
|
+
@client.expects(:add_job).once.with(:delete, :VideoEvent__c, :external_id_field_name => nil).returns(@job)
|
23
|
+
@client.expects(:add_batch).once.with(@job.id, data).returns(@batch)
|
24
|
+
@client.expects(:close_job).once.with(@job.id).returns(@job)
|
25
|
+
@client.expects(:batch_info).at_least_once.returns(@batch)
|
26
|
+
@client.expects(:batch_result).once.with(@job.id, @batch.id)
|
27
|
+
|
28
|
+
@client.delete(:VideoEvent__c, data)
|
29
|
+
end
|
30
|
+
|
31
|
+
test "insert" do
|
32
|
+
data = [{:Title__c => 'Test Title'}, {:Title__c => 'Test Title'}]
|
33
|
+
|
34
|
+
@client.expects(:add_job).once.with(:insert, :VideoEvent__c, :external_id_field_name => nil).returns(@job)
|
35
|
+
@client.expects(:add_batch).once.with(@job.id, data).returns(@batch)
|
36
|
+
@client.expects(:close_job).once.with(@job.id).returns(@job)
|
37
|
+
@client.expects(:batch_info).at_least_once.returns(@batch)
|
38
|
+
@client.expects(:batch_result).once.with(@job.id, @batch.id)
|
39
|
+
|
40
|
+
@client.insert(:VideoEvent__c, data)
|
41
|
+
end
|
42
|
+
|
43
|
+
test "query" do
|
44
|
+
data = 'SELECT Id, Name FROM Account'
|
45
|
+
|
46
|
+
@client.expects(:add_job).once.with(:query, :VideoEvent__c, :external_id_field_name => nil).returns(@job)
|
47
|
+
@client.expects(:add_batch).once.with(@job.id, data).returns(@batch)
|
48
|
+
@client.expects(:close_job).once.with(@job.id).returns(@job)
|
49
|
+
@client.expects(:batch_info).at_least_once.returns(@batch)
|
50
|
+
@client.expects(:batch_result).once.with(@job.id, @batch.id)
|
51
|
+
|
52
|
+
@client.query(:VideoEvent__c, data)
|
53
|
+
end
|
54
|
+
|
55
|
+
test "update" do
|
56
|
+
data = [{:Id => '123123', :Title__c => 'Test Title'}, {:Id => '234234', :Title__c => 'A Second Title'}]
|
57
|
+
|
58
|
+
@client.expects(:add_job).once.with(:update, :VideoEvent__c, :external_id_field_name => nil).returns(@job)
|
59
|
+
@client.expects(:add_batch).once.with(@job.id, data).returns(@batch)
|
60
|
+
@client.expects(:close_job).once.with(@job.id).returns(@job)
|
61
|
+
@client.expects(:batch_info).at_least_once.returns(@batch)
|
62
|
+
@client.expects(:batch_result).once.with(@job.id, @batch.id)
|
63
|
+
|
64
|
+
@client.update(:VideoEvent__c, data)
|
65
|
+
end
|
66
|
+
|
67
|
+
test "upsert" do
|
68
|
+
data = [{:Id__c => '123123', :Title__c => 'Test Title'}, {:Id__c => '234234', :Title__c => 'A Second Title'}]
|
69
|
+
|
70
|
+
@client.expects(:add_job).once.with(:upsert, :VideoEvent__c, :external_id_field_name => :Id__c).returns(@job)
|
71
|
+
@client.expects(:add_batch).once.with(@job.id, data).returns(@batch)
|
72
|
+
@client.expects(:close_job).once.with(@job.id).returns(@job)
|
73
|
+
@client.expects(:batch_info).at_least_once.returns(@batch)
|
74
|
+
@client.expects(:batch_result).once.with(@job.id, @batch.id)
|
75
|
+
|
76
|
+
@client.upsert(:VideoEvent__c, :Id__c, data)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'mocha'
|
5
|
+
require 'webmock/test_unit'
|
6
|
+
require 'salesforce_bulk'
|
7
|
+
|
8
|
+
class Test::Unit::TestCase
|
9
|
+
|
10
|
+
def self.test(name, &block)
|
11
|
+
define_method("test #{name.inspect}", &block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_url(client)
|
15
|
+
"https://#{client.host}/services/async/#{client.version}/"
|
16
|
+
end
|
17
|
+
|
18
|
+
def bypass_authentication(client)
|
19
|
+
client.instance_variable_set('@session_id', '123456789')
|
20
|
+
client.instance_variable_set('@host', 'na9.salesforce.com')
|
21
|
+
client.instance_variable_set('@instance_host', 'na9.salesforce.com')
|
22
|
+
end
|
23
|
+
|
24
|
+
def fixture_path(file)
|
25
|
+
File.expand_path("../fixtures/#{file}", __FILE__)
|
26
|
+
end
|
27
|
+
|
28
|
+
def fixture(file)
|
29
|
+
File.new(fixture_path(file)).read
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: salesforce_bulk2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Kerr
|
9
|
+
- Jorge Valdivia
|
10
|
+
- Javier Julio
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: active_support
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: xml-simple
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: mocha
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: rake
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
type: :development
|
73
|
+
prerelease: false
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: shoulda
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: webmock
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description: This gem is a simple interface to the Salesforce Bulk API providing support
|
113
|
+
for insert, update, upsert, delete, and query.
|
114
|
+
email:
|
115
|
+
- ajrkerr@gmail.com
|
116
|
+
- jorge@valdivia.me
|
117
|
+
- jjfutbol@gmail.com
|
118
|
+
executables: []
|
119
|
+
extensions: []
|
120
|
+
extra_rdoc_files: []
|
121
|
+
files:
|
122
|
+
- .gitignore
|
123
|
+
- Gemfile
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- lib/salesforce_bulk.rb
|
127
|
+
- lib/salesforce_bulk/batch.rb
|
128
|
+
- lib/salesforce_bulk/batch_result.rb
|
129
|
+
- lib/salesforce_bulk/batch_result_collection.rb
|
130
|
+
- lib/salesforce_bulk/client.rb
|
131
|
+
- lib/salesforce_bulk/connection.rb
|
132
|
+
- lib/salesforce_bulk/core_extensions/string.rb
|
133
|
+
- lib/salesforce_bulk/job.rb
|
134
|
+
- lib/salesforce_bulk/query_result_collection.rb
|
135
|
+
- lib/salesforce_bulk/salesforce_error.rb
|
136
|
+
- lib/salesforce_bulk/version.rb
|
137
|
+
- salesforce_bulk.gemspec
|
138
|
+
- test/fixtures/batch_create_request.csv
|
139
|
+
- test/fixtures/batch_create_response.xml
|
140
|
+
- test/fixtures/batch_info_list_response.xml
|
141
|
+
- test/fixtures/batch_info_response.xml
|
142
|
+
- test/fixtures/batch_result_list_response.csv
|
143
|
+
- test/fixtures/config.yml
|
144
|
+
- test/fixtures/invalid_batch_error.xml
|
145
|
+
- test/fixtures/invalid_error.xml
|
146
|
+
- test/fixtures/invalid_job_error.xml
|
147
|
+
- test/fixtures/invalid_session_error.xml
|
148
|
+
- test/fixtures/job_abort_request.xml
|
149
|
+
- test/fixtures/job_abort_response.xml
|
150
|
+
- test/fixtures/job_close_request.xml
|
151
|
+
- test/fixtures/job_close_response.xml
|
152
|
+
- test/fixtures/job_create_request.xml
|
153
|
+
- test/fixtures/job_create_response.xml
|
154
|
+
- test/fixtures/job_info_response.xml
|
155
|
+
- test/fixtures/login_error.xml
|
156
|
+
- test/fixtures/login_request.xml
|
157
|
+
- test/fixtures/login_response.xml
|
158
|
+
- test/fixtures/query_result_list_response.xml
|
159
|
+
- test/fixtures/query_result_response.csv
|
160
|
+
- test/lib/test_batch.rb
|
161
|
+
- test/lib/test_batch_result.rb
|
162
|
+
- test/lib/test_core_extensions.rb
|
163
|
+
- test/lib/test_initialization.rb
|
164
|
+
- test/lib/test_job.rb
|
165
|
+
- test/lib/test_query_result_collection.rb
|
166
|
+
- test/lib/test_simple_api.rb
|
167
|
+
- test/test_helper.rb
|
168
|
+
homepage: https://github.com/ajrkerr/salesforce_bulk
|
169
|
+
licenses: []
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ! '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ! '>='
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
requirements: []
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 1.8.23
|
189
|
+
signing_key:
|
190
|
+
specification_version: 3
|
191
|
+
summary: Ruby support for the Salesforce Bulk API
|
192
|
+
test_files:
|
193
|
+
- test/fixtures/batch_create_request.csv
|
194
|
+
- test/fixtures/batch_create_response.xml
|
195
|
+
- test/fixtures/batch_info_list_response.xml
|
196
|
+
- test/fixtures/batch_info_response.xml
|
197
|
+
- test/fixtures/batch_result_list_response.csv
|
198
|
+
- test/fixtures/config.yml
|
199
|
+
- test/fixtures/invalid_batch_error.xml
|
200
|
+
- test/fixtures/invalid_error.xml
|
201
|
+
- test/fixtures/invalid_job_error.xml
|
202
|
+
- test/fixtures/invalid_session_error.xml
|
203
|
+
- test/fixtures/job_abort_request.xml
|
204
|
+
- test/fixtures/job_abort_response.xml
|
205
|
+
- test/fixtures/job_close_request.xml
|
206
|
+
- test/fixtures/job_close_response.xml
|
207
|
+
- test/fixtures/job_create_request.xml
|
208
|
+
- test/fixtures/job_create_response.xml
|
209
|
+
- test/fixtures/job_info_response.xml
|
210
|
+
- test/fixtures/login_error.xml
|
211
|
+
- test/fixtures/login_request.xml
|
212
|
+
- test/fixtures/login_response.xml
|
213
|
+
- test/fixtures/query_result_list_response.xml
|
214
|
+
- test/fixtures/query_result_response.csv
|
215
|
+
- test/lib/test_batch.rb
|
216
|
+
- test/lib/test_batch_result.rb
|
217
|
+
- test/lib/test_core_extensions.rb
|
218
|
+
- test/lib/test_initialization.rb
|
219
|
+
- test/lib/test_job.rb
|
220
|
+
- test/lib/test_query_result_collection.rb
|
221
|
+
- test/lib/test_simple_api.rb
|
222
|
+
- test/test_helper.rb
|