lib/sportradar/api/request.rb in sportradar-api-0.12.3 vs lib/sportradar/api/request.rb in sportradar-api-0.13.0

- old
+ new

@@ -1,8 +1,9 @@ module Sportradar module Api class Request + attr_reader :qps_allotted, :qps_current, :quota_allotted, :quota_current include HTTParty # attr_reader :url, :headers, :timeout, :api_key @@ -15,15 +16,32 @@ data = get request_url(url) if data.is_a?(::Sportradar::Api::Error) puts request_url(url) puts puts data.inspect - raise 'Sportradar error' + raise data end + parse_usage(data.headers) data end + def usage + { + qps_allotted: @qps_allotted, + qps_current: @qps_current, + quota_allotted: @quota_allotted, + quota_current: @quota_current, + } + end + + def parse_usage(headers) + @qps_allotted = (headers['x-plan-qps-allotted'] || headers['x-packagekey-qps-allotted']).to_i + @qps_current = (headers['x-plan-qps-current'] || headers['x-packagekey-qps-current']).to_i + @quota_allotted = (headers['x-plan-quota-allotted'] || headers['x-packagekey-quota-allotted']).to_i + @quota_current = (headers['x-plan-quota-current'] || headers['x-packagekey-quota-current']).to_i + end + def get(path, options={}) url, headers, options, timeout = base_setup(path, options) begin # puts url + "?api_key=#{api_key[:api_key]}" # uncomment for debugging response = self.class.get(url, headers: headers, query: options, timeout: timeout) @@ -60,9 +78,12 @@ protocol = !!Sportradar::Api.config.use_ssl ? "https://" : "http://" url = "#{protocol}api.sportradar.us" url += path end + def default_date + Date.today + end def date_path(date) "#{date.year}/#{date.month}/#{date.day}" end