lib/rforce.rb in activesalesforce-0.0.8 vs lib/rforce.rb in activesalesforce-0.0.9

- old
+ new

@@ -162,13 +162,16 @@ @server.set_debug_output $stderr if $DEBUG end #Log in to the server and remember the session ID #returned to us by SalesForce. - def login(user, pass) - response = call_remote(:login, [:username, user, :password, pass]) + def login(user, password) + @user = user + @password = password + response = call_remote(:login, [:username, user, :password, password]) + raise "Incorrect user name / password [#{response.fault}]" unless response.loginResponse result = response.loginResponse.result @session_id = result.sessionId @@ -193,9 +196,20 @@ # reset the batch size for the next request @batch_size = DEFAULT_BATCH_SIZE #Send the request to the server and read the response. response = @server.post2(@url.path, request, {'SOAPAction' => method.to_s, 'content-type' => 'text/xml'}) + + # Check to see if INVALID_SESSION_ID was raised and try to relogin in + if method != :login and @session_id and response =~ /<faultcode>sf\:INVALID_SESSION_ID<\/faultcode>/ + puts "\n\nSession timeout error - auto relogin activated" + + login(@user, @password) + + #Send the request to the server and read the response. + response = @server.post2(@url.path, request, {'SOAPAction' => method.to_s, 'content-type' => 'text/xml'}) + end + SoapResponse.new(response.body) end #Turns method calls on this object into remote SOAP calls. def method_missing(method, *args)