Class: Exchange::ExternalAPI::Call
- Defined in:
- lib/exchange/external_api/call.rb
Overview
A class to handle API calls in a standardized way for all APIs
Instance Attribute Summary
Attributes inherited from Base
#base, #cache, #helper, #rates, #timestamp
Instance Method Summary collapse
-
#initialize(url, options = {}) {|Nokogiri::XML, Hash| ... } ⇒ Nokogiri::XML, Hash
constructor
Initialization of the Call class is the call itself.
Methods inherited from Base
#convert, #rate, #test_for_rates_and_raise_if_nil, #to_hash!
Constructor Details
#initialize(url, options = {}) {|Nokogiri::XML, Hash| ... } ⇒ Nokogiri::XML, Hash
Initialization of the Call class is the call itself. This means that every instance of the class will only exist during the call
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/exchange/external_api/call.rb', line 34 def initialize url, ={}, &block Exchange::GemLoader.new([:format] == :xml ? 'nokogiri' : 'json').try_load result = cache_config.subclass.cached([:api] || config.subclass, ) do load_url(url, [:retries] || config.retries, [:retry_with]) end parsed = [:format] == :xml ? Nokogiri::XML.parse(result.sub("\n", '')) : ::JSON.load(result) return parsed unless block_given? yield parsed end |