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 +4 -4
- data/CHANGELOG.md +7 -2
- data/Gemfile.lock +2 -1
- data/README.md +12 -2
- data/lib/mlb_rb/client.rb +23 -2
- data/lib/mlb_rb/game.rb +16 -0
- data/lib/mlb_rb/version.rb +1 -1
- data/lib/mlb_rb.rb +14 -7
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '09ab2cb933d3a46547ff876634d4442eee526c629b7ff25dc341b33743646a1b'
|
|
4
|
+
data.tar.gz: e8b8325cadaa830073610169bd927fdd41c9d5406d8990212f4ea51a942221ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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
|
data/lib/mlb_rb/version.rb
CHANGED
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
31
|
-
|
|
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.
|
|
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-
|
|
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.
|
|
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: []
|