Skip to content

Commit a0771e2

Browse files
committed
Add SearchRikishisAPI
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
1 parent 55c88be commit a0771e2

21 files changed

Lines changed: 1239 additions & 1 deletion

.github/dependabot.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
multi-ecosystem-groups:
3+
project:
4+
schedule:
5+
interval: weekly
6+
updates:
7+
- package-ecosystem: gomod
8+
directory: /
9+
patterns: ["*"]
10+
multi-ecosystem-group: project
11+
- package-ecosystem: github-actions
12+
directories:
13+
- .github/workflows
14+
patterns: ["*"]
15+
multi-ecosystem-group: project

.github/workflows/release.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
15+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
16+
with:
17+
go-version: 1.25
18+
- run: make test
19+
- run: make test-integration
20+
- name: Create GitHub release
21+
run: gh release create ${{ github.ref_name }} --generate-notes
22+
env:
23+
GH_TOKEN: ${{ github.token }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Test Integration
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
11+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
12+
with:
13+
go-version: 1.25
14+
- run: make test-integration

.github/workflows/test.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
14+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
15+
with:
16+
go-version: 1.25
17+
- run: make test

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.PHONY: test
2+
test:
3+
go test -v ./...
4+
5+
.PHONY: test-integration
6+
test-integration:
7+
cd tests/integration; go test -v ./...

basho.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package sumoapi
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"strconv"
7+
)
8+
9+
// BashoID represents the unique identifier for a Basho (sumo tournament).
10+
type BashoID struct {
11+
Year int
12+
Month int // Month is 1-12.
13+
}
14+
15+
func (b BashoID) MarshalJSON() ([]byte, error) {
16+
return []byte(`"` + fmt.Sprintf("%04d%02d", b.Year, b.Month) + `"`), nil
17+
}
18+
19+
func (b *BashoID) UnmarshalJSON(data []byte) error {
20+
var s string
21+
if err := json.Unmarshal(data, &s); err != nil {
22+
return fmt.Errorf("error unmarshaling BashoID: %w", err)
23+
}
24+
if len(s) != 6 {
25+
return fmt.Errorf("invalid BashoID format: %s", s)
26+
}
27+
year, err := strconv.Atoi(s[0:4])
28+
if err != nil {
29+
return fmt.Errorf("error parsing year from BashoID: %w", err)
30+
}
31+
month, err := strconv.Atoi(s[4:6])
32+
if err != nil {
33+
return fmt.Errorf("error parsing month from BashoID: %w", err)
34+
}
35+
b.Year = year
36+
b.Month = month
37+
return nil
38+
}

basho_rikishi_id.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package sumoapi
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"strconv"
7+
)
8+
9+
// BashoRikishiID represents the unique identifier for a Rikishi in a specific Basho (sumo tournament).
10+
type BashoRikishiID struct {
11+
BashoID
12+
RikishiID int
13+
}
14+
15+
func (b BashoRikishiID) MarshalJSON() ([]byte, error) {
16+
return []byte(`"` + fmt.Sprintf("%04d%02d-%d", b.Year, b.Month, b.RikishiID) + `"`), nil
17+
}
18+
19+
func (b *BashoRikishiID) UnmarshalJSON(data []byte) error {
20+
var s string
21+
if err := json.Unmarshal(data, &s); err != nil {
22+
return fmt.Errorf("error unmarshaling BashoRikishiID: %w", err)
23+
}
24+
if len(s) < 7 {
25+
return fmt.Errorf("invalid BashoRikishiID format: %s", s)
26+
}
27+
year, err := strconv.Atoi(s[0:4])
28+
if err != nil {
29+
return fmt.Errorf("error parsing year from BashoRikishiID: %w", err)
30+
}
31+
month, err := strconv.Atoi(s[4:6])
32+
if err != nil {
33+
return fmt.Errorf("error parsing month from BashoRikishiID: %w", err)
34+
}
35+
b.Year = year
36+
b.Month = month
37+
rikishiID, err := strconv.Atoi(s[7:])
38+
if err != nil {
39+
return fmt.Errorf("error parsing RikishiID from BashoRikishiID: %w", err)
40+
}
41+
b.RikishiID = rikishiID
42+
return nil
43+
}

basho_rikishi_id_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package sumoapi_test
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
. "github.com/onsi/gomega"
8+
9+
"github.com/sumo-mcp/sumoapi-go"
10+
)
11+
12+
func TestMarshalBashoRikishiIDToJSON(t *testing.T) {
13+
for _, tt := range []struct {
14+
name string
15+
bashoRikishiID sumoapi.BashoRikishiID
16+
expectedJSON string
17+
}{
18+
{
19+
name: "double digit month",
20+
bashoRikishiID: sumoapi.BashoRikishiID{BashoID: sumoapi.BashoID{Year: 2023, Month: 11}, RikishiID: 1},
21+
expectedJSON: `"202311-1"`,
22+
},
23+
{
24+
name: "single digit month",
25+
bashoRikishiID: sumoapi.BashoRikishiID{BashoID: sumoapi.BashoID{Year: 1999, Month: 3}, RikishiID: 1},
26+
expectedJSON: `"199903-1"`,
27+
},
28+
} {
29+
t.Run(tt.name, func(t *testing.T) {
30+
g := NewWithT(t)
31+
b, err := json.Marshal(tt.bashoRikishiID)
32+
g.Expect(err).ToNot(HaveOccurred())
33+
g.Expect(string(b)).To(Equal(tt.expectedJSON))
34+
})
35+
}
36+
37+
t.Run("marshal inside struct", func(t *testing.T) {
38+
g := NewWithT(t)
39+
type wrapper struct {
40+
Basho sumoapi.BashoRikishiID `json:"basho"`
41+
}
42+
w := wrapper{Basho: sumoapi.BashoRikishiID{BashoID: sumoapi.BashoID{Year: 2023, Month: 11}, RikishiID: 1}}
43+
b, err := json.Marshal(w)
44+
g.Expect(err).ToNot(HaveOccurred())
45+
g.Expect(string(b)).To(Equal(`{"basho":"202311-1"}`))
46+
})
47+
}
48+
49+
func TestUnmarshalBashoRikishiIDFromJSON(t *testing.T) {
50+
for _, tt := range []struct {
51+
name string
52+
jsonData string
53+
expectedBashoRikishiID sumoapi.BashoRikishiID
54+
expectError bool
55+
}{
56+
{
57+
name: "double digit month",
58+
jsonData: `"202311-1"`,
59+
expectedBashoRikishiID: sumoapi.BashoRikishiID{BashoID: sumoapi.BashoID{Year: 2023, Month: 11}, RikishiID: 1},
60+
expectError: false,
61+
},
62+
{
63+
name: "single digit month",
64+
jsonData: `"199903-1"`,
65+
expectedBashoRikishiID: sumoapi.BashoRikishiID{BashoID: sumoapi.BashoID{Year: 1999, Month: 3}, RikishiID: 1},
66+
expectError: false,
67+
},
68+
{
69+
name: "invalid format",
70+
jsonData: `"20A911"`,
71+
expectedBashoRikishiID: sumoapi.BashoRikishiID{},
72+
expectError: true,
73+
},
74+
{
75+
name: "wrong length",
76+
jsonData: `"20231"`,
77+
expectedBashoRikishiID: sumoapi.BashoRikishiID{},
78+
expectError: true,
79+
},
80+
} {
81+
t.Run(tt.name, func(t *testing.T) {
82+
g := NewWithT(t)
83+
var b sumoapi.BashoRikishiID
84+
err := json.Unmarshal([]byte(tt.jsonData), &b)
85+
if tt.expectError {
86+
g.Expect(err).To(HaveOccurred())
87+
} else {
88+
g.Expect(err).ToNot(HaveOccurred())
89+
g.Expect(b).To(Equal(tt.expectedBashoRikishiID))
90+
}
91+
})
92+
}
93+
94+
t.Run("unmarshal inside struct", func(t *testing.T) {
95+
g := NewWithT(t)
96+
type wrapper struct {
97+
Basho sumoapi.BashoRikishiID `json:"basho"`
98+
}
99+
jsonData := `{"basho":"202311-1"}`
100+
var w wrapper
101+
err := json.Unmarshal([]byte(jsonData), &w)
102+
g.Expect(err).ToNot(HaveOccurred())
103+
g.Expect(w.Basho).To(Equal(sumoapi.BashoRikishiID{BashoID: sumoapi.BashoID{Year: 2023, Month: 11}, RikishiID: 1}))
104+
})
105+
}

basho_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package sumoapi_test
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
. "github.com/onsi/gomega"
8+
9+
"github.com/sumo-mcp/sumoapi-go"
10+
)
11+
12+
func TestMarshalBashoIDToJSON(t *testing.T) {
13+
for _, tt := range []struct {
14+
name string
15+
bashoID sumoapi.BashoID
16+
expectedJSON string
17+
}{
18+
{
19+
name: "double digit month",
20+
bashoID: sumoapi.BashoID{Year: 2023, Month: 11},
21+
expectedJSON: `"202311"`,
22+
},
23+
{
24+
name: "single digit month",
25+
bashoID: sumoapi.BashoID{Year: 1999, Month: 3},
26+
expectedJSON: `"199903"`,
27+
},
28+
} {
29+
t.Run(tt.name, func(t *testing.T) {
30+
g := NewWithT(t)
31+
b, err := json.Marshal(tt.bashoID)
32+
g.Expect(err).ToNot(HaveOccurred())
33+
g.Expect(string(b)).To(Equal(tt.expectedJSON))
34+
})
35+
}
36+
37+
t.Run("marshal inside struct", func(t *testing.T) {
38+
g := NewWithT(t)
39+
type wrapper struct {
40+
Basho sumoapi.BashoID `json:"basho"`
41+
}
42+
w := wrapper{Basho: sumoapi.BashoID{Year: 2023, Month: 11}}
43+
b, err := json.Marshal(w)
44+
g.Expect(err).ToNot(HaveOccurred())
45+
g.Expect(string(b)).To(Equal(`{"basho":"202311"}`))
46+
})
47+
}
48+
49+
func TestUnmarshalBashoIDFromJSON(t *testing.T) {
50+
for _, tt := range []struct {
51+
name string
52+
jsonData string
53+
expectedBashoID sumoapi.BashoID
54+
expectError bool
55+
}{
56+
{
57+
name: "double digit month",
58+
jsonData: `"202311"`,
59+
expectedBashoID: sumoapi.BashoID{Year: 2023, Month: 11},
60+
expectError: false,
61+
},
62+
{
63+
name: "single digit month",
64+
jsonData: `"199903"`,
65+
expectedBashoID: sumoapi.BashoID{Year: 1999, Month: 3},
66+
expectError: false,
67+
},
68+
{
69+
name: "invalid format",
70+
jsonData: `"20A911"`,
71+
expectedBashoID: sumoapi.BashoID{},
72+
expectError: true,
73+
},
74+
{
75+
name: "wrong length",
76+
jsonData: `"20231"`,
77+
expectedBashoID: sumoapi.BashoID{},
78+
expectError: true,
79+
},
80+
} {
81+
t.Run(tt.name, func(t *testing.T) {
82+
g := NewWithT(t)
83+
var b sumoapi.BashoID
84+
err := json.Unmarshal([]byte(tt.jsonData), &b)
85+
if tt.expectError {
86+
g.Expect(err).To(HaveOccurred())
87+
} else {
88+
g.Expect(err).ToNot(HaveOccurred())
89+
g.Expect(b).To(Equal(tt.expectedBashoID))
90+
}
91+
})
92+
}
93+
94+
t.Run("unmarshal inside struct", func(t *testing.T) {
95+
g := NewWithT(t)
96+
type wrapper struct {
97+
Basho sumoapi.BashoID `json:"basho"`
98+
}
99+
jsonData := `{"basho":"202311"}`
100+
var w wrapper
101+
err := json.Unmarshal([]byte(jsonData), &w)
102+
g.Expect(err).ToNot(HaveOccurred())
103+
g.Expect(w.Basho).To(Equal(sumoapi.BashoID{Year: 2023, Month: 11}))
104+
})
105+
}

client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
// Client is a client for the Sumo API.
1313
type Client interface {
14+
SearchRikishisAPI
1415
}
1516

1617
type client struct {

0 commit comments

Comments
 (0)