mlb_rb 0.0.2 → 0.0.3

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: 93a32c08203af72a90434508faa6a3f9eed11818bd85d5b4d58f02900603bd52
4
- data.tar.gz: 7c5018622dcbbf59b427406a9989a6abd260b03ebd8805168e9e3aa7e9111f37
3
+ metadata.gz: '09ab2cb933d3a46547ff876634d4442eee526c629b7ff25dc341b33743646a1b'
4
+ data.tar.gz: e8b8325cadaa830073610169bd927fdd41c9d5406d8990212f4ea51a942221ea
5
5
  SHA512:
6
- metadata.gz: ebefd20383b5e2c9306c4df86f4fd614b1f2b9beb25c4d9fc2dff08552908b6ee1c8f601cf66fa981fbedbb2b6c66a62ddecd51abcab70ba6d4ba9a28ed32a32
7
- data.tar.gz: 23e4e550d72fd47a17ec28e0a2c4a70f8ec507bb5f5b12c936e0f2dca20aac45fdaaa3451561d0fdcae5717b15a89b19446b2b1d1db946bb4eef7e1591795f87
6
+ metadata.gz: 8622208d3231a546619c35c49266c95ae8df78430f6e669364b77108ea66d49ca4ad0711c9d63aef27de8d227308bd70b9bfd15eebfed459759bc2fc17fbb494
7
+ data.tar.gz: 53bd30fbc5934e0d1866e4439d91ba8efaa1cf94248aa75f9af66cf86572b01737f3d327524ece1399bb58f8ca0f526eaf0e3677088bc2d4c502e03e964fc245
data/CHANGELOG.md CHANGED
@@ -1,8 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.0.1] - 2022-03-25
3
+ ## [0.0.3] - 2022-03-26
4
+
5
+ - Add method to retrieve games for date range
6
+
7
+ ## [0.0.2] - 2022-03-25
8
+
9
+ - Add method to retrieve games for one date
4
10
 
5
- - Add endpoint to retrieve games for one date
6
11
  ## [0.0.1] - 2022-03-24
7
12
 
8
13
  - Add healthcheck that returns a string
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mlb_rb (0.0.1)
4
+ mlb_rb (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -50,6 +50,7 @@ GEM
50
50
 
51
51
  PLATFORMS
52
52
  x86_64-darwin-20
53
+ x86_64-linux
53
54
 
54
55
  DEPENDENCIES
55
56
  mlb_rb!
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mlb_rb`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ I started writing this gem because I wanted to extract a piece of a rails app that I had previously used to a gem, but the API changed from the first time I used it, so I had to rewrite it anyway, so instead of starting a new rails app immediately. I figured I could kill two birds and learn to write a gem and use the new MLB API.
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,7 +22,17 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ There are currently only two methods available:
26
+
27
+ ```ruby
28
+ MlbRb.games_for_date({ date: { year: 2022, month: 3, day: 24 } })
29
+ MlbRb.games_for_date_range(
30
+ {
31
+ start_date: { year: 2022, month: 3, day: 23 },
32
+ end_date: { year: 2022, month: 3, day: 24 }
33
+ }
34
+ )
35
+ ```
26
36
 
27
37
  ## Development
28
38
 
data/lib/mlb_rb/client.rb CHANGED
@@ -1,11 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "net/http"
4
+ require "json"
4
5
 
5
6
  module MlbRb
6
7
  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}")
8
+ attr_reader :json_response
9
+
10
+ def initialize(json_response)
11
+ @json_response = json_response
12
+ end
13
+
14
+ def parse_games_by_date_response
15
+ JSON.parse(json_response)["dates"].map do |date_hash|
16
+ date_hash["games"].map { |game| Game.new(game) }
17
+ end.flatten
18
+ end
19
+
20
+ class << self
21
+ def get_games_for_date(date)
22
+ json_response = Net::HTTP.get("statsapi.mlb.com", "/api/v1/schedule/games/?sportId=1&date=#{date}")
23
+ new(json_response).parse_games_by_date_response
24
+ end
25
+
26
+ def get_games_for_range(start_date, end_date)
27
+ json_response = Net::HTTP.get("statsapi.mlb.com", "/api/v1/schedule/games/?sportId=1&startDate=#{start_date}&endDate=#{end_date}")
28
+ new(json_response).parse_games_by_date_response
29
+ end
9
30
  end
10
31
  end
11
32
  end
data/lib/mlb_rb/game.rb CHANGED
@@ -20,5 +20,21 @@ module MlbRb
20
20
  @away_score = game_hash["teams"]["away"]["score"]
21
21
  @game_date = Date.parse(game_hash["gameDate"])
22
22
  end
23
+
24
+ def home_team_name
25
+ home_team.name
26
+ end
27
+
28
+ def home_team_id
29
+ home_team.id
30
+ end
31
+
32
+ def away_team_name
33
+ away_team.name
34
+ end
35
+
36
+ def away_team_id
37
+ away_team.id
38
+ end
23
39
  end
24
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MlbRb
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
data/lib/mlb_rb.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require "./lib/mlb_rb/version"
4
4
  require "./lib/mlb_rb/client"
5
5
  require "./lib/mlb_rb/game"
6
- require "json"
7
6
 
8
7
  module MlbRb
9
8
  class Error < StandardError; end
@@ -19,17 +18,25 @@ module MlbRb
19
18
  date = options[:date]
20
19
  raise DateError unless validate_date(date)
21
20
 
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) }
21
+ client.get_games_for_date(format_date(date))
22
+ end
23
+
24
+ def games_for_date_range(options)
25
+ start_date = options[:start_date]
26
+ end_date = options[:end_date]
27
+ [start_date, end_date].each do |date|
28
+ raise DateError unless validate_date(date)
29
+ end
30
+ client.get_games_for_range(format_date(start_date), format_date(end_date))
26
31
  end
27
32
 
28
33
  private
29
34
 
30
- def validate_date(date)
31
- return unless date
35
+ def format_date(date)
36
+ "#{"%02d" % date[:month]}/#{"%02d" % date[:day]}/#{date[:year]}"
37
+ end
32
38
 
39
+ def validate_date(date)
33
40
  date.map do |key, value|
34
41
  valid_number_for_date(value, key)
35
42
  end.all?
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlb_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Miranda
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-25 00:00:00.000000000 Z
11
+ date: 2022-03-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email:
15
15
  - mmiranda@doximity.com
16
16
  executables: []
@@ -42,7 +42,7 @@ metadata:
42
42
  homepage_uri: https://www.github.com/notmarkmiranda/mlb_rb
43
43
  source_code_uri: https://www.github.com/notmarkmiranda/mlb_rb
44
44
  changelog_uri: https://www.github.com/notmarkmiranda/mlb_rb/blob/main/CHANGELOG.md
45
- post_install_message:
45
+ post_install_message:
46
46
  rdoc_options: []
47
47
  require_paths:
48
48
  - lib
@@ -57,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  requirements: []
60
- rubygems_version: 3.2.3
61
- signing_key:
60
+ rubygems_version: 3.2.32
61
+ signing_key:
62
62
  specification_version: 4
63
63
  summary: MLB API Wrapper for Ruby
64
64
  test_files: []