salesforce_bulk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in salesforce_bulk.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,71 @@
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
@@ -0,0 +1,3 @@
1
+ module SalesforceBulk
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
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 = ""
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
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: salesforce_bulk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jorge Valdivia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-19 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: This gem provides a super simple interface for the Salesforce Bulk API.
15
+ It provides support for insert, update, upsert, delete, and query.
16
+ email:
17
+ - jorge@valdivia.me
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - Rakefile
25
+ - lib/salesforce_bulk.rb
26
+ - lib/salesforce_bulk/version.rb
27
+ - salesforce_bulk.gemspec
28
+ homepage: ''
29
+ licenses: []
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project: salesforce_bulk
48
+ rubygems_version: 1.8.10
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Ruby support for the Salesforce Bulk API
52
+ test_files: []