Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Nexus API URL and add API key #187

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading