salesforce_bulk_api 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ec5f79187db5cdcfcc991dbb8220e0bc0a23346
4
- data.tar.gz: 0873d30f2a3faca6f54d3c2faf3da52c90a963bc
3
+ metadata.gz: 99c3f558cf30c25184d78f67c158fac104d3deca
4
+ data.tar.gz: 4298337ac2a86b50e959eee7c9707a8de423778d
5
5
  SHA512:
6
- metadata.gz: 4a32896b615d513aa141dcc43f377e07971e1278eea1d89a6fd264184696b5384884d467d870adfa1f22f2bc935138bdaa2204d1724c7074d6a6f5fe116a38f0
7
- data.tar.gz: fe6f1c0cb8f62f21265da9ff3bd5727a2e68dd28d022abd43c6d904b906f0cd2323399995acbe20f63ac9969e0a013f8b36ebb6c60ed37fa43e2bf5bb8d6e3ff
6
+ metadata.gz: 035074901c3cbc3aeb06cb47b008c094e1e02b62b0c784021d9b434e8608c8d9bd89472580bf993397420c5849122821c3df3c540ac1d420f97d57178c5b74a4
7
+ data.tar.gz: 6b804db79f5ca0b6aa8be4233f72d842c08ab0e1465edfbc606c25615d33a3a5233419cae594b990fcbcefc7c4660afef43aca6b94417f907f7748e18dbe5274
data/README.md CHANGED
@@ -82,6 +82,22 @@ Sample operations:
82
82
  # Query
83
83
  res = salesforce.query("Account", "select id, name, createddate from Account limit 3") # We just need to pass the sobject name and the query string
84
84
 
85
+ Helpful methods:
86
+
87
+ # Check status of a job via #job_from_id
88
+ job = salesforce.job_from_id('a00A0001009zA2m') # Returns a SalesforceBulkApi::Job instance
89
+ puts "status is: #{job.check_job_status.inspect}"
90
+
91
+
92
+ Listening to events:
93
+
94
+ # A job is created
95
+ # Useful when you need to store the job_id before any work begins, then if you fail during a complex load scenario, you can wait for your
96
+ # previous job(s) to finish.
97
+ salesforce.on_job_created do |job|
98
+ puts "Job #{job.job_id} created!"
99
+ end
100
+
85
101
  ## Installation
86
102
 
87
103
  sudo gem install salesforce_bulk_api
@@ -9,13 +9,14 @@ require 'salesforce_bulk_api/job'
9
9
  require 'salesforce_bulk_api/connection'
10
10
 
11
11
  module SalesforceBulkApi
12
-
12
+
13
13
  class Api
14
14
 
15
- @@SALESFORCE_API_VERSION = '23.0'
15
+ @@SALESFORCE_API_VERSION = '32.0'
16
16
 
17
17
  def initialize(client)
18
18
  @connection = SalesforceBulkApi::Connection.new(@@SALESFORCE_API_VERSION,client)
19
+ @listeners = { job_created: [] }
19
20
  end
20
21
 
21
22
  def upsert(sobject, records, external_field, get_response = false, send_nulls = false, no_null_list = [], batch_size = 10000, timeout = 1500)
@@ -38,16 +39,30 @@ module SalesforceBulkApi
38
39
  self.do_operation('query', sobject, query, nil, true, timeout, batch_size)
39
40
  end
40
41
 
42
+ ##
43
+ # Allows you to attach a listener that accepts the created job (which has a useful #job_id field). This is useful
44
+ # for recording a job ID persistently before you begin batch work (i.e. start modifying the salesforce database),
45
+ # so if the load process you are writing needs to recover, it can be aware of previous jobs it started and wait
46
+ # for them to finish.
47
+ def on_job_created(&block)
48
+ @listeners[:job_created] << block
49
+ end
50
+
51
+ def job_from_id(job_id)
52
+ SalesforceBulkApi::Job.new(job_id: job_id, connection: @connection)
53
+ end
54
+
41
55
  #private
42
56
 
43
57
  def do_operation(operation, sobject, records, external_field, get_response, timeout, batch_size, send_nulls = false, no_null_list = [])
44
- job = SalesforceBulkApi::Job.new(operation, sobject, records, external_field, @connection)
58
+ job = SalesforceBulkApi::Job.new(operation: operation, sobject: sobject, records: records, external_field: external_field, connection: @connection)
45
59
 
46
60
  job.create_job(batch_size, send_nulls, no_null_list)
61
+ @listeners[:job_created].each {|callback| callback.call(job)}
47
62
  operation == "query" ? job.add_query() : job.add_batches()
48
63
  response = job.close_job
49
64
  response.merge!({'batches' => job.get_job_result(get_response, timeout)}) if get_response == true
50
65
  response
51
66
  end
52
- end
53
- end
67
+ end
68
+ end
@@ -75,7 +75,7 @@ require 'timeout'
75
75
 
76
76
  def parse_instance()
77
77
  @instance=@server_url.match(/https:\/\/[a-z]{2}[0-9]{1,2}/).to_s.gsub("https://","")
78
- @instance = @server_url.split(".salesforce.com")[0].split("://")[1] if @instance.blank?
78
+ @instance = @server_url.split(".salesforce.com")[0].split("://")[1] if @instance.nil? || @instance.empty?
79
79
  return @instance
80
80
  end
81
81
 
@@ -1,8 +1,12 @@
1
1
  module SalesforceBulkApi
2
2
 
3
3
  class Job
4
+ attr_reader :job_id
4
5
 
5
- def initialize(operation, sobject, records, external_field, connection)
6
+ class SalesforceException < StandardError; end
7
+
8
+ def initialize(operation: nil, sobject: nil, records: nil, external_field: nil, connection: nil, job_id: nil)
9
+ @job_id = job_id
6
10
  @operation = operation
7
11
  @sobject = sobject
8
12
  @external_field = external_field
@@ -12,6 +16,8 @@ module SalesforceBulkApi
12
16
  @XML_HEADER = '<?xml version="1.0" encoding="utf-8" ?>'
13
17
  end
14
18
 
19
+
20
+
15
21
  def create_job(batch_size, send_nulls, no_null_list)
16
22
  @batch_size = batch_size
17
23
  @send_nulls = send_nulls
@@ -32,6 +38,9 @@ module SalesforceBulkApi
32
38
  response = @connection.post_xml(nil, path, xml, headers)
33
39
  response_parsed = XmlSimple.xml_in(response)
34
40
 
41
+ # response may contain an exception, so raise it
42
+ raise SalesforceException.new("#{response_parsed['exceptionMessage'][0]} (#{response_parsed['exceptionCode'][0]})") if response_parsed['exceptionCode']
43
+
35
44
  @job_id = response_parsed['id'][0]
36
45
 
37
46
  end
@@ -112,6 +121,8 @@ module SalesforceBulkApi
112
121
  sobject_xml += "<#{k}>"
113
122
  if r[k].respond_to?(:encode)
114
123
  sobject_xml += r[k].encode(:xml => :text)
124
+ elsif r[k].respond_to?(:iso8601) # timestamps
125
+ sobject_xml += r[k].iso8601.to_s
115
126
  else
116
127
  sobject_xml += r[k].to_s
117
128
  end
@@ -1,3 +1,3 @@
1
1
  module SalesforceBulkApi
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: salesforce_bulk_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yatish Mehta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-12 00:00:00.000000000 Z
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: xml-simple
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.13'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.13'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: vcr
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '2.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.5'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: databasedotcom
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Salesforce Bulk API with governor limits taken care of
@@ -101,8 +101,8 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - .gitignore
105
- - .rspec
104
+ - ".gitignore"
105
+ - ".rspec"
106
106
  - Gemfile
107
107
  - README.md
108
108
  - Rakefile
@@ -123,21 +123,20 @@ require_paths:
123
123
  - lib
124
124
  required_ruby_version: !ruby/object:Gem::Requirement
125
125
  requirements:
126
- - - '>='
126
+ - - ">="
127
127
  - !ruby/object:Gem::Version
128
128
  version: '0'
129
129
  required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - '>='
131
+ - - ">="
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project: salesforce_bulk_api
136
- rubygems_version: 2.1.11
136
+ rubygems_version: 2.4.5
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: It uses the bulk api of salesforce to communicate with Salesforce CRM
140
140
  test_files:
141
141
  - spec/salesforce_bulk_api/salesforce_bulk_api_spec.rb
142
142
  - spec/spec_helper.rb
143
- has_rdoc: