Created
May 23, 2011 12:41
-
-
Save pedrobrasileiro/986632 to your computer and use it in GitHub Desktop.
Savon
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
# -*- coding: utf-8 -*- | |
Savon::Client.class_eval do | |
# Retorna nil caso não consiga comunicação | |
def get_hash_body method, params={} | |
begin | |
retorno = nil | |
resp = "#{method.to_s}_response".to_sym | |
ret = "#{method.to_s}_return".to_sym | |
unless params.empty? | |
retorno = self.request method do | |
soap.body = params | |
end | |
else | |
retorno = self.request method | |
end | |
retorno[resp][ret][ret].map do |r| | |
begin | |
r[ret] | |
rescue Exception=>e | |
r[1].include?("soapenc") ? nil : r[1] # Workaround para quando o WS manda um array vazio... | |
end | |
end.compact | |
rescue Exception=>ex | |
raise ex | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment