class FootballApi::BaseRequest
Constants
- RETRIES
How many times should we retry the request if Timeout::Error is raised?
Public Class Methods
action_query(options = {})
click to toggle source
# File lib/football_api/base_request.rb, line 63 def action_query(options = {}) { query: { "Action" => action }.merge(options) }.tap do |hs| hs[:query].merge!(get_parameters) if params_method end end
get!(options = {}, &block)
click to toggle source
The generic get method for all requests. Uses httparty get and makes no assumptions about the response, simply returns it
# File lib/football_api/base_request.rb, line 37 def get!(options = {}, &block) attempts ||= RETRIES query = action_query(options) get("/api/", query, &block) rescue Timeout::Error => e puts "Timeout! Retrying... (#{RETRIES - attempts})" retry if (attempts -= 1) > 0 raise FootballApi::RequestError.new('Request timeout') end
Also aliased as: request!
get_parameters()
click to toggle source
# File lib/football_api/base_request.rb, line 69 def get_parameters send(params_method) end
response(options = {})
click to toggle source
This is an handy method for response parsing. Subclasses that include Requestable
can simply use the json_key option and response will only contain that field. It also deep symbolizes the response keys
# File lib/football_api/base_request.rb, line 56 def response(options = {}) data = get!(options) || Hash.new data = custom_deep_symbolic_hash(data) data.present? ? data[json_id] : data end