lib/rforce/binding.rb in rforce-0.7 vs lib/rforce/binding.rb in rforce-0.8
- old
+ new
@@ -22,11 +22,11 @@
Envelope = <<-HERE
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:partner="urn:partner.soap.sforce.com">
+ xmlns:partner="urn:partner.soap.sforce.com"
xmlns:spartner="urn:sobject.partner.soap.sforce.com">
<soap:Header>
<partner:SessionHeader soap:mustUnderstand='1'>
<partner:sessionId>%s</partner:sessionId>
</partner:SessionHeader>
@@ -47,13 +47,17 @@
ClientIdHeader = '<partner:CallOptions soap:mustUnderstand="1"><partner:client>%s</partner:client></partner:CallOptions>'
# Connect to the server securely. If you pass an oauth hash, it
# must contain the keys :consumer_key, :consumer_secret,
# :access_token, :access_secret, and :login_url.
- def initialize(url, sid = nil, oauth = nil)
+ #
+ # proxy may be a URL of the form http://user:pass@example.com:port
+ #
+ def initialize(url, sid = nil, oauth = nil, proxy = nil)
@session_id = sid
@oauth = oauth
+ @proxy = proxy
@batch_size = DEFAULT_BATCH_SIZE
init_server(url)
end
@@ -68,11 +72,14 @@
if (@oauth)
consumer = OAuth::Consumer.new \
@oauth[:consumer_key],
@oauth[:consumer_secret],
- { :site => url }
+ {
+ :site => url,
+ :proxy => @proxy
+ }
consumer.http.set_debug_output $stderr if show_debug
@server = OAuth::AccessToken.new \
consumer,
@@ -81,30 +88,35 @@
class << @server
alias_method :post2, :post
end
else
- @server = Net::HTTP.new(@url.host, @url.port)
+ @server = Net::HTTP.Proxy(@proxy).new(@url.host, @url.port)
@server.use_ssl = @url.scheme == 'https'
@server.verify_mode = OpenSSL::SSL::VERIFY_NONE
# run ruby with -d or env variable SHOWSOAP=true to see SOAP wiredumps.
@server.set_debug_output $stderr if show_debug
end
end
+ # Connect to remote server
+ #
+ def connect(user, password)
+ @user = user
+ @password = password
+ call_remote(:login, [:username, user, :password, password])
+ end
+
# Log in to the server with a user name and password, remembering
# the session ID returned to us by Salesforce.
def login(user, password)
- @user = user
- @password = password
+ response = connect(user, password)
- response = call_remote(:login, [:username, user, :password, password])
+ raise "Incorrect user name / password [#{response.Fault}]" unless response.loginResponse
- raise "Incorrect user name / password [#{response.fault}]" unless response.loginResponse
-
result = response[:loginResponse][:result]
@session_id = result[:sessionId]
init_server(result[:serverUrl])
@@ -246,13 +258,13 @@
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'
+ unless args.empty? || (args.size == 1 && [Hash, Array].include?(args[0].class))
+ raise 'Expected at most 1 Hash or Array argument'
end
- call_remote method, args[0]
+ call_remote method, args[0] || []
end
end
end