From 91e1ae09b35b47364ed90d9aba19b253f981b64f Mon Sep 17 00:00:00 2001 From: Evan Forbes Date: Sun, 26 May 2024 20:19:41 -0700 Subject: [PATCH 1/2] Update Nexus API URL and add API key --- partner/nexus.go | 8 +++++--- partner/nexus_test.go | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/partner/nexus.go b/partner/nexus.go index 495288d2..d5202658 100644 --- a/partner/nexus.go +++ b/partner/nexus.go @@ -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 } @@ -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 diff --git a/partner/nexus_test.go b/partner/nexus_test.go index 0b9c5409..ef6cda74 100644 --- a/partner/nexus_test.go +++ b/partner/nexus_test.go @@ -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) From a1ccd2c3715aa2eebaaf84bbf60b42f00b6f2c70 Mon Sep 17 00:00:00 2001 From: Patrick Fairbank Date: Mon, 27 May 2024 16:05:15 -0700 Subject: [PATCH 2/2] Fix Nexus test in arena_test.go. --- field/arena_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/field/arena_test.go b/field/arena_test.go index e1f0e58e..d5aec8b8 100644 --- a/field/arena_test.go +++ b/field/arena_test.go @@ -525,7 +525,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)