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.
@@ -1,71 +1,70 @@
1
- require 'net/http'
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
- state = job.check_batch_status()
53
- while true
54
- #puts "\nstate is #{state}\n"
55
- state = job.check_batch_status()
56
- if state != "Queued"
57
- break
58
- end
59
- sleep(2) # wait x seconds and check again
60
- end
61
-
62
- if state == 'Completed'
63
- job.get_batch_result()
64
- else
65
- return "error"
66
- end
67
-
68
- end
69
-
70
- end # End class
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
- http = Net::HTTP.new(host)
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
- http = Net::HTTP.new(host)
78
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
79
- resp = http.get(path, headers)
80
- return resp.body
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,1})-api/
85
+ @server_url =~ /https:\/\/([a-z]{2,2}[0-9]{1,2})-api/
85
86
  @instance = $~.captures[0]
86
87
  end
87
88
 
@@ -34,7 +34,7 @@ module SalesforceBulk
34
34
 
35
35
  def close_job()
36
36
  xml = "#{@@XML_HEADER}<jobInfo xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">"
37
- xml += "state>Closed</state>"
37
+ xml += "<state>Closed</state>"
38
38
  xml += "</jobInfo>"
39
39
 
40
40
  path = "job/#{@@job_id}"
@@ -1,3 +1,3 @@
1
1
  module SalesforceBulk
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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
- #s.add_development_dependency "net-http"
26
- #s.add_development_dependency "xmlsimple"
27
- #s.add_development_dependency "csv"
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.3
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-10-19 00:00:00.000000000Z
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.10
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