mlb_rb 0.0.1 → 0.0.2

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: 310accad978cc9d84cd83bb5239980ab8e6a131a3b961b18031982d63701dbec
4
- data.tar.gz: ae4db5eb92b6ce49cb5276b3b54c1389909dafa66dad6f10e2229133c9e2090d
3
+ metadata.gz: 93a32c08203af72a90434508faa6a3f9eed11818bd85d5b4d58f02900603bd52
4
+ data.tar.gz: 7c5018622dcbbf59b427406a9989a6abd260b03ebd8805168e9e3aa7e9111f37
5
5
  SHA512:
6
- metadata.gz: 0d3ec6aafac47c26fcd80786ee478ce794779cd23e1c32ee1040a1db4a2f5eac6e6e78fbf5f807a67966c2605e39e2de7fe5bed07e8c42e7f08eaf9d47b392af
7
- data.tar.gz: eb3f00d63cbb92db50d81ab03248890093a466e7f06b10c4efcd1a989ae6ea5c25f488d9fc5de6d4092ec3ed708d4c1192af121da97899f50aa8e06857c80b6d
6
+ metadata.gz: ebefd20383b5e2c9306c4df86f4fd614b1f2b9beb25c4d9fc2dff08552908b6ee1c8f601cf66fa981fbedbb2b6c66a62ddecd51abcab70ba6d4ba9a28ed32a32
7
+ data.tar.gz: 23e4e550d72fd47a17ec28e0a2c4a70f8ec507bb5f5b12c936e0f2dca20aac45fdaaa3451561d0fdcae5717b15a89b19446b2b1d1db946bb4eef7e1591795f87
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.0.1] - 2022-03-25
4
+
5
+ - Add endpoint to retrieve games for one date
3
6
  ## [0.0.1] - 2022-03-24
4
7
 
5
8
  - Add healthcheck that returns a string
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mlb_rb (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ parallel (1.22.0)
12
+ parser (3.1.1.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.1.1)
15
+ rake (13.0.6)
16
+ regexp_parser (2.2.1)
17
+ rexml (3.2.5)
18
+ rspec (3.11.0)
19
+ rspec-core (~> 3.11.0)
20
+ rspec-expectations (~> 3.11.0)
21
+ rspec-mocks (~> 3.11.0)
22
+ rspec-core (3.11.0)
23
+ rspec-support (~> 3.11.0)
24
+ rspec-expectations (3.11.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.11.0)
27
+ rspec-mocks (3.11.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-support (3.11.0)
31
+ rubocop (1.26.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.1.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.16.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.16.0)
41
+ parser (>= 3.1.1.0)
42
+ rubocop-performance (1.13.3)
43
+ rubocop (>= 1.7.0, < 2.0)
44
+ rubocop-ast (>= 0.4.0)
45
+ ruby-progressbar (1.11.0)
46
+ standard (1.9.0)
47
+ rubocop (= 1.26.0)
48
+ rubocop-performance (= 1.13.3)
49
+ unicode-display_width (2.1.0)
50
+
51
+ PLATFORMS
52
+ x86_64-darwin-20
53
+
54
+ DEPENDENCIES
55
+ mlb_rb!
56
+ rake (~> 13.0)
57
+ rspec (~> 3.0)
58
+ standard (~> 1.3)
59
+
60
+ BUNDLED WITH
61
+ 2.3.1
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+
5
+ module MlbRb
6
+ class Client
7
+ def self.get_games_for_date(date)
8
+ Net::HTTP.get("statsapi.mlb.com", "/api/v1/schedule/games/?sportId=1&date=#{date}")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "./lib/mlb_rb/team"
4
+ require "date"
5
+
6
+ module MlbRb
7
+ class Game
8
+ attr_reader :game_pk,
9
+ :home_team,
10
+ :away_team,
11
+ :home_score,
12
+ :away_score,
13
+ :game_date
14
+
15
+ def initialize(game_hash)
16
+ @game_pk = game_hash["gamePk"]
17
+ @home_team = Team.new(game_hash["teams"]["home"]["team"])
18
+ @away_team = Team.new(game_hash["teams"]["away"]["team"])
19
+ @home_score = game_hash["teams"]["home"]["score"]
20
+ @away_score = game_hash["teams"]["away"]["score"]
21
+ @game_date = Date.parse(game_hash["gameDate"])
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MlbRb
4
+ class Team
5
+ attr_reader :id, :name
6
+ def initialize(team_hash)
7
+ @id = team_hash["id"]
8
+ @name = team_hash["name"]
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MlbRb
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
data/lib/mlb_rb.rb CHANGED
@@ -1,11 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "mlb_rb/version"
3
+ require "./lib/mlb_rb/version"
4
+ require "./lib/mlb_rb/client"
5
+ require "./lib/mlb_rb/game"
6
+ require "json"
4
7
 
5
8
  module MlbRb
6
9
  class Error < StandardError; end
7
10
 
8
- def self.healthcheck
9
- "Yup, everything is fine"
11
+ class DateError < StandardError; end
12
+
13
+ class << self
14
+ def healthcheck
15
+ "Yup, everything is fine"
16
+ end
17
+
18
+ def games_for_date(options)
19
+ date = options[:date]
20
+ raise DateError unless validate_date(date)
21
+
22
+ formatted_date = "#{"%02d" % date[:month]}/#{"%02d" % date[:day]}/#{date[:year]}"
23
+ games_json = client.get_games_for_date(formatted_date)
24
+ games = JSON.parse(games_json)["dates"].first["games"]
25
+ games.map { |game| Game.new(game) }
26
+ end
27
+
28
+ private
29
+
30
+ def validate_date(date)
31
+ return unless date
32
+
33
+ date.map do |key, value|
34
+ valid_number_for_date(value, key)
35
+ end.all?
36
+ end
37
+
38
+ def valid_number_for_date(date_number, type)
39
+ if type == :year
40
+ date_number.between?(1876, Date.today.year)
41
+ elsif type == :month
42
+ date_number.between?(1, 12)
43
+ elsif type == :day
44
+ date_number.between?(1, 31)
45
+ end
46
+ end
47
+
48
+ def client
49
+ MlbRb::Client
50
+ end
10
51
  end
11
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlb_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Miranda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-24 00:00:00.000000000 Z
11
+ date: 2022-03-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -22,12 +22,16 @@ files:
22
22
  - CHANGELOG.md
23
23
  - CODE_OF_CONDUCT.md
24
24
  - Gemfile
25
+ - Gemfile.lock
25
26
  - LICENSE.txt
26
27
  - README.md
27
28
  - Rakefile
28
29
  - bin/console
29
30
  - bin/setup
30
31
  - lib/mlb_rb.rb
32
+ - lib/mlb_rb/client.rb
33
+ - lib/mlb_rb/game.rb
34
+ - lib/mlb_rb/team.rb
31
35
  - lib/mlb_rb/version.rb
32
36
  - mlb_rb.gemspec
33
37
  - sig/mlb_rb.rbs