Skip to content

Commit

Permalink
Update Nexus API URL and add API key
Browse files Browse the repository at this point in the history
  • Loading branch information
eforbes committed May 27, 2024
1 parent d8406f4 commit 91e1ae0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
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 91e1ae0

Please sign in to comment.