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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de842b344e37f8c369d3017ef9e18e8389bc1308d0a09f6b599788972e303355
4
- data.tar.gz: ebe944144b60bf498123efa73e71b21a6b1b4b808b8aa5c5e4c00afe79d03ac8
3
+ metadata.gz: 9825c4b3b3277d1addc0d50c01683144de143366bfb394bccceee46f3b043d2c
4
+ data.tar.gz: 6fc6a99c1285f4523cdd60696e340e868c4a48c49c9e9b7f6a6188fcad9b28e6
5
5
  SHA512:
6
- metadata.gz: 9d078d642a8a0e1c11722a31d8785dba6076d36622d29f032f6e80f9df522c6c95f711df35b03b87494e56f5d450198aec0d17f5fe1db5ccf76b2c383451743c
7
- data.tar.gz: 6b2b73144fa2b7345c0e534929926aa92ea6c5762fcf4d1d69479fad809dc9f29bef963503353fd82295bccef66a249eef704f7625f25c3a8b1ac5b5bb0bc0f4
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
- attr_reader :id, :home_team, :away_team, :date
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
- def initialize(id:, home_team:, away_team:, date:)
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,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EspnPub
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: espn_pub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Bowman