Skip to content

Instantly share code, notes, and snippets.

@pedrobrasileiro
Created May 23, 2011 12:41
Show Gist options
  • Save pedrobrasileiro/986632 to your computer and use it in GitHub Desktop.
Save pedrobrasileiro/986632 to your computer and use it in GitHub Desktop.
Savon
# -*- 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