Skip to content

Commit ab90c85

Browse files
committed
Added Mock API endpoint /content_classification_labels
1 parent 6b5147e commit ab90c85

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package ccl
4+
5+
import (
6+
"net/http"
7+
"testing"
8+
9+
"github.com/twitchdev/twitch-cli/test_setup"
10+
"github.com/twitchdev/twitch-cli/test_setup/test_server"
11+
)
12+
13+
func TestContentClassificationLabels(t *testing.T) {
14+
a := test_setup.SetupTestEnv(t)
15+
ts := test_server.SetupTestServer(ContentClassificationLabels{})
16+
17+
// get
18+
req, _ := http.NewRequest(http.MethodGet, ts.URL+ContentClassificationLabels{}.Path(), nil)
19+
q := req.URL.Query()
20+
req.URL.RawQuery = q.Encode()
21+
resp, err := http.DefaultClient.Do(req)
22+
a.Nil(err)
23+
a.Equal(200, resp.StatusCode)
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package ccl
4+
5+
import (
6+
"encoding/json"
7+
"net/http"
8+
9+
"github.com/twitchdev/twitch-cli/internal/models"
10+
)
11+
12+
var cclMethodsSupported = map[string]bool{
13+
http.MethodGet: true,
14+
http.MethodPost: false,
15+
http.MethodDelete: false,
16+
http.MethodPatch: false,
17+
http.MethodPut: false,
18+
}
19+
20+
var cclScopesByMethod = map[string][]string{
21+
http.MethodGet: {},
22+
http.MethodPost: {},
23+
http.MethodDelete: {},
24+
http.MethodPatch: {},
25+
http.MethodPut: {},
26+
}
27+
28+
type ContentClassificationLabels struct{}
29+
30+
func (e ContentClassificationLabels) Path() string { return "/content_classification_labels" }
31+
32+
func (e ContentClassificationLabels) GetRequiredScopes(method string) []string {
33+
return cclScopesByMethod[method]
34+
}
35+
36+
func (e ContentClassificationLabels) ValidMethod(method string) bool {
37+
return cclMethodsSupported[method]
38+
}
39+
40+
func (e ContentClassificationLabels) ServeHTTP(w http.ResponseWriter, r *http.Request) {
41+
switch r.Method {
42+
case http.MethodGet:
43+
getContentClassificationLabels(w, r)
44+
break
45+
default:
46+
w.WriteHeader(http.StatusMethodNotAllowed)
47+
}
48+
}
49+
func getContentClassificationLabels(w http.ResponseWriter, r *http.Request) {
50+
// TODO: locale param
51+
52+
allCCLs := []models.ContentClassificationLabel{}
53+
for _, ccl := range models.CCL_MAP {
54+
allCCLs = append(allCCLs, ccl)
55+
}
56+
57+
bytes, _ := json.Marshal(
58+
models.APIResponse{
59+
Data: allCCLs,
60+
},
61+
)
62+
w.Write(bytes)
63+
}

internal/mock_api/endpoints/endpoints.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/twitchdev/twitch-cli/internal/mock_api"
77
"github.com/twitchdev/twitch-cli/internal/mock_api/endpoints/bits"
88
"github.com/twitchdev/twitch-cli/internal/mock_api/endpoints/categories"
9+
"github.com/twitchdev/twitch-cli/internal/mock_api/endpoints/ccl"
910
"github.com/twitchdev/twitch-cli/internal/mock_api/endpoints/channel_points"
1011
"github.com/twitchdev/twitch-cli/internal/mock_api/endpoints/channels"
1112
"github.com/twitchdev/twitch-cli/internal/mock_api/endpoints/charity"
@@ -34,6 +35,7 @@ func All() []mock_api.MockEndpoint {
3435
bits.Cheermotes{},
3536
categories.Games{},
3637
categories.TopGames{},
38+
ccl.ContentClassificationLabels{},
3739
channel_points.Redemption{},
3840
channel_points.Reward{},
3941
channels.CommercialEndpoint{},

internal/models/ccl.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
package models
44

55
type ContentClassificationLabel struct {
6-
Description string
7-
ID string
8-
Name string
9-
RestrictedGaming bool // Restricts users from applying that CCL via the API. Currently only for MatureGame.
6+
Description string `json:"description"`
7+
ID string `json:"id"`
8+
Name string `json:"name"`
9+
RestrictedGaming bool `json:"-"` // Restricts users from applying that CCL via the API. Currently only for MatureGame.
1010
}
1111

1212
var CCL_MAP = map[string]ContentClassificationLabel{

0 commit comments

Comments
 (0)