Class: Sportradar::Api::Request
- Inherits:
-
Object
- Object
- Sportradar::Api::Request
- Includes:
- HTTParty
- Defined in:
- lib/sportradar/api/request.rb
Direct Known Subclasses
Baseball::Mlb::Api, Basketball::Nba::Api, Basketball::Ncaamb::Api, Content, Football::Ncaafb::Api, Football::Nfl::Api, Images, LiveImages, Mma::Api, Odds::Api, Soccer::Api
Instance Attribute Summary collapse
-
#qps_allotted ⇒ Object
readonly
Returns the value of attribute qps_allotted.
-
#qps_current ⇒ Object
readonly
Returns the value of attribute qps_current.
-
#quota_allotted ⇒ Object
readonly
Returns the value of attribute quota_allotted.
-
#quota_current ⇒ Object
readonly
Returns the value of attribute quota_current.
Instance Method Summary collapse
- #get(path, options = {}) ⇒ Object
- #get_data(url, extra_params = {}) ⇒ Object
- #get_request_info(url) ⇒ Object
- #parse_usage(headers) ⇒ Object
-
#sim! ⇒ Object
attr_reader :url, :headers, :timeout, :api_key.
- #usage ⇒ Object
Instance Attribute Details
#qps_allotted ⇒ Object (readonly)
Returns the value of attribute qps_allotted.
4 5 6 |
# File 'lib/sportradar/api/request.rb', line 4 def qps_allotted @qps_allotted end |
#qps_current ⇒ Object (readonly)
Returns the value of attribute qps_current.
4 5 6 |
# File 'lib/sportradar/api/request.rb', line 4 def qps_current @qps_current end |
#quota_allotted ⇒ Object (readonly)
Returns the value of attribute quota_allotted.
4 5 6 |
# File 'lib/sportradar/api/request.rb', line 4 def quota_allotted @quota_allotted end |
#quota_current ⇒ Object (readonly)
Returns the value of attribute quota_current.
4 5 6 |
# File 'lib/sportradar/api/request.rb', line 4 def quota_current @quota_current end |
Instance Method Details
#get(path, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sportradar/api/request.rb', line 43 def get(path, ={}) url, headers, , timeout = base_setup(path, ) begin # puts url + "?api_key=#{api_key[:api_key]}" # uncomment for debugging response = self.class.get(url, headers: headers, query: , timeout: timeout) rescue Net::ReadTimeout, Net::OpenTimeout raise Sportradar::Api::Error::Timeout rescue EOFError raise Sportradar::Api::Error::NoData end unless response.success? puts url + "?api_key=#{api_key[:api_key]}" # uncomment for debugging puts puts response.inspect Sportradar::Api::Error.new(response.code, response., response) else File.write("response.json", JSON.pretty_generate(response.to_h)) if ENV['SPORTRADAR_LOG'] response end end |
#get_data(url, extra_params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sportradar/api/request.rb', line 15 def get_data(url, extra_params = {}) data = get(request_url(url), extra_params) if data.is_a?(::Sportradar::Api::Error) puts request_url(url) puts puts data.inspect raise data end parse_usage(data.headers) data end |
#get_request_info(url) ⇒ Object
64 65 66 |
# File 'lib/sportradar/api/request.rb', line 64 def get_request_info(url) base_setup(request_url(url)) end |
#parse_usage(headers) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/sportradar/api/request.rb', line 36 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 |
#sim! ⇒ Object
attr_reader :url, :headers, :timeout, :api_key
10 11 12 13 |
# File 'lib/sportradar/api/request.rb', line 10 def sim! @access_level = 'sim' self end |
#usage ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/sportradar/api/request.rb', line 27 def usage { qps_allotted: @qps_allotted, qps_current: @qps_current, quota_allotted: @quota_allotted, quota_current: @quota_current, } end |