Skip to content

Instantly share code, notes, and snippets.

@DriesS
Created June 27, 2012 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DriesS/3003686 to your computer and use it in GitHub Desktop.
Save DriesS/3003686 to your computer and use it in GitHub Desktop.
Timeout because other methods
module SoColissimo
class Client
def self.execute(action, body, order)
client.http.read_timeout = 2
client.http.open_timeout = 2
tries = 0
begin
body[:order!] = order.unshift(:accountNumber, :password)
response = client.request :poin, action do
soap.body = body.merge(login)
end
response_return = response.to_hash[:"#{action.underscore.to_sym}_#{"response"}"][:return]
raise SoColissimo::Error.new(response_return[:error_code], response_return[:error_message]) if response_return[:error_code] != "0"
return response_return
rescue Timeout::Error, Errno::ECONNREFUSED
tries += 1
puts "Trying again execute!"
retry if tries <= 2
end
end
protected
def self.client
Savon::Client.new do
wsdl.namespace = "http://pointretrait.geopost.com/"
wsdl.endpoint = "http://ws.colissimo.fr/pointretrait-ws-cxf/PointRetraitServiceWS"
wsdl.element_form_default = :unqualified
end
end
def self.login
{:accountNumber => SoColissimo.config[:username], :password => SoColissimo.config[:password]}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment