salesforce_bulk 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/salesforce_bulk.rb +70 -71
- data/lib/salesforce_bulk/connection.rb +10 -9
- data/lib/salesforce_bulk/job.rb +1 -1
- data/lib/salesforce_bulk/version.rb +1 -1
- data/salesforce_bulk.gemspec +27 -29
- metadata +15 -4
data/lib/salesforce_bulk.rb
CHANGED
@@ -1,71 +1,70 @@
|
|
1
|
-
require 'net/
|
2
|
-
require 'xmlsimple'
|
3
|
-
require 'csv'
|
4
|
-
require "salesforce_bulk/version"
|
5
|
-
require 'salesforce_bulk/job'
|
6
|
-
require 'salesforce_bulk/connection'
|
7
|
-
|
8
|
-
module SalesforceBulk
|
9
|
-
# Your code goes here...
|
10
|
-
class Api
|
11
|
-
|
12
|
-
@@SALESFORCE_API_VERSION = '23.0'
|
13
|
-
|
14
|
-
def initialize(username, password)
|
15
|
-
@connection = SalesforceBulk::Connection.new(username, password, @@SALESFORCE_API_VERSION)
|
16
|
-
end
|
17
|
-
|
18
|
-
def upsert(sobject, records, external_field)
|
19
|
-
self.do_operation('upsert', sobject, records, external_field)
|
20
|
-
end
|
21
|
-
|
22
|
-
def update(sobject, records)
|
23
|
-
self.do_operation('update', sobject, records, nil)
|
24
|
-
end
|
25
|
-
|
26
|
-
def create(sobject, records)
|
27
|
-
self.do_operation('insert', sobject, records, nil)
|
28
|
-
end
|
29
|
-
|
30
|
-
def delete(sobject, records)
|
31
|
-
self.do_operation('delete', sobject, records, nil)
|
32
|
-
end
|
33
|
-
|
34
|
-
def query(sobject, query)
|
35
|
-
self.do_operation('query', sobject, query, nil)
|
36
|
-
end
|
37
|
-
|
38
|
-
#private
|
39
|
-
|
40
|
-
def do_operation(operation, sobject, records, external_field)
|
41
|
-
job = SalesforceBulk::Job.new(operation, sobject, records, external_field, @connection)
|
42
|
-
|
43
|
-
# TODO: put this in one function
|
44
|
-
job_id = job.create_job()
|
45
|
-
if(operation == "query")
|
46
|
-
batch_id = job.add_query()
|
47
|
-
else
|
48
|
-
batch_id = job.add_batch()
|
49
|
-
end
|
50
|
-
job.close_job()
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
#puts "\nstate is #{state}\n"
|
55
|
-
state
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
1
|
+
require 'net/https'
|
2
|
+
require 'xmlsimple'
|
3
|
+
require 'csv'
|
4
|
+
require "salesforce_bulk/version"
|
5
|
+
require 'salesforce_bulk/job'
|
6
|
+
require 'salesforce_bulk/connection'
|
7
|
+
|
8
|
+
module SalesforceBulk
|
9
|
+
# Your code goes here...
|
10
|
+
class Api
|
11
|
+
|
12
|
+
@@SALESFORCE_API_VERSION = '23.0'
|
13
|
+
|
14
|
+
def initialize(username, password)
|
15
|
+
@connection = SalesforceBulk::Connection.new(username, password, @@SALESFORCE_API_VERSION)
|
16
|
+
end
|
17
|
+
|
18
|
+
def upsert(sobject, records, external_field)
|
19
|
+
self.do_operation('upsert', sobject, records, external_field)
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(sobject, records)
|
23
|
+
self.do_operation('update', sobject, records, nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create(sobject, records)
|
27
|
+
self.do_operation('insert', sobject, records, nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(sobject, records)
|
31
|
+
self.do_operation('delete', sobject, records, nil)
|
32
|
+
end
|
33
|
+
|
34
|
+
def query(sobject, query)
|
35
|
+
self.do_operation('query', sobject, query, nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
#private
|
39
|
+
|
40
|
+
def do_operation(operation, sobject, records, external_field)
|
41
|
+
job = SalesforceBulk::Job.new(operation, sobject, records, external_field, @connection)
|
42
|
+
|
43
|
+
# TODO: put this in one function
|
44
|
+
job_id = job.create_job()
|
45
|
+
if(operation == "query")
|
46
|
+
batch_id = job.add_query()
|
47
|
+
else
|
48
|
+
batch_id = job.add_batch()
|
49
|
+
end
|
50
|
+
job.close_job()
|
51
|
+
|
52
|
+
while true
|
53
|
+
state = job.check_batch_status()
|
54
|
+
#puts "\nstate is #{state}\n"
|
55
|
+
if state != "Queued"
|
56
|
+
break
|
57
|
+
end
|
58
|
+
sleep(2) # wait x seconds and check again
|
59
|
+
end
|
60
|
+
|
61
|
+
if state == 'Completed'
|
62
|
+
job.get_batch_result()
|
63
|
+
else
|
64
|
+
return "error"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end # End class
|
70
|
+
end
|
@@ -60,10 +60,7 @@ module SalesforceBulk
|
|
60
60
|
|
61
61
|
#puts "#{host} -- #{path} -- #{headers.inspect}\n"
|
62
62
|
|
63
|
-
|
64
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
65
|
-
resp = http.post(path, xml, headers)
|
66
|
-
return resp.body
|
63
|
+
https(host).post(path, xml, headers).body
|
67
64
|
end
|
68
65
|
|
69
66
|
def get_request(host, path, headers)
|
@@ -74,14 +71,18 @@ module SalesforceBulk
|
|
74
71
|
headers['X-SFDC-Session'] = @session_id;
|
75
72
|
end
|
76
73
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
74
|
+
https(host).get(path, headers).body
|
75
|
+
end
|
76
|
+
|
77
|
+
def https(host)
|
78
|
+
req = Net::HTTP.new(host, 443)
|
79
|
+
req.use_ssl = true
|
80
|
+
req.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
81
|
+
req
|
81
82
|
end
|
82
83
|
|
83
84
|
def parse_instance()
|
84
|
-
@server_url =~ /https:\/\/([a-z]{2,2}[0-9]{1,
|
85
|
+
@server_url =~ /https:\/\/([a-z]{2,2}[0-9]{1,2})-api/
|
85
86
|
@instance = $~.captures[0]
|
86
87
|
end
|
87
88
|
|
data/lib/salesforce_bulk/job.rb
CHANGED
data/salesforce_bulk.gemspec
CHANGED
@@ -1,29 +1,27 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "salesforce_bulk/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "salesforce_bulk"
|
7
|
-
s.version = SalesforceBulk::VERSION
|
8
|
-
s.authors = ["Jorge Valdivia"]
|
9
|
-
s.email = ["jorge@valdivia.me"]
|
10
|
-
s.homepage = "https://github.com/jorgevaldivia/salesforce_bulk"
|
11
|
-
s.summary = %q{Ruby support for the Salesforce Bulk API}
|
12
|
-
s.description = %q{This gem provides a super simple interface for the Salesforce Bulk API. It provides support for insert, update, upsert, delete, and query.}
|
13
|
-
|
14
|
-
s.rubyforge_project = "salesforce_bulk"
|
15
|
-
|
16
|
-
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
|
21
|
-
# specify any dependencies here; for example:
|
22
|
-
# s.add_development_dependency "rspec"
|
23
|
-
# s.add_runtime_dependency "rest-client"
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "salesforce_bulk/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "salesforce_bulk"
|
7
|
+
s.version = SalesforceBulk::VERSION
|
8
|
+
s.authors = ["Jorge Valdivia"]
|
9
|
+
s.email = ["jorge@valdivia.me"]
|
10
|
+
s.homepage = "https://github.com/jorgevaldivia/salesforce_bulk"
|
11
|
+
s.summary = %q{Ruby support for the Salesforce Bulk API}
|
12
|
+
s.description = %q{This gem provides a super simple interface for the Salesforce Bulk API. It provides support for insert, update, upsert, delete, and query.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "salesforce_bulk"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
|
25
|
+
s.add_dependency "xml-simple"
|
26
|
+
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesforce_bulk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
dependencies:
|
12
|
+
date: 2011-11-18 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: xml-simple
|
16
|
+
requirement: &24345852 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *24345852
|
14
25
|
description: This gem provides a super simple interface for the Salesforce Bulk API.
|
15
26
|
It provides support for insert, update, upsert, delete, and query.
|
16
27
|
email:
|
@@ -48,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
59
|
version: '0'
|
49
60
|
requirements: []
|
50
61
|
rubyforge_project: salesforce_bulk
|
51
|
-
rubygems_version: 1.8.
|
62
|
+
rubygems_version: 1.8.11
|
52
63
|
signing_key:
|
53
64
|
specification_version: 3
|
54
65
|
summary: Ruby support for the Salesforce Bulk API
|