Skip to content
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
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Client interface {
// Error represents an error returned by the Sumo API.
type Error struct {
StatusCode int
Body []byte
Body string
ReadBodyErr error
}

Expand All @@ -41,7 +41,7 @@ func (e *Error) Error() string {
case len(e.Body) == 0:
return fmt.Sprintf("sumoapi: received HTTP %d response with empty body", e.StatusCode)
default:
return fmt.Sprintf("sumoapi: received HTTP %d response: %s", e.StatusCode, string(e.Body))
return fmt.Sprintf("sumoapi: received HTTP %d response: %s", e.StatusCode, e.Body)
}
}

Expand Down Expand Up @@ -104,7 +104,7 @@ func (c *client) doRequest(ctx context.Context, method, path string, query url.V
b, readErr := io.ReadAll(resp.Body)
return nil, &Error{
StatusCode: status,
Body: b,
Body: string(b),
ReadBodyErr: readErr,
}
}
Expand Down
6 changes: 6 additions & 0 deletions list_measurement_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func TestClient_ListMeasurementChanges(t *testing.T) {
g.Expect(query.Get("rikishiId")).To(Equal("123"))
g.Expect(query.Get("bashoId")).To(Equal("202501"))
g.Expect(query.Get("sortOrder")).To(Equal("asc"))
g.Expect(query.Get("limit")).To(Equal("50"))
g.Expect(query.Get("skip")).To(Equal("10"))
return nil
},
response: &http.Response{
Expand All @@ -187,6 +189,8 @@ func TestClient_ListMeasurementChanges(t *testing.T) {
RikishiID: 123,
BashoID: &bashoID,
SortOrder: "asc",
Limit: 50,
Skip: 10,
})

g.Expect(err).ToNot(HaveOccurred())
Expand All @@ -208,6 +212,8 @@ func TestClient_ListMeasurementChanges(t *testing.T) {
g.Expect(query.Has("rikishiId")).To(BeFalse())
g.Expect(query.Has("bashoId")).To(BeFalse())
g.Expect(query.Has("sortOrder")).To(BeFalse())
g.Expect(query.Has("limit")).To(BeFalse())
g.Expect(query.Has("skip")).To(BeFalse())
return nil
},
response: &http.Response{
Expand Down
3 changes: 3 additions & 0 deletions list_rank_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import "context"
// ListRankChangesAPI defines the methods available for listing rikishi rank changes across bashos.
type ListRankChangesAPI interface {
// ListRankChanges calls the GET /api/ranks endpoint.
//
// Ordering: results are sorted by rank (always ascending) when filtering
// by bashoId, and by bashoId when filtering by rikishiId.
ListRankChanges(ctx context.Context, req ListRikishiChangesRequest) ([]Rank, error)
}

Expand Down
6 changes: 6 additions & 0 deletions list_rank_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func TestClient_ListRankChanges(t *testing.T) {
g.Expect(query.Get("rikishiId")).To(Equal("123"))
g.Expect(query.Get("bashoId")).To(Equal("202501"))
g.Expect(query.Get("sortOrder")).To(Equal("asc"))
g.Expect(query.Get("limit")).To(Equal("50"))
g.Expect(query.Get("skip")).To(Equal("10"))
return nil
},
response: &http.Response{
Expand All @@ -180,6 +182,8 @@ func TestClient_ListRankChanges(t *testing.T) {
RikishiID: 123,
BashoID: &bashoID,
SortOrder: "asc",
Limit: 50,
Skip: 10,
})

g.Expect(err).ToNot(HaveOccurred())
Expand All @@ -200,6 +204,8 @@ func TestClient_ListRankChanges(t *testing.T) {
g.Expect(query.Has("rikishiId")).To(BeFalse())
g.Expect(query.Has("bashoId")).To(BeFalse())
g.Expect(query.Has("sortOrder")).To(BeFalse())
g.Expect(query.Has("limit")).To(BeFalse())
g.Expect(query.Has("skip")).To(BeFalse())
return nil
},
response: &http.Response{
Expand Down
8 changes: 8 additions & 0 deletions list_rikishi_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type ListRikishiChangesRequest struct {
RikishiID int `json:"rikishiId,omitempty" jsonschema:"The ID of the rikishi (sumo wrestler) whose changes are to be listed. Cannot be used together with bashoId."`
BashoID *BashoID `json:"bashoId,omitempty" jsonschema:"The ID of the basho (sumo tournament) for which rikishi (sumo wrestler) changes are to be listed. Cannot be used together with rikishiId."`
SortOrder string `json:"sortOrder,omitempty" jsonschema:"The order in which to sort the results by basho (sumo tournament). Valid values are 'asc' for ascending and 'desc' for descending. Default is 'desc'."`
Limit int `json:"limit,omitempty" jsonschema:"The maximum number of results to return."`
Skip int `json:"skip,omitempty" jsonschema:"The number of results to skip over for pagination."`
}

func listRikishiChanges[obj any](ctx context.Context, c *client, path string, req ListRikishiChangesRequest) ([]obj, error) {
Expand All @@ -24,5 +26,11 @@ func listRikishiChanges[obj any](ctx context.Context, c *client, path string, re
if order := getSortOrder(req.SortOrder); order != "" {
query.Set("sortOrder", order)
}
if req.Limit > 0 {
query.Set("limit", fmt.Sprint(req.Limit))
}
if req.Skip > 0 {
query.Set("skip", fmt.Sprint(req.Skip))
}
return listObjects[obj](ctx, c, path, query)
}
6 changes: 6 additions & 0 deletions list_shikona_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ func TestClient_ListShikonaChanges(t *testing.T) {
g.Expect(query.Get("rikishiId")).To(Equal("123"))
g.Expect(query.Get("bashoId")).To(Equal("202501"))
g.Expect(query.Get("sortOrder")).To(Equal("asc"))
g.Expect(query.Get("limit")).To(Equal("50"))
g.Expect(query.Get("skip")).To(Equal("10"))
return nil
},
response: &http.Response{
Expand All @@ -185,6 +187,8 @@ func TestClient_ListShikonaChanges(t *testing.T) {
RikishiID: 123,
BashoID: &bashoID,
SortOrder: "asc",
Limit: 50,
Skip: 10,
})

g.Expect(err).ToNot(HaveOccurred())
Expand All @@ -206,6 +210,8 @@ func TestClient_ListShikonaChanges(t *testing.T) {
g.Expect(query.Has("rikishiId")).To(BeFalse())
g.Expect(query.Has("bashoId")).To(BeFalse())
g.Expect(query.Has("sortOrder")).To(BeFalse())
g.Expect(query.Has("limit")).To(BeFalse())
g.Expect(query.Has("skip")).To(BeFalse())
return nil
},
response: &http.Response{
Expand Down
44 changes: 27 additions & 17 deletions tests/integration/list_rank_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,31 @@ import (
func TestIntegration_ListRankChanges(t *testing.T) {
client := sumoapi.New()

// Use a non-default limit to exercise the Limit input as well.
const pageLimit = 99

listAllRanks := func(g *WithT, req sumoapi.ListRikishiChangesRequest) []sumoapi.Rank {
req.Limit = pageLimit
var all []sumoapi.Rank
for {
req.Skip = len(all)
page, err := client.ListRankChanges(context.Background(), req)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(page).ToNot(BeNil())
all = append(all, page...)
if len(page) < pageLimit {
return all
}
}
}

t.Run("for rikishi", func(t *testing.T) {
g := NewWithT(t)

resp, err := client.ListRankChanges(context.Background(), sumoapi.ListRikishiChangesRequest{
resp := listAllRanks(g, sumoapi.ListRikishiChangesRequest{
RikishiID: 3081, // Hakuho
})

g.Expect(err).ToNot(HaveOccurred())
g.Expect(resp).ToNot(BeNil())
g.Expect(resp).To(HaveLen(122))

expectedBashoID := sumoapi.BashoID{Year: 2021, Month: 9}
Expand Down Expand Up @@ -48,24 +64,18 @@ func TestIntegration_ListRankChanges(t *testing.T) {
Month: 9,
}

resp, err := client.ListRankChanges(context.Background(), sumoapi.ListRikishiChangesRequest{
resp := listAllRanks(g, sumoapi.ListRikishiChangesRequest{
BashoID: &bashoID,
})

g.Expect(err).ToNot(HaveOccurred())
g.Expect(resp).ToNot(BeNil())
g.Expect(resp).To(HaveLen(611))

g.Expect(resp[0].ID).To(Equal(sumoapi.RikishiChangeID{BashoID: bashoID, RikishiID: 8850}))
g.Expect(resp[0].BashoID).To(Equal(bashoID))
g.Expect(resp[0].RikishiID).To(Equal(8850))
g.Expect(resp[0].HumanReadableName).To(Equal("Yokozuna 1 East"))
g.Expect(resp[0].NumericName).To(Equal(101))

g.Expect(resp[610].ID).To(Equal(sumoapi.RikishiChangeID{BashoID: bashoID, RikishiID: 9101}))
g.Expect(resp[610].BashoID).To(Equal(bashoID))
g.Expect(resp[610].RikishiID).To(Equal(9101))
g.Expect(resp[610].HumanReadableName).To(Equal("Jonokuchi 26 East"))
g.Expect(resp[610].NumericName).To(Equal(1026))
g.Expect(resp[0]).To(Equal(sumoapi.Rank{
ID: sumoapi.RikishiChangeID{BashoID: bashoID, RikishiID: 19},
BashoID: bashoID,
RikishiID: 19,
HumanReadableName: "Yokozuna 1 West",
NumericName: 101,
}))
})
}
Loading