module KfcApi
Public Instance Methods
Source
# File lib/kfc_api.rb, line 27 def default_headers { "Accept" => "application/json" } end
Source
# File lib/kfc_api.rb, line 14 def fetch_json(url, fetch: nil) body = if fetch fetch.call(url, headers: default_headers) else live_fetch(url) end JSON.parse(body) end
Source
# File lib/kfc_api.rb, line 31 def fetch_stores(location, fetch: nil, max_attempts: KfcFetch::DEFAULT_MAX_ATTEMPTS, sleep_fn: nil) KfcLocation.location_search_queries(location).each do |query| stores = fetch_stores_for_query( query, fetch: fetch, max_attempts: max_attempts, sleep_fn: sleep_fn ) return stores unless stores.empty? end [] end
Source
# File lib/kfc_api.rb, line 45 def fetch_stores_for_query(query, fetch: nil, max_attempts: KfcFetch::DEFAULT_MAX_ATTEMPTS, sleep_fn: nil) url = KfcConfig.stores_url(query) payload = KfcFetch.with_retry(max_attempts: max_attempts, sleep_fn: sleep_fn) do fetch_json(url, fetch: fetch) end KfcStores.parse_stores(payload) rescue StandardError [] end
Source
# File lib/kfc_api.rb, line 23 def live_fetch(url) RabbotHttp.fetch(url, user_agent: KfcConfig::USER_AGENT) end