lib/soapy_cake/client.rb in soapy_cake-0.2.10 vs lib/soapy_cake/client.rb in soapy_cake-0.2.11

- old
+ new

@@ -1,7 +1,8 @@ require 'sekken' require 'active_support/core_ext/time/zones' +require 'local_copy' module SoapyCake class Client attr_reader :service, :api_key, :domain, :role @@ -12,21 +13,21 @@ @domain = opts.fetch(:domain) do if ENV['CAKE_DOMAIN'].present? ENV['CAKE_DOMAIN'] else - raise 'We need a domain' + fail 'We need a domain' end end @api_key = opts.fetch(:api_key) do if opts[:username] && opts[:password] get_api_key(opts[:username], opts[:password]) elsif ENV['CAKE_API_KEY'] ENV['CAKE_API_KEY'] else - raise 'We need an API key here!' + fail 'We need an API key here!' end end end def self.method_missing(method, opts = {}) @@ -36,12 +37,13 @@ def sekken_client(method) self.class.sekken_client(wsdl_url(version(method))) end def self.sekken_client(url) + path = LocalCopy.fetch(url) @sekken_clients ||= {} - @sekken_clients[url] ||= Sekken.new(url) + @sekken_clients[url] ||= Sekken.new(path) end def method_missing(method, opts = {}) if supported?(method) method = method.to_s @@ -82,11 +84,11 @@ end end def process_response(method, response) Time.use_zone('UTC') do - raise RequestUnsuccessful, response[:fault][:reason][:text] if response[:fault] + fail RequestUnsuccessful, response[:fault][:reason][:text] if response[:fault] node_name = { 'affiliate_summary' => 'affiliates', 'advertiser_summary' => 'advertisers', 'affiliate_tags' => 'tags', 'offer_summary' => 'offers', @@ -95,13 +97,13 @@ 'export_affiliate_bills' => 'affiliate_bills', 'export_advertiser_bills' => 'advertiser_bills', }.fetch(method, method) result = response[:"#{method}_response"][:"#{method}_result"] - raise RequestUnsuccessful, result[:message] if result[:success] == false + fail 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) } + extract_collection(node_name, result) + .map { |hash| remove_prefix(node_name, hash) } end end def result_has_collection?(result, method) !result.key?(:message) && !method.to_s.starts_with?('get_')