feat: init client
This commit is contained in:
55
client/sets.go
Normal file
55
client/sets.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/kratisto/tcgdex-golang/models"
|
||||
)
|
||||
|
||||
// Sets retrieves all sets.
|
||||
// This function returns a list of all sets available in the Pokémon TCG database.
|
||||
func (s *tcgDexClient) Sets(ctx context.Context) ([]*models.Set, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, s.baseURL+"/sets", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sets, err := doRequest[[]*models.Set](s.httpClient, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sets, nil
|
||||
}
|
||||
|
||||
// GetSet retrieves a specific set by its ID.
|
||||
func (s *tcgDexClient) GetSet(ctx context.Context, setID string) (*models.Set, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, s.baseURL+"/sets/"+setID, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
set, err := doRequest[*models.Set](s.httpClient, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return set, nil
|
||||
}
|
||||
|
||||
// GetCardOfSet retrieves a specific card from a set by its ID.
|
||||
// This function is used to get a card that belongs to a specific set.
|
||||
func (s *tcgDexClient) GetCardOfSet(ctx context.Context, setID string, cardID string) (*models.Card, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, s.baseURL+"/sets/"+setID+"/cards/"+cardID, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
card, err := doRequest[*models.Card](s.httpClient, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return card, nil
|
||||
}
|
||||
Reference in New Issue
Block a user