Created
June 27, 2012 12:13
-
-
Save DriesS/3003686 to your computer and use it in GitHub Desktop.
Timeout because other methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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