Skip to content

Commit

Permalink
Merge branch 'main' into 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed Jun 5, 2024
2 parents 0d8324d + bc0727b commit ac1b477
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion field/arena_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ func TestLoadTeamsFromNexus(t *testing.T) {

// Mock the Nexus server.
nexusServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.URL.String(), "/v1/my_event_code/p1/lineup") {
if strings.Contains(r.URL.String(), "/api/v1/event/my_event_code/match/p1/lineup") {
w.Write([]byte("{\"red\":[\"112\",\"111\",\"110\"],\"blue\":[\"109\",\"108\",\"107\"]}"))
} else {
http.Error(w, "Match not found", 404)
Expand Down
8 changes: 5 additions & 3 deletions partner/nexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (
"strconv"
)

const nexusBaseUrl = "https://api.frc.nexus"
const nexusBaseUrl = "https://frc.nexus"
const nexusApiKey = "Vn6D9y80kQcNijDItKOJHg8yYEk"

type NexusClient struct {
BaseUrl string
apiKey string
eventCode string
}

Expand All @@ -27,12 +29,12 @@ type nexusLineup struct {
}

func NewNexusClient(eventCode string) *NexusClient {
return &NexusClient{BaseUrl: nexusBaseUrl, eventCode: eventCode}
return &NexusClient{BaseUrl: nexusBaseUrl, apiKey: nexusApiKey, eventCode: eventCode}
}

// Gets the team lineup for a given match from the Nexus API. Returns nil and an error if the lineup is not available.
func (client *NexusClient) GetLineup(tbaMatchKey model.TbaMatchKey) (*[6]int, error) {
path := fmt.Sprintf("/v1/%s/%s/lineup", client.eventCode, tbaMatchKey.String())
path := fmt.Sprintf("/api/v1/event/%s/match/%s/lineups?key=%s", client.eventCode, tbaMatchKey.String(), client.apiKey)
resp, err := client.getRequest(path)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions partner/nexus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
func TestGetLineup(t *testing.T) {
// Mock the Nexus server.
nexusServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Contains(t, r.URL.String(), "/v1/my_event_code/")
if strings.Contains(r.URL.String(), "/v1/my_event_code/p1/lineup") {
assert.Contains(t, r.URL.String(), "/api/v1/event/my_event_code/")
if strings.Contains(r.URL.String(), "/api/v1/event/my_event_code/match/p1/lineups") {
w.Write([]byte("{\"red\":[\"101\",\"102\",\"103\"],\"blue\":[\"104\",\"105\",\"106\"]}"))
} else if strings.Contains(r.URL.String(), "/v1/my_event_code/p2/lineup") {
} else if strings.Contains(r.URL.String(), "/api/v1/event/my_event_code/match/p2/lineups") {
w.Write([]byte("{\"blue\":[\"104\",\"105\",\"106\"]}"))
} else if strings.Contains(r.URL.String(), "/v1/my_event_code/p3/lineup") {
} else if strings.Contains(r.URL.String(), "/api/v1/event/my_event_code/match/p3/lineups") {
w.Write([]byte("{}"))
} else {
http.Error(w, "Match not found", 404)
Expand Down

0 comments on commit ac1b477

Please sign in to comment.