49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/asf_adapter.rb', line 49
def self.activesalesforce_connection(config) debug("\nUsing ActiveSalesforce connection\n")
url = config[:url]
url = "https://www.salesforce.com" unless url
uri = URI.parse(url)
uri.path = "/services/Soap/u/8.0"
url = uri.to_s
sid = config[:sid]
client_id = config[:client_id]
username = config[:username].to_s
password = config[:password].to_s
recording_source = config[:recording_source]
recording = config[:recording]
if recording_source
recording_source = File.open(recording_source, recording ? "w" : "r")
binding = ActiveSalesforce::RecordingBinding.new(url, nil, recording != nil, recording_source, logger)
binding.client_id = client_id if client_id
binding.login(username, password) unless sid
end
raise ActiveSalesforce::ASFError.new(logger, "Invalid salesforce server url '#{url}', must be a valid Parter API URL") unless url.match(/\/u\//mi)
if sid
binding = @@cache["sid=#{sid}"] unless binding
unless binding
debug("Establishing new connection for [sid='#{sid}']")
binding = RForce::Binding.new(url, sid)
@@cache["sid=#{sid}"] = binding
debug("Created new connection for [sid='#{sid}']")
else
debug("Reused existing connection for [sid='#{sid}']")
end
else
binding = @@cache["#{url}.#{username}.#{password}.#{client_id}"] unless binding
unless binding
debug("Establishing new connection for ['#{url}', '#{username}, '#{client_id}'")
seconds = Benchmark.realtime {
binding = RForce::Binding.new(url, sid)
binding.login(username, password)
@@cache["#{url}.#{username}.#{password}.#{client_id}"] = binding
}
debug("Created new connection for ['#{url}', '#{username}', '#{client_id}'] in #{seconds} seconds")
end
end
ConnectionAdapters::SalesforceAdapter.new(binding, logger, config)
end
|