activesalesforce 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +3 -1
- data/lib/asf_adapter.rb +21 -14
- data/lib/rforce.rb +5 -8
- data/test/unit/basic_test.rb +6 -2
- data/test/unit/config.yml +3 -7
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_add_notes_to_contact.recording +1068 -875
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_assignment_rule_id.recording +836 -697
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_batch_insert.recording +852 -729
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_client_id.recording +1236 -0
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_count_contacts.recording +830 -2703
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_create_a_contact.recording +831 -692
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_a_contact.recording +831 -692
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_a_contact_by_first_name.recording +844 -949
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_a_contact_by_id.recording +865 -730
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_find_addresses.recording +841 -930
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_get_created_by_from_contact.recording +2071 -1614
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_master_detail.recording +1146 -701
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_read_all_content_columns.recording +831 -692
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_save_a_contact.recording +831 -692
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_use_default_rule.recording +833 -695
- data/test/unit/recorded_results/AsfUnitTestsBasicTest.test_use_update_mru.recording +833 -695
- data/test/unit/recorded_test_case.rb +1 -3
- metadata +23 -35
- data/test/unit/config.yml~ +0 -8
- data/test/unit/profiler_results.txt +0 -1072
- data/test/unit/profiler_results_live.txt +0 -1347
- data/test/unit/test.html +0 -157
- data/test/unit/test.html~ +0 -183
data/README
CHANGED
@@ -19,10 +19,12 @@
|
|
19
19
|
4. edit database.yml
|
20
20
|
|
21
21
|
adapter: activesalesforce
|
22
|
-
url: https://www.salesforce.com
|
22
|
+
url: https://www.salesforce.com
|
23
23
|
username: <salesforce user name goes here>
|
24
24
|
password: <salesforce password goes here>
|
25
25
|
|
26
|
+
NOTE: If you want to access your Salesforce Sandbox account use https://test.salesforce.com as your url instead
|
27
|
+
|
26
28
|
5. proceed using standard Rails development techniques!
|
27
29
|
|
28
30
|
== Advanced Features
|
data/lib/asf_adapter.rb
CHANGED
@@ -50,11 +50,16 @@ module ActiveRecord
|
|
50
50
|
def self.activesalesforce_connection(config) # :nodoc:
|
51
51
|
debug("\nUsing ActiveSalesforce connection\n")
|
52
52
|
|
53
|
-
# Default to production system using
|
53
|
+
# Default to production system using 8.0 API
|
54
54
|
url = config[:url]
|
55
|
-
url = "https://www.salesforce.com
|
55
|
+
url = "https://www.salesforce.com" unless url
|
56
|
+
|
57
|
+
uri = URI.parse(url)
|
58
|
+
uri.path = "/services/Soap/u/8.0"
|
59
|
+
url = uri.to_s
|
56
60
|
|
57
61
|
sid = config[:sid]
|
62
|
+
client_id = config[:client_id]
|
58
63
|
username = config[:username].to_s
|
59
64
|
password = config[:password].to_s
|
60
65
|
|
@@ -65,6 +70,7 @@ module ActiveRecord
|
|
65
70
|
if recording_source
|
66
71
|
recording_source = File.open(recording_source, recording ? "w" : "r")
|
67
72
|
binding = ActiveSalesforce::RecordingBinding.new(url, nil, recording != nil, recording_source, logger)
|
73
|
+
binding.client_id = client_id if client_id
|
68
74
|
binding.login(username, password) unless sid
|
69
75
|
end
|
70
76
|
|
@@ -85,22 +91,22 @@ module ActiveRecord
|
|
85
91
|
# Check to insure that the second to last path component is a 'u' for Partner API
|
86
92
|
raise ActiveSalesforce::ASFError.new(logger, "Invalid salesforce server url '#{url}', must be a valid Parter API URL") unless url.match(/\/u\//mi)
|
87
93
|
|
88
|
-
binding = @@cache["#{url}.#{username}.#{password}"] unless binding
|
94
|
+
binding = @@cache["#{url}.#{username}.#{password}.#{client_id}"] unless binding
|
89
95
|
|
90
96
|
unless binding
|
91
|
-
debug("Establishing new connection for ['#{url}', '#{username}'")
|
97
|
+
debug("Establishing new connection for ['#{url}', '#{username}, '#{client_id}'")
|
92
98
|
|
93
99
|
seconds = Benchmark.realtime {
|
94
100
|
binding = RForce::Binding.new(url, sid)
|
95
101
|
binding.login(username, password)
|
96
102
|
|
97
|
-
@@cache["#{url}.#{username}.#{password}"] = binding
|
103
|
+
@@cache["#{url}.#{username}.#{password}.#{client_id}"] = binding
|
98
104
|
}
|
99
105
|
|
100
|
-
debug("Created new connection for ['#{url}', '#{username}'] in #{seconds} seconds")
|
106
|
+
debug("Created new connection for ['#{url}', '#{username}', '#{client_id}'] in #{seconds} seconds")
|
101
107
|
end
|
102
108
|
|
103
|
-
ConnectionAdapters::SalesforceAdapter.new(binding, logger, [url, username, password, sid], config)
|
109
|
+
ConnectionAdapters::SalesforceAdapter.new(binding, logger, [url, username, password, sid, client_id], config)
|
104
110
|
end
|
105
111
|
end
|
106
112
|
end
|
@@ -221,7 +227,7 @@ module ActiveRecord
|
|
221
227
|
result
|
222
228
|
end
|
223
229
|
|
224
|
-
|
230
|
+
|
225
231
|
# Commits the transaction (and turns on auto-committing).
|
226
232
|
def commit_db_transaction()
|
227
233
|
log("Committing boxcar with #{@command_boxcar.length} commands", 'commit_db_transaction()')
|
@@ -272,7 +278,7 @@ module ActiveRecord
|
|
272
278
|
selectCountMatch = sql.match(/SELECT\s+COUNT\(\*\)\s+FROM/mi) unless selectCountMatch
|
273
279
|
|
274
280
|
if selectCountMatch
|
275
|
-
soql = "SELECT
|
281
|
+
soql = "SELECT COUNT() FROM#{selectCountMatch.post_match}"
|
276
282
|
else
|
277
283
|
if sql.match(/SELECT\s+\*\s+FROM/mi)
|
278
284
|
# Always convert SELECT * to select all columns (required for the AR attributes mechanism to work correctly)
|
@@ -283,6 +289,11 @@ module ActiveRecord
|
|
283
289
|
end
|
284
290
|
|
285
291
|
soql.sub!(/\s+FROM\s+\w+/mi, " FROM #{entity_def.api_name}")
|
292
|
+
|
293
|
+
if selectCountMatch
|
294
|
+
query_result = get_result(@connection.query(:queryString => soql), :query)
|
295
|
+
return [{ :count => query_result[:size] }]
|
296
|
+
end
|
286
297
|
|
287
298
|
# Look for a LIMIT clause
|
288
299
|
limit = extract_sql_modifier(soql, "LIMIT")
|
@@ -323,11 +334,7 @@ module ActiveRecord
|
|
323
334
|
add_rows(entity_def, query_result, result, limit)
|
324
335
|
end
|
325
336
|
|
326
|
-
|
327
|
-
[{ :count => result.actual_size }]
|
328
|
-
else
|
329
|
-
result
|
330
|
-
end
|
337
|
+
result
|
331
338
|
}
|
332
339
|
end
|
333
340
|
|
data/lib/rforce.rb
CHANGED
@@ -128,7 +128,7 @@ module RForce
|
|
128
128
|
#Implements the connection to the SalesForce server.
|
129
129
|
class Binding
|
130
130
|
DEFAULT_BATCH_SIZE = 10
|
131
|
-
attr_accessor :batch_size, :url, :assignment_rule_id, :use_default_rule, :update_mru
|
131
|
+
attr_accessor :batch_size, :url, :assignment_rule_id, :use_default_rule, :update_mru, :client_id
|
132
132
|
|
133
133
|
#Fill in the guts of this typical SOAP envelope
|
134
134
|
#with the session ID and the body of the SOAP request.
|
@@ -157,6 +157,7 @@ module RForce
|
|
157
157
|
AssignmentRuleHeaderUsingRuleId = '<partner:AssignmentRuleHeader soap:mustUnderstand="1"><partner:assignmentRuleId>%s</partner:assignmentRuleId></partner:AssignmentRuleHeader>'
|
158
158
|
AssignmentRuleHeaderUsingDefaultRule = '<partner:AssignmentRuleHeader soap:mustUnderstand="1"><partner:useDefaultRule>true</partner:useDefaultRule></partner:AssignmentRuleHeader>'
|
159
159
|
MruHeader = '<partner:MruHeader soap:mustUnderstand="1"><partner:updateMru>true</partner:updateMru></partner:MruHeader>'
|
160
|
+
ClientIdHeader = '<partner:CallOptions soap:mustUnderstand="1"><partner:client>%s</partner:client></partner:CallOptions>'
|
160
161
|
|
161
162
|
#Connect to the server securely.
|
162
163
|
def initialize(url, sid)
|
@@ -190,11 +191,8 @@ module RForce
|
|
190
191
|
@password = password
|
191
192
|
|
192
193
|
response = call_remote(:login, [:username, user, :password, password])
|
193
|
-
|
194
|
-
unless response.loginResponse
|
195
|
-
pp response
|
196
|
-
raise "Incorrect user name / password [#{response.fault}]"
|
197
|
-
end
|
194
|
+
|
195
|
+
raise "Incorrect user name / password [#{response.fault}]" unless response.loginResponse
|
198
196
|
|
199
197
|
result = response[:loginResponse][:result]
|
200
198
|
@session_id = result[:sessionId]
|
@@ -218,6 +216,7 @@ module RForce
|
|
218
216
|
extra_headers << (AssignmentRuleHeaderUsingRuleId % assignment_rule_id) if assignment_rule_id
|
219
217
|
extra_headers << AssignmentRuleHeaderUsingDefaultRule if use_default_rule
|
220
218
|
extra_headers << MruHeader if update_mru
|
219
|
+
extra_headers << (ClientIdHeader % client_id) if client_id
|
221
220
|
|
222
221
|
#Fill in the blanks of the SOAP envelope with our
|
223
222
|
#session ID and the expanded XML of our request.
|
@@ -249,8 +248,6 @@ module RForce
|
|
249
248
|
|
250
249
|
# Check to see if INVALID_SESSION_ID was raised and try to relogin in
|
251
250
|
if method != :login and @session_id and content =~ /sf:INVALID_SESSION_ID/
|
252
|
-
puts "\n\nSession timeout error - auto relogin activated"
|
253
|
-
|
254
251
|
login(@user, @password)
|
255
252
|
|
256
253
|
# repackage and rencode request with the new session id
|
data/test/unit/basic_test.rb
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
require 'rubygems'
|
19
19
|
|
20
20
|
#require_gem 'activesalesforce', '>= 0.4.3'
|
21
|
-
require File.dirname(__FILE__) + '/../../lib/
|
21
|
+
require File.dirname(__FILE__) + '/../../lib/asf_adapter'
|
22
22
|
|
23
23
|
require File.dirname(__FILE__) + '/recorded_test_case'
|
24
24
|
require 'pp'
|
@@ -45,7 +45,7 @@ module Asf
|
|
45
45
|
def initialize(test_method_name)
|
46
46
|
super(test_method_name)
|
47
47
|
|
48
|
-
#force_recording :
|
48
|
+
#force_recording :test_create_a_contact
|
49
49
|
end
|
50
50
|
|
51
51
|
def setup
|
@@ -132,6 +132,10 @@ module Asf
|
|
132
132
|
contact.save
|
133
133
|
end
|
134
134
|
|
135
|
+
def test_client_id
|
136
|
+
Contact.connection.binding.client_id = "testClient"
|
137
|
+
contact.save
|
138
|
+
end
|
135
139
|
|
136
140
|
|
137
141
|
def test_add_notes_to_contact
|
data/test/unit/config.yml
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
url: https://
|
2
|
-
username:
|
3
|
-
password:
|
4
|
-
|
5
|
-
#username: admin@summer05_pbrondum.com
|
6
|
-
#password: Test2000
|
7
|
-
|
1
|
+
url: https://test.salesforce.com
|
2
|
+
username: dutch@activesalesforce.com
|
3
|
+
password: maceymo
|
8
4
|
recording: true
|