lib/soapy_cake/client.rb in soapy_cake-0.2.1 vs lib/soapy_cake/client.rb in soapy_cake-0.2.10
- old
+ new
@@ -82,26 +82,32 @@
end
end
def process_response(method, response)
Time.use_zone('UTC') do
- raise response[:fault][:reason][:text] if response[:fault]
+ raise RequestUnsuccessful, response[:fault][:reason][:text] if response[:fault]
node_name = {
'affiliate_summary' => 'affiliates',
+ 'advertiser_summary' => 'advertisers',
'affiliate_tags' => 'tags',
'offer_summary' => 'offers',
+ 'campaign_summary' => 'campaigns',
+ 'offer_feed' => 'offers',
+ 'export_affiliate_bills' => 'affiliate_bills',
+ 'export_advertiser_bills' => 'advertiser_bills',
}.fetch(method, method)
+
result = response[:"#{method}_response"][:"#{method}_result"]
- raise result[:message] if result[:success] == false
- return result unless result_has_collection?(result)
+ raise RequestUnsuccessful, result[:message] if result[:success] == false
+ return result unless result_has_collection?(result, method)
extract_collection(node_name, result).
map { |hash| remove_prefix(node_name, hash) }
end
end
- def result_has_collection?(result)
- !result.key?(:message)
+ def result_has_collection?(result, method)
+ !result.key?(:message) && !method.to_s.starts_with?('get_')
end
def extract_collection(node_name, response)
node_name = node_name.to_sym
if response.key?(node_name)
@@ -139,7 +145,9 @@
end
def supported?(method)
API_VERSIONS[role][service].keys.include?(method)
end
+
+ class RequestUnsuccessful < RuntimeError; end
end
end