Class: ApiSports::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/api_sports/client.rb

Constant Summary collapse

BASE_URL =
"https://v3.football.api-sports.io/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
# File 'lib/api_sports/client.rb', line 9

def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
  @api_key = api_key
  @adapter = adapter

  # Test stubs for requests
  @stubs = stubs
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/api_sports/client.rb', line 7

def adapter
  @adapter
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/api_sports/client.rb', line 7

def api_key
  @api_key
end

Instance Method Details

#connectionObject



57
58
59
60
61
62
63
# File 'lib/api_sports/client.rb', line 57

def connection
  @connection ||= Faraday.new(BASE_URL) do |conn|
    conn.headers = { "x-apisports-key": api_key }
    conn.response :json, content_type: "application/json"
    conn.adapter adapter, @stubs
  end
end

#countriesObject



17
18
19
# File 'lib/api_sports/client.rb', line 17

def countries
  CountriesResource.new(self)
end

#fixturesObject



45
46
47
# File 'lib/api_sports/client.rb', line 45

def fixtures
  FixturesResource.new(self)
end

#leaguesObject



25
26
27
# File 'lib/api_sports/client.rb', line 25

def leagues
  LeaguesResource.new(self)
end

#oddsObject



53
54
55
# File 'lib/api_sports/client.rb', line 53

def odds
  OddsResource.new(self)
end

#predictionsObject



49
50
51
# File 'lib/api_sports/client.rb', line 49

def predictions
  PredictionsResource.new(self)
end

#seasonsObject



29
30
31
# File 'lib/api_sports/client.rb', line 29

def seasons
  SeasonsResource.new(self)
end

#standingsObject



41
42
43
# File 'lib/api_sports/client.rb', line 41

def standings
  StandingsResource.new(self)
end

#teamsObject



33
34
35
# File 'lib/api_sports/client.rb', line 33

def teams
  TeamsResource.new(self)
end

#timezonesObject



21
22
23
# File 'lib/api_sports/client.rb', line 21

def timezones
  TimezonesResource.new(self)
end

#venuesObject



37
38
39
# File 'lib/api_sports/client.rb', line 37

def venues
  VenuesResource.new(self)
end