activesalesforce 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/column_definition.rb +0 -1
- data/lib/rforce.rb +12 -2
- data/lib/salesforce_connection_adapter.rb +47 -30
- metadata +1 -2
- data/lib/salesforce_login.rb +0 -39
data/lib/column_definition.rb
CHANGED
data/lib/rforce.rb
CHANGED
@@ -120,6 +120,7 @@ module RForce
|
|
120
120
|
return elements
|
121
121
|
end
|
122
122
|
end
|
123
|
+
|
123
124
|
|
124
125
|
#Implements the connection to the SalesForce server.
|
125
126
|
class Binding
|
@@ -147,17 +148,20 @@ module RForce
|
|
147
148
|
</env:Envelope>
|
148
149
|
HERE
|
149
150
|
|
151
|
+
|
150
152
|
#Connect to the server securely.
|
151
|
-
def initialize(url)
|
153
|
+
def initialize(url, sid = nil)
|
152
154
|
init_server(url)
|
153
155
|
|
154
|
-
@session_id =
|
156
|
+
@session_id = sid
|
155
157
|
@batch_size = DEFAULT_BATCH_SIZE
|
156
158
|
end
|
157
159
|
|
160
|
+
|
158
161
|
def show_debug
|
159
162
|
$DEBUG or ENV['SHOWSOAP']
|
160
163
|
end
|
164
|
+
|
161
165
|
|
162
166
|
def init_server(url)
|
163
167
|
@url = URI.parse(url)
|
@@ -169,6 +173,7 @@ module RForce
|
|
169
173
|
@server.set_debug_output $stderr if show_debug
|
170
174
|
end
|
171
175
|
|
176
|
+
|
172
177
|
#Log in to the server and remember the session ID
|
173
178
|
#returned to us by SalesForce.
|
174
179
|
def login(user, password)
|
@@ -186,6 +191,7 @@ module RForce
|
|
186
191
|
|
187
192
|
response
|
188
193
|
end
|
194
|
+
|
189
195
|
|
190
196
|
#Call a method on the remote server. Arguments can be
|
191
197
|
#a hash or (if order is important) an array of alternating
|
@@ -238,6 +244,7 @@ module RForce
|
|
238
244
|
|
239
245
|
SoapResponse.new(content)
|
240
246
|
end
|
247
|
+
|
241
248
|
|
242
249
|
# decode gzip
|
243
250
|
def decode(response)
|
@@ -260,6 +267,7 @@ module RForce
|
|
260
267
|
response.body
|
261
268
|
end
|
262
269
|
end
|
270
|
+
|
263
271
|
|
264
272
|
# encode gzip
|
265
273
|
def encode(request)
|
@@ -275,6 +283,7 @@ module RForce
|
|
275
283
|
end
|
276
284
|
end
|
277
285
|
|
286
|
+
|
278
287
|
#Turns method calls on this object into remote SOAP calls.
|
279
288
|
def method_missing(method, *args)
|
280
289
|
unless args.size == 1 && [Hash, Array].include?(args[0].class)
|
@@ -283,6 +292,7 @@ module RForce
|
|
283
292
|
|
284
293
|
call_remote method, args[0]
|
285
294
|
end
|
295
|
+
|
286
296
|
|
287
297
|
#Expand Ruby data structures into XML.
|
288
298
|
def expand(args, xmlns = nil)
|
@@ -26,7 +26,7 @@ require_gem 'rails', ">= 1.0.0"
|
|
26
26
|
|
27
27
|
require 'thread'
|
28
28
|
|
29
|
-
require File.dirname(__FILE__) + '/
|
29
|
+
require File.dirname(__FILE__) + '/rforce'
|
30
30
|
require File.dirname(__FILE__) + '/column_definition'
|
31
31
|
|
32
32
|
class ResultArray < Array
|
@@ -46,20 +46,38 @@ module ActiveRecord
|
|
46
46
|
puts "Using ActiveSalesforce connection!"
|
47
47
|
|
48
48
|
url = config[:url]
|
49
|
-
|
50
|
-
password = config[:password]
|
49
|
+
sid = config[:sid]
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
if sid
|
52
|
+
connection = @@cache["sid=#{sid}"]
|
53
|
+
unless connection
|
54
|
+
puts "Establishing new connection for [sid='#{sid}']"
|
55
|
+
|
56
|
+
connection = RForce::Binding.new(url, sid)
|
57
|
+
@@cache["sid=#{sid}"] = connection
|
58
|
+
|
59
|
+
puts "Created new connection for [sid='#{sid}']"
|
60
|
+
end
|
61
|
+
|
62
|
+
ConnectionAdapters::SalesforceAdapter.new(connection, logger, [url, sid], config)
|
63
|
+
else
|
64
|
+
username = config[:username]
|
65
|
+
password = config[:password]
|
66
|
+
|
67
|
+
connection = @@cache["#{url}.#{username}.#{password}"]
|
68
|
+
unless connection
|
69
|
+
puts "Establishing new connection for ['#{url}', '#{username}']"
|
70
|
+
|
71
|
+
connection = RForce::Binding.new(url)
|
72
|
+
connection.login(username, password).result
|
73
|
+
|
74
|
+
@@cache["#{url}.#{username}.#{password}"] = connection
|
75
|
+
|
76
|
+
puts "Created new connection for ['#{url}', '#{username}']"
|
77
|
+
end
|
58
78
|
|
59
|
-
|
79
|
+
ConnectionAdapters::SalesforceAdapter.new(connection, logger, [url, username, password], config)
|
60
80
|
end
|
61
|
-
|
62
|
-
ConnectionAdapters::SalesforceAdapter.new(connection, logger, [url, username, password], config)
|
63
81
|
end
|
64
82
|
end
|
65
83
|
|
@@ -72,15 +90,14 @@ module ActiveRecord
|
|
72
90
|
super message
|
73
91
|
|
74
92
|
@fault = fault
|
75
|
-
|
76
|
-
#puts "\nSalesforceError:\n message='#{message}'\n fault='#{fault}'\n\n"
|
93
|
+
|
77
94
|
logger.debug("\nSalesforceError:\n message='#{message}'\n fault='#{fault}'\n\n")
|
78
95
|
end
|
79
96
|
end
|
80
97
|
|
81
|
-
|
82
|
-
class SalesforceAdapter < AbstractAdapter
|
83
98
|
|
99
|
+
class SalesforceAdapter < AbstractAdapter
|
100
|
+
|
84
101
|
class EntityDefinition
|
85
102
|
attr_reader :name, :columns, :column_name_to_column, :relationships
|
86
103
|
|
@@ -134,10 +151,10 @@ module ActiveRecord
|
|
134
151
|
|
135
152
|
def quote(value, column = nil)
|
136
153
|
case value
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
154
|
+
when NilClass then quoted_value = "'NULL'"
|
155
|
+
when TrueClass then quoted_value = "'TRUE'"
|
156
|
+
when FalseClass then quoted_value = "'FALSE'"
|
157
|
+
else quoted_value = super(value, column)
|
141
158
|
end
|
142
159
|
|
143
160
|
"@V_#{quoted_value}"
|
@@ -176,7 +193,7 @@ module ActiveRecord
|
|
176
193
|
table_name = raw_table_name.singularize
|
177
194
|
entity_name = entity_name_from_table(table_name)
|
178
195
|
entity_def = get_entity_def(entity_name)
|
179
|
-
|
196
|
+
|
180
197
|
column_names = api_column_names(table_name)
|
181
198
|
|
182
199
|
# Always (unless COUNT*)'ing) select all columns (required for the AR attributes mechanism to work correctly
|
@@ -209,7 +226,7 @@ module ActiveRecord
|
|
209
226
|
@batch_size = nil
|
210
227
|
|
211
228
|
queryResult = get_result(@connection.query(:queryString => soql), :query)
|
212
|
-
records = queryResult
|
229
|
+
records = queryResult[:records]
|
213
230
|
|
214
231
|
result = ResultArray.new(queryResult[:size].to_i)
|
215
232
|
return result unless records
|
@@ -264,7 +281,7 @@ module ActiveRecord
|
|
264
281
|
|
265
282
|
# Extract arrays of values
|
266
283
|
values = extract_values(sql)
|
267
|
-
|
284
|
+
|
268
285
|
fields = {}
|
269
286
|
names.each_with_index do | name, n |
|
270
287
|
value = values[n]
|
@@ -289,14 +306,14 @@ module ActiveRecord
|
|
289
306
|
|
290
307
|
names = extract_columns(sql)
|
291
308
|
values = extract_values(sql)
|
292
|
-
|
309
|
+
|
293
310
|
fields = {}
|
294
311
|
names.each_with_index do | name, n |
|
295
312
|
column = columns[name]
|
296
313
|
value = values[n]
|
297
314
|
fields[column.api_name] = value if not column.readonly and value != "NULL"
|
298
315
|
end
|
299
|
-
|
316
|
+
|
300
317
|
id = sql.match(/WHERE id = @V_'(\w+)'/i)[1]
|
301
318
|
|
302
319
|
sobject = create_sobject(entity_name, id, fields)
|
@@ -332,7 +349,7 @@ module ActiveRecord
|
|
332
349
|
result = [ result ] unless result.is_a?(Array)
|
333
350
|
|
334
351
|
result.each do |r|
|
335
|
-
|
352
|
+
raise SalesforceError.new(@logger, r[:errors], r[:errors][:message]) unless r[:success] == "true"
|
336
353
|
end
|
337
354
|
|
338
355
|
result
|
@@ -354,7 +371,7 @@ module ActiveRecord
|
|
354
371
|
metadata = get_result(@connection.describeSObject(:sObjectType => entity_name + "__c"), :describeSObject)
|
355
372
|
custom = true
|
356
373
|
end
|
357
|
-
|
374
|
+
|
358
375
|
metadata.fields.each do |field|
|
359
376
|
column = SalesforceColumn.new(field)
|
360
377
|
cached_columns << column
|
@@ -375,12 +392,12 @@ module ActiveRecord
|
|
375
392
|
end
|
376
393
|
end
|
377
394
|
end
|
378
|
-
|
395
|
+
|
379
396
|
entity_def = EntityDefinition.new(entity_name, cached_columns, cached_relationships, custom)
|
380
397
|
@entity_def_map[entity_name] = entity_def
|
381
398
|
|
382
399
|
configure_active_record entity_def
|
383
|
-
|
400
|
+
|
384
401
|
entity_def
|
385
402
|
end
|
386
403
|
|
@@ -429,7 +446,7 @@ module ActiveRecord
|
|
429
446
|
entity_name = entity_name_from_table(table_name)
|
430
447
|
get_entity_def(entity_name).columns
|
431
448
|
end
|
432
|
-
|
449
|
+
|
433
450
|
|
434
451
|
def columns_map(table_name, name = nil)
|
435
452
|
entity_name = entity_name_from_table(table_name)
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: activesalesforce
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
6
|
+
version: 0.2.2
|
7
7
|
date: 2006-02-06 00:00:00 -05:00
|
8
8
|
summary: ActiveSalesforce is an extension to the Rails Framework that allows for the dynamic creation and management of ActiveRecord objects through the use of Salesforce meta-data and uses a Salesforce.com organization as the backing store.
|
9
9
|
require_paths:
|
@@ -28,7 +28,6 @@ cert_chain:
|
|
28
28
|
authors:
|
29
29
|
- Doug Chasman
|
30
30
|
files:
|
31
|
-
- lib/salesforce_login.rb
|
32
31
|
- lib/column_definition.rb
|
33
32
|
- lib/activesalesforce.rb
|
34
33
|
- lib/rforce.rb
|
data/lib/salesforce_login.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
=begin
|
4
|
-
ActiveSalesforce
|
5
|
-
Copyright (c) 2006 Doug Chasman
|
6
|
-
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
9
|
-
in the Software without restriction, including without limitation the rights
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
12
|
-
furnished to do so, subject to the following conditions:
|
13
|
-
|
14
|
-
The above copyright notice and this permission notice shall be included in
|
15
|
-
all copies or substantial portions of the Software.
|
16
|
-
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
-
SOFTWARE.
|
24
|
-
=end
|
25
|
-
|
26
|
-
require File.dirname(__FILE__) + '/rforce.rb'
|
27
|
-
|
28
|
-
|
29
|
-
class SalesforceLogin
|
30
|
-
attr_reader :proxy
|
31
|
-
|
32
|
-
def initialize(url, username, password)
|
33
|
-
puts "SalesforceLogin.initialize()"
|
34
|
-
|
35
|
-
@proxy = RForce::Binding.new(url)
|
36
|
-
|
37
|
-
login_result = @proxy.login(username, password).result
|
38
|
-
end
|
39
|
-
end
|