|
| 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 | +} |
0 commit comments