Files
tcgdex-golang/client/cards.go

41 lines
1005 B
Go

package client
import (
"context"
"net/http"
"github.com/kratisto/tcgdex-golang/models"
)
// GetCard retrieves a specific card by its ID.
// This function is used to get detailed information about a specific card.
func (s *tcgDexClient) GetCard(ctx context.Context, id string) (*models.Card, error) {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, s.baseURL+"/cards/"+id, nil)
if err != nil {
return nil, err
}
card, err := doRequest[models.Card](s.httpClient, request)
if err != nil {
return nil, err
}
return card, nil
}
// Cards retrieves all cards.
// This function returns a list of all cards available in the Pokémon TCG database.
func (s *tcgDexClient) Cards(ctx context.Context) ([]models.Card, error) {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, s.baseURL+"/cards", nil)
if err != nil {
return nil, err
}
cards, err := doRequestSlice[models.Card](s.httpClient, request)
if err != nil {
return nil, err
}
return cards, nil
}