-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jasonhancock/venues
Adds support for retrieving venue information
- Loading branch information
Showing
11 changed files
with
161 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/stevepartridge/mlb | ||
|
||
go 1.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package mlb | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
func (m *Mlb) GetVenues() ([]Venue, error) { | ||
resp, err := m.Call("/venues", nil) | ||
if err != nil { | ||
return []Venue{}, err | ||
} | ||
|
||
return resp.Venues, nil | ||
} | ||
|
||
func (m *Mlb) GetVenue(venueID int) (Venue, error) { | ||
resp, err := m.Call(fmt.Sprintf("/venues/%d", venueID), nil) | ||
if err != nil { | ||
return Venue{}, err | ||
} | ||
|
||
for _, v := range resp.Venues { | ||
if v.Id == venueID { | ||
return v, nil | ||
} | ||
} | ||
|
||
return Venue{}, errors.New("not found") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package mlb_test | ||
|
||
import "testing" | ||
|
||
func Test_GetVenues_Success(t *testing.T) { | ||
|
||
venues, err := mlbApi.GetVenues() | ||
if err != nil { | ||
t.Error("Should not error when retrieving venues") | ||
} | ||
|
||
if len(venues) == 0 { | ||
t.Error("Should be more than zero") | ||
} | ||
|
||
} | ||
|
||
func Test_GetVenue_Success(t *testing.T) { | ||
venue, err := mlbApi.GetVenue(10) // "Oakland Coliseum" | ||
if err != nil { | ||
t.Error("Should not error when retrieving venue") | ||
} | ||
|
||
if venue.Name != "Oakland Coliseum" { | ||
t.Errorf("Expected `Oakland Coliseum`, got %q", venue.Name) | ||
|
||
} | ||
} | ||
|
||
func Test_GetVenue_Failure_InvalidVenueID(t *testing.T) { | ||
_, err := mlbApi.GetVenue(8675309) | ||
if err == nil { | ||
t.Error("Should be error when retrieving invalid venue") | ||
} | ||
} |