From bff78e417d2bf41e16eb1e4141bcaaa7d2d566e0 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Mon, 19 Jan 2026 09:58:10 -1000 Subject: Refactor Trello client to use url.Values for query params Replace manual string concatenation with url.Values for cleaner, safer query parameter construction in GetBoards, GetCards, and getLists. Co-Authored-By: Claude Opus 4.5 --- internal/api/trello.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/internal/api/trello.go b/internal/api/trello.go index be5d81b..91d6d66 100644 --- a/internal/api/trello.go +++ b/internal/api/trello.go @@ -64,9 +64,13 @@ type trelloListResponse struct { // GetBoards fetches all boards for the authenticated user func (c *TrelloClient) GetBoards(ctx context.Context) ([]models.Board, error) { - url := fmt.Sprintf("%s/members/me/boards?key=%s&token=%s&filter=open", c.baseURL, c.apiKey, c.token) + params := url.Values{} + params.Set("key", c.apiKey) + params.Set("token", c.token) + params.Set("filter", "open") - req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + reqURL := fmt.Sprintf("%s/members/me/boards?%s", c.baseURL, params.Encode()) + req, err := http.NewRequestWithContext(ctx, "GET", reqURL, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } @@ -103,9 +107,13 @@ func (c *TrelloClient) GetBoards(ctx context.Context) ([]models.Board, error) { // GetCards fetches all cards for a specific board func (c *TrelloClient) GetCards(ctx context.Context, boardID string) ([]models.Card, error) { - url := fmt.Sprintf("%s/boards/%s/cards?key=%s&token=%s&filter=visible", c.baseURL, boardID, c.apiKey, c.token) + params := url.Values{} + params.Set("key", c.apiKey) + params.Set("token", c.token) + params.Set("filter", "visible") - req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + reqURL := fmt.Sprintf("%s/boards/%s/cards?%s", c.baseURL, boardID, params.Encode()) + req, err := http.NewRequestWithContext(ctx, "GET", reqURL, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } @@ -163,9 +171,12 @@ func (c *TrelloClient) GetCards(ctx context.Context, boardID string) ([]models.C // getLists fetches lists for a board func (c *TrelloClient) getLists(ctx context.Context, boardID string) ([]models.List, error) { - url := fmt.Sprintf("%s/boards/%s/lists?key=%s&token=%s", c.baseURL, boardID, c.apiKey, c.token) + params := url.Values{} + params.Set("key", c.apiKey) + params.Set("token", c.token) - req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + reqURL := fmt.Sprintf("%s/boards/%s/lists?%s", c.baseURL, boardID, params.Encode()) + req, err := http.NewRequestWithContext(ctx, "GET", reqURL, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } -- cgit v1.2.3