espn_pub 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/espn_pub/entities/game.rb +16 -2
- data/lib/espn_pub/entities/league.rb +19 -0
- data/lib/espn_pub/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9825c4b3b3277d1addc0d50c01683144de143366bfb394bccceee46f3b043d2c
|
|
4
|
+
data.tar.gz: 6fc6a99c1285f4523cdd60696e340e868c4a48c49c9e9b7f6a6188fcad9b28e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b7c63799f4d0bdb87601e31a89bbadce8b3ce77dd14ac93dfff521d4a3cd1586b483b0490f86814d29e10093b52839bcb0ea5aec84e11831f794915f3149d316
|
|
7
|
+
data.tar.gz: 23f0d9d8af7f36469fa15734aeea9c02162133f92c48ff67b46737d98eec811c0cac01c4f4b37c465ae1b333f39e5af78007872c3e9b30ead77c5d77669194a4
|
|
@@ -4,7 +4,19 @@ module EspnPub
|
|
|
4
4
|
module Entities
|
|
5
5
|
# Represents a game between two teams.
|
|
6
6
|
class Game < Base
|
|
7
|
-
|
|
7
|
+
module Type
|
|
8
|
+
PRESEASON = 'preseason'
|
|
9
|
+
REGULAR = 'regular'
|
|
10
|
+
POSTSEASON = 'postseason'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
GAME_TYPES = {
|
|
14
|
+
1 => Type::PRESEASON,
|
|
15
|
+
2 => Type::REGULAR,
|
|
16
|
+
3 => Type::POSTSEASON
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
attr_reader :id, :home_team, :away_team, :date, :type
|
|
8
20
|
|
|
9
21
|
# Initialize a Game entity.
|
|
10
22
|
#
|
|
@@ -12,11 +24,13 @@ module EspnPub
|
|
|
12
24
|
# @param home_team [EspnPub::Entities::Team] The home team.
|
|
13
25
|
# @param away_team [EspnPub::Entities::Team] The away team.
|
|
14
26
|
# @param date [DateTime] The scheduled game date.
|
|
15
|
-
|
|
27
|
+
# @param type [String] The type of the game.
|
|
28
|
+
def initialize(id:, home_team:, away_team:, date:, type: nil)
|
|
16
29
|
@id = id
|
|
17
30
|
@home_team = home_team
|
|
18
31
|
@away_team = away_team
|
|
19
32
|
@date = date
|
|
33
|
+
@type = type
|
|
20
34
|
super()
|
|
21
35
|
end
|
|
22
36
|
end
|
|
@@ -22,6 +22,24 @@ module EspnPub
|
|
|
22
22
|
|
|
23
23
|
attr_reader :name
|
|
24
24
|
|
|
25
|
+
def self.fetch_season_details(name, season_year)
|
|
26
|
+
raise ArgumentError, "Unknown league name: #{name}" unless NAME_TO_SPORT.key?(name)
|
|
27
|
+
raise ArgumentError, 'Season year must be an integer' unless season_year.to_i.positive?
|
|
28
|
+
|
|
29
|
+
path = format GAMES_PATH, EspnPub::Client::API_VERSION, NAME_TO_SPORT[name], name
|
|
30
|
+
path += "?dates=#{Time.new(season_year).strftime('%Y%m%d')}"
|
|
31
|
+
resp = EspnPub::Client.new.send_request(path)
|
|
32
|
+
season = resp.dig('leagues', 0, 'season')
|
|
33
|
+
|
|
34
|
+
return {} unless season
|
|
35
|
+
|
|
36
|
+
{
|
|
37
|
+
year: season['year'],
|
|
38
|
+
start_date: Date.parse(season['startDate']),
|
|
39
|
+
end_date: Date.parse(season['endDate'])
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
|
|
25
43
|
# Initialize a League instance.
|
|
26
44
|
#
|
|
27
45
|
# @param name [String] The league identifier string.
|
|
@@ -68,6 +86,7 @@ module EspnPub
|
|
|
68
86
|
(games_resp['events'] || []).map do |game_data|
|
|
69
87
|
EspnPub::Entities::Game.new(
|
|
70
88
|
id: game_data['id'],
|
|
89
|
+
type: Game::GAME_TYPES[game_data.dig('season', 'type')],
|
|
71
90
|
home_team: EspnPub::Entities::Team.fetch_by_id(
|
|
72
91
|
id: game_data.dig('competitions', 0, 'competitors', 0, 'id'),
|
|
73
92
|
sport: sport,
|
data/lib/espn_pub/version.rb
CHANGED