Skip to content

Commit f8f15cf

Browse files
committed
Renamed /chat/emotes/channel to /chat/emotes; /chat/emotes and its sub-endpoints now have all missing fields; POST and PATCH /schedule/segment have missing fields, and no longer mandate is_reoccurring
1 parent 98df51e commit f8f15cf

File tree

8 files changed

+111
-24
lines changed

8 files changed

+111
-24
lines changed

internal/database/schedule.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type ScheduleSegment struct {
2424
IsVacation bool `db:"is_vacation" json:"-"`
2525
Category *SegmentCategory `json:"category"`
2626
UserID string `db:"broadcaster_id" json:"-"`
27-
Timezone string `db:"timezone" json:"timezone"`
27+
Timezone string `db:"timezone" json:"timezone,omitempty"`
2828
CategoryID *string `db:"category_id" json:"-"`
2929
CategoryName *string `db:"category_name" dbi:"false" json:"-"`
3030
IsCanceled *bool `db:"is_canceled" json:"-"`

internal/mock_api/endpoints/chat/emote_set.go

+24-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func getEmoteSets(w http.ResponseWriter, r *http.Request) {
6161
}
6262

6363
for _, v := range defaultEmoteTypes {
64+
ownerID := util.RandomUserID()
6465
emoteType := v
6566
for i := 0; i < 5; i++ {
6667
id := util.RandomInt(10 * 1000)
@@ -69,12 +70,26 @@ func getEmoteSets(w http.ResponseWriter, r *http.Request) {
6970
ID: fmt.Sprint(id),
7071
Name: name,
7172
Images: EmotesImages{
72-
ImageURL1X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v1/%v/1.0", id),
73-
ImageURL2X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v1/%v/2.0", id),
74-
ImageURL4X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v1/%v/4.0", id),
73+
ImageURL1X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v2/%v/static/light/1.0", id),
74+
ImageURL2X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v2/%v/static/light/2.0", id),
75+
ImageURL4X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v2/%v/static/light/3.0", id),
7576
},
7677
EmoteType: &emoteType,
7778
EmoteSetID: &setID,
79+
OwnerID: &ownerID,
80+
Format: []string{
81+
"static",
82+
"animated",
83+
},
84+
Scale: []string{
85+
"1.0",
86+
"2.0",
87+
"3.0",
88+
},
89+
ThemeMode: []string{
90+
"light",
91+
"dark",
92+
},
7893
}
7994
if emoteType == "subscription" {
8095
thousand := "1000"
@@ -88,6 +103,11 @@ func getEmoteSets(w http.ResponseWriter, r *http.Request) {
88103
}
89104
}
90105

91-
bytes, _ := json.Marshal(models.APIResponse{Data: emotes})
106+
bytes, _ := json.Marshal(
107+
models.APIResponse{
108+
Data: emotes,
109+
Template: templateEmoteURL,
110+
},
111+
)
92112
w.Write(bytes)
93113
}

internal/mock_api/endpoints/chat/channel_emotes.go renamed to internal/mock_api/endpoints/chat/emotes.go

+23-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var channelEmotesScopesByMethod = map[string][]string{
3131

3232
type ChannelEmotes struct{}
3333

34-
func (e ChannelEmotes) Path() string { return "/chat/emotes/channel" }
34+
func (e ChannelEmotes) Path() string { return "/chat/emotes" }
3535

3636
func (e ChannelEmotes) GetRequiredScopes(method string) []string {
3737
return channelEmotesScopesByMethod[method]
@@ -61,7 +61,6 @@ func getChannelEmotes(w http.ResponseWriter, r *http.Request) {
6161
}
6262

6363
setID := fmt.Sprint(util.RandomInt(10 * 1000))
64-
ownerID := util.RandomUserID()
6564
for _, v := range defaultEmoteTypes {
6665
emoteType := v
6766
for i := 0; i < 5; i++ {
@@ -71,13 +70,25 @@ func getChannelEmotes(w http.ResponseWriter, r *http.Request) {
7170
ID: fmt.Sprint(id),
7271
Name: name,
7372
Images: EmotesImages{
74-
ImageURL1X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v1/%v/1.0", id),
75-
ImageURL2X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v1/%v/2.0", id),
76-
ImageURL4X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v1/%v/4.0", id),
73+
ImageURL1X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v2/%v/static/light/1.0", id),
74+
ImageURL2X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v2/%v/static/light/2.0", id),
75+
ImageURL4X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v2/%v/static/light/3.0", id),
7776
},
7877
EmoteType: &emoteType,
7978
EmoteSetID: &setID,
80-
OwnerID: &ownerID,
79+
Format: []string{
80+
"static",
81+
"animated",
82+
},
83+
Scale: []string{
84+
"1.0",
85+
"2.0",
86+
"3.0",
87+
},
88+
ThemeMode: []string{
89+
"light",
90+
"dark",
91+
},
8192
}
8293
if emoteType == "subscription" {
8394
thousand := "1000"
@@ -91,6 +102,11 @@ func getChannelEmotes(w http.ResponseWriter, r *http.Request) {
91102
}
92103
}
93104

94-
bytes, _ := json.Marshal(models.APIResponse{Data: emotes})
105+
bytes, _ := json.Marshal(
106+
models.APIResponse{
107+
Data: emotes,
108+
Template: templateEmoteURL,
109+
},
110+
)
95111
w.Write(bytes)
96112
}

internal/mock_api/endpoints/chat/global_emotes.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,30 @@ func getGlobalEmotes(w http.ResponseWriter, r *http.Request) {
6262
ID: fmt.Sprintf("%v", id),
6363
Name: name,
6464
Images: EmotesImages{
65-
ImageURL1X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v1/%v/1.0", id),
66-
ImageURL2X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v1/%v/2.0", id),
67-
ImageURL4X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v1/%v/4.0", id),
65+
ImageURL1X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v2/%v/static/light/1.0", id),
66+
ImageURL2X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v2/%v/static/light/2.0", id),
67+
ImageURL4X: fmt.Sprintf("https://static-cdn.jtvnw.net/emoticons/v2/%v/static/light/3.0", id),
68+
},
69+
Format: []string{
70+
"static",
71+
},
72+
Scale: []string{
73+
"1.0",
74+
"2.0",
75+
"3.0",
76+
},
77+
ThemeMode: []string{
78+
"light",
79+
"dark",
6880
},
6981
})
7082
}
7183

72-
bytes, _ := json.Marshal(models.APIResponse{Data: emotes})
84+
bytes, _ := json.Marshal(
85+
models.APIResponse{
86+
Data: emotes,
87+
Template: templateEmoteURL,
88+
},
89+
)
7390
w.Write(bytes)
7491
}

internal/mock_api/endpoints/chat/shared.go

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import "github.com/twitchdev/twitch-cli/internal/database"
77
var db database.CLIDatabase
88
var defaultEmoteTypes = []string{"subscription", "bitstier", "follower"}
99

10+
const templateEmoteURL = "https://static-cdn.jtvnw.net/emoticons/v2/{{id}}/{{format}}/{{theme_mode}}/{{scale}}"
11+
1012
type BadgesResponse struct {
1113
SetID string `json:"set_id"`
1214
Versions []BadgesVersion `json:"versions"`
@@ -27,6 +29,9 @@ type EmotesResponse struct {
2729
EmoteType *string `json:"emote_type,omitempty"`
2830
EmoteSetID *string `json:"emote_set_id,omitempty"`
2931
OwnerID *string `json:"owner_id,omitempty"`
32+
Format []string `json:"format"`
33+
Scale []string `json:"scale"`
34+
ThemeMode []string `json:"theme_mode"`
3035
}
3136

3237
type EmotesImages struct {

internal/mock_api/endpoints/hype_train/hype_train.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ func getHypeTrainEvents(w http.ResponseWriter, r *http.Request) {
130130
events = append(events, h)
131131
}
132132

133-
bytes, _ := json.Marshal(models.APIResponse{Data: events})
133+
bytes, _ := json.Marshal(
134+
models.APIResponse{
135+
Data: events,
136+
Pagination: &models.APIPagination{}, // Since these are randomly generated, true pagination isn't implemented
137+
},
138+
)
134139
w.Write(bytes)
135140
}

internal/mock_api/endpoints/schedule/segment.go

+30-6
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
9292
}
9393
st, err := time.Parse(time.RFC3339, body.StartTime)
9494
if err != nil {
95-
mock_errors.WriteBadRequest(w, "Invalid timezone provided")
95+
mock_errors.WriteBadRequest(w, "Invalid/malformed start_time provided")
9696
return
9797
}
9898
if body.Timezone == "" {
@@ -104,9 +104,13 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
104104
mock_errors.WriteBadRequest(w, "Invalid timezone provided")
105105
return
106106
}
107+
108+
var isRecurring bool
109+
107110
if body.IsRecurring == nil {
108-
mock_errors.WriteBadRequest(w, "Missing is_recurring")
109-
return
111+
isRecurring = false
112+
} else {
113+
isRecurring = *body.IsRecurring
110114
}
111115

112116
if len(body.Title) > 140 {
@@ -129,7 +133,7 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
129133
ID: eventID,
130134
StartTime: st.UTC().Format(time.RFC3339),
131135
EndTime: et.UTC().Format(time.RFC3339),
132-
IsRecurring: *body.IsRecurring,
136+
IsRecurring: isRecurring,
133137
IsVacation: false,
134138
CategoryID: body.CategoryID,
135139
Title: body.Title,
@@ -142,7 +146,7 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
142146
mock_errors.WriteServerError(w, err.Error())
143147
return
144148
}
145-
if *body.IsRecurring {
149+
if isRecurring {
146150
// just a years worth of recurring events; mock data
147151
for i := 0; i < 52; i++ {
148152
weekAdd := (i + 1) * 7 * 24
@@ -154,7 +158,7 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
154158
ID: eventID,
155159
StartTime: startTime.Format(time.RFC3339),
156160
EndTime: endTime.Format(time.RFC3339),
157-
IsRecurring: *body.IsRecurring,
161+
IsRecurring: isRecurring,
158162
IsVacation: false,
159163
CategoryID: body.CategoryID,
160164
Title: body.Title,
@@ -176,6 +180,16 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
176180
return
177181
}
178182
b := dbr.Data.(database.Schedule)
183+
184+
// Remove timezone from JSON given in response
185+
for i := range b.Segments {
186+
b.Segments[i].Timezone = ""
187+
}
188+
189+
if b.Vacation.StartTime == "" && b.Vacation.EndTime == "" {
190+
b.Vacation = nil
191+
}
192+
179193
bytes, _ := json.Marshal(b)
180194
w.Write(bytes)
181195
}
@@ -314,6 +328,16 @@ func (e ScheduleSegment) patchSegment(w http.ResponseWriter, r *http.Request) {
314328
return
315329
}
316330
b = dbr.Data.(database.Schedule)
331+
332+
// Remove timezone from JSON given in response
333+
for i := range b.Segments {
334+
b.Segments[i].Timezone = ""
335+
}
336+
337+
if b.Vacation.StartTime == "" && b.Vacation.EndTime == "" {
338+
b.Vacation = nil
339+
}
340+
317341
bytes, _ := json.Marshal(b)
318342
w.Write(bytes)
319343
}

internal/models/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type APIResponse struct {
1414
}
1515

1616
type APIPagination struct {
17-
Cursor string `json:"cursor"`
17+
Cursor string `json:"cursor,omitempty"`
1818
}
1919

2020
type BitsLeaderboardDateRange struct {

0 commit comments

Comments
 (0)