Class: SportsOddsAPI::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- SportsOddsAPI::Client
- Defined in:
- lib/sports_odds_api/client.rb,
sig/sports_odds_api/client.rbs
Constant Summary collapse
- DEFAULT_MAX_RETRIES =
Default max number of retries to attempt after a failed retryable request.
2- DEFAULT_TIMEOUT_IN_SECONDS =
Default per-request timeout.
60.0- DEFAULT_INITIAL_RETRY_DELAY =
Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.
0.5- DEFAULT_MAX_RETRY_DELAY =
Default max retry delay in seconds.
8.0
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS, Internal::Transport::BaseClient::SportsOddsAPI
Instance Attribute Summary collapse
-
#account ⇒ SportsOddsAPI::Resources::Account
readonly
Get data related to your Account & API key.
-
#api_key_header ⇒ String?
readonly
API key via header.
-
#api_key_param ⇒ String?
readonly
API key via query param.
-
#events ⇒ SportsOddsAPI::Resources::Events
readonly
Get info about Events (includes odds, results, teams, and other metadata).
-
#leagues ⇒ SportsOddsAPI::Resources::Leagues
readonly
Get League-related data.
-
#markets ⇒ SportsOddsAPI::Resources::Markets
readonly
Get metadata on supported Markets.
-
#players ⇒ SportsOddsAPI::Resources::Players
readonly
Get Player-related data.
-
#sports ⇒ SportsOddsAPI::Resources::Sports
readonly
Get Sport-related data.
-
#stats ⇒ SportsOddsAPI::Resources::Stats
readonly
Get data on specific Stats.
-
#stream ⇒ SportsOddsAPI::Resources::Stream
readonly
Get info about Events (includes odds, results, teams, and other metadata).
-
#teams ⇒ SportsOddsAPI::Resources::Teams
readonly
Get Team-related data.
Attributes inherited from Internal::Transport::BaseClient
#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout
Instance Method Summary collapse
-
#initialize(api_key_header: ENV["SPORTS_ODDS_API_KEY_HEADER"], api_key_param: ENV["SPORTS_ODDS_API_KEY_HEADER"], base_url: ENV["SPORTS_GAME_ODDS_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client
constructor
Creates and returns a new client for interacting with the API.
Methods inherited from Internal::Transport::BaseClient
follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!
Methods included from Internal::Util::SorbetRuntimeSupport
#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type
Constructor Details
#initialize(api_key_header: ENV["SPORTS_ODDS_API_KEY_HEADER"], api_key_param: ENV["SPORTS_ODDS_API_KEY_HEADER"], base_url: ENV["SPORTS_GAME_ODDS_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY) ⇒ Client
Creates and returns a new client for interacting with the API.
"https://api.example.com/v2/". Defaults to ENV["SPORTS_GAME_ODDS_BASE_URL"]
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/sports_odds_api/client.rb', line 92 def initialize( api_key_header: ENV["SPORTS_ODDS_API_KEY_HEADER"], api_key_param: ENV["SPORTS_ODDS_API_KEY_HEADER"], base_url: ENV["SPORTS_GAME_ODDS_BASE_URL"], max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY ) base_url ||= "https://api.sportsgameodds.com/v2" headers = {} custom_headers_env = ENV["SPORTS_GAME_ODDS_CUSTOM_HEADERS"] unless custom_headers_env.nil? parsed = {} custom_headers_env.split("\n").each do |line| colon = line.index(":") unless colon.nil? parsed[line[0...colon].strip] = line[(colon + 1)..].strip end end headers = parsed.merge(headers) end @api_key_header = api_key_header&.to_s @api_key_param = api_key_param&.to_s super( base_url: base_url, timeout: timeout, max_retries: max_retries, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, headers: headers ) @events = SportsOddsAPI::Resources::Events.new(client: self) @markets = SportsOddsAPI::Resources::Markets.new(client: self) @teams = SportsOddsAPI::Resources::Teams.new(client: self) @players = SportsOddsAPI::Resources::Players.new(client: self) @leagues = SportsOddsAPI::Resources::Leagues.new(client: self) @sports = SportsOddsAPI::Resources::Sports.new(client: self) @stats = SportsOddsAPI::Resources::Stats.new(client: self) @account = SportsOddsAPI::Resources::Account.new(client: self) @stream = SportsOddsAPI::Resources::Stream.new(client: self) end |
Instance Attribute Details
#account ⇒ SportsOddsAPI::Resources::Account (readonly)
Get data related to your Account & API key
56 57 58 |
# File 'lib/sports_odds_api/client.rb', line 56 def account @account end |
#api_key_header ⇒ String? (readonly)
API key via header
20 21 22 |
# File 'lib/sports_odds_api/client.rb', line 20 def api_key_header @api_key_header end |
#api_key_param ⇒ String? (readonly)
API key via query param
24 25 26 |
# File 'lib/sports_odds_api/client.rb', line 24 def api_key_param @api_key_param end |
#events ⇒ SportsOddsAPI::Resources::Events (readonly)
Get info about Events (includes odds, results, teams, and other metadata)
28 29 30 |
# File 'lib/sports_odds_api/client.rb', line 28 def events @events end |
#leagues ⇒ SportsOddsAPI::Resources::Leagues (readonly)
Get League-related data
44 45 46 |
# File 'lib/sports_odds_api/client.rb', line 44 def leagues @leagues end |
#markets ⇒ SportsOddsAPI::Resources::Markets (readonly)
Get metadata on supported Markets
32 33 34 |
# File 'lib/sports_odds_api/client.rb', line 32 def markets @markets end |
#players ⇒ SportsOddsAPI::Resources::Players (readonly)
Get Player-related data
40 41 42 |
# File 'lib/sports_odds_api/client.rb', line 40 def players @players end |
#sports ⇒ SportsOddsAPI::Resources::Sports (readonly)
Get Sport-related data
48 49 50 |
# File 'lib/sports_odds_api/client.rb', line 48 def sports @sports end |
#stats ⇒ SportsOddsAPI::Resources::Stats (readonly)
Get data on specific Stats
52 53 54 |
# File 'lib/sports_odds_api/client.rb', line 52 def stats @stats end |
#stream ⇒ SportsOddsAPI::Resources::Stream (readonly)
Get info about Events (includes odds, results, teams, and other metadata)
60 61 62 |
# File 'lib/sports_odds_api/client.rb', line 60 def stream @stream end |
#teams ⇒ SportsOddsAPI::Resources::Teams (readonly)
Get Team-related data
36 37 38 |
# File 'lib/sports_odds_api/client.rb', line 36 def teams @teams end |