lib/rforce.rb in activesalesforce-0.2.1 vs lib/rforce.rb in activesalesforce-0.2.2
- old
+ new
@@ -118,10 +118,11 @@
end
return elements
end
end
+
#Implements the connection to the SalesForce server.
class Binding
DEFAULT_BATCH_SIZE = 10
attr_accessor :batch_size
@@ -145,21 +146,24 @@
%s
</env:Body>
</env:Envelope>
HERE
+
#Connect to the server securely.
- def initialize(url)
+ def initialize(url, sid = nil)
init_server(url)
- @session_id = ''
+ @session_id = sid
@batch_size = DEFAULT_BATCH_SIZE
end
+
def show_debug
$DEBUG or ENV['SHOWSOAP']
end
+
def init_server(url)
@url = URI.parse(url)
@server = Net::HTTP.new(@url.host, @url.port)
@server.use_ssl = @url.scheme == 'https'
@@ -167,10 +171,11 @@
# run ruby with -d to see SOAP wiredumps.
@server.set_debug_output $stderr if show_debug
end
+
#Log in to the server and remember the session ID
#returned to us by SalesForce.
def login(user, password)
@user = user
@password = password
@@ -184,10 +189,11 @@
init_server(result.serverUrl)
response
end
+
#Call a method on the remote server. Arguments can be
#a hash or (if order is important) an array of alternating
#keys and values.
def call_remote(method, args)
@@ -236,10 +242,11 @@
content = decode(response)
end
SoapResponse.new(content)
end
+
# decode gzip
def decode(response)
encoding = response['Content-Encoding']
@@ -258,10 +265,11 @@
decoded
else
response.body
end
end
+
# encode gzip
def encode(request)
return request if show_debug
@@ -273,17 +281,19 @@
ensure
gzw.close
end
end
+
#Turns method calls on this object into remote SOAP calls.
def method_missing(method, *args)
unless args.size == 1 && [Hash, Array].include?(args[0].class)
raise 'Expected 1 Hash or Array argument'
end
call_remote method, args[0]
end
+
#Expand Ruby data structures into XML.
def expand(args, xmlns = nil)
#Nest arrays: [:a, 1, :b, 2] => [[:a, 1], [:b, 2]]
if (args.class == Array)