Class: Fotmob::Client

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

Constant Summary collapse

BASE_URL =
"https://www.fotmob.com/api/data"
DEFAULT_TIMEOUT =
10
DEFAULT_TIMEZONE =
"Europe/Paris"
UA =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 " \
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timeout: DEFAULT_TIMEOUT, timezone: DEFAULT_TIMEZONE) ⇒ Client

Returns a new instance of Client.



18
19
20
21
# File 'lib/fotmob/client.rb', line 18

def initialize(timeout: DEFAULT_TIMEOUT, timezone: DEFAULT_TIMEZONE)
  @timeout = timeout
  @timezone = timezone
end

Instance Attribute Details

#timeoutObject (readonly)

Returns the value of attribute timeout.



16
17
18
# File 'lib/fotmob/client.rb', line 16

def timeout
  @timeout
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



16
17
18
# File 'lib/fotmob/client.rb', line 16

def timezone
  @timezone
end

Instance Method Details

#get_league(league_id) ⇒ Object



23
24
25
# File 'lib/fotmob/client.rb', line 23

def get_league(league_id)
  get("/leagues", id: league_id, tab: "overview")
end

#get_match_details(match_id) ⇒ Object

Returns pageProps with keys: general, header, content (stats, lineup, etc.) Resolves the match slug via a redirect, with automatic buildId refresh on stale deploys.



33
34
35
36
37
38
39
40
41
# File 'lib/fotmob/client.rb', line 33

def get_match_details(match_id)
  @retried_build_id = false
  build_id = fetch_build_id
  slug = fetch_match_slug(match_id, build_id)
  body = fetch_with_timeout(URI("https://www.fotmob.com/_next/data/#{build_id}/matches/#{slug}.json"))
  parse_json(body)[:pageProps]
rescue OpenURI::HTTPError => e
  handle_http_error(e)
end

#get_matches(date) ⇒ Object



27
28
29
# File 'lib/fotmob/client.rb', line 27

def get_matches(date)
  get("/matches", date: date, timezone: @timezone)
end

#get_team(team_id) ⇒ Object



43
44
45
# File 'lib/fotmob/client.rb', line 43

def get_team(team_id)
  get("/teams", id: team_id)
end