Skip to content

Commit

Permalink
updating model
Browse files Browse the repository at this point in the history
  • Loading branch information
lleadbet committed Mar 18, 2021
1 parent 1996808 commit ca79191
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 44 deletions.
30 changes: 18 additions & 12 deletions internal/events/types/hype_train/hype_train_event.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package hype_train

import (
"encoding/json"
"time"

"github.com/twitchdev/twitch-cli/internal/events"
"github.com/twitchdev/twitch-cli/internal/models"
"github.com/twitchdev/twitch-cli/internal/util"
)

var transportsSupported = map[string]bool{
models.TransportWebSub: true,
models.TransportEventSub: true,
Expand All @@ -25,7 +28,9 @@ var triggerMapping = map[string]map[string]string{
"hype-train-end": "channel.hype_train.end",
},
}

type Event struct{}

func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEventResponse, error) {
var event []byte
var err error
Expand All @@ -36,6 +41,7 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
localTotal := util.RandomViewerCount()
localGoal := util.RandomViewerCount()
localProgress := (localTotal / localGoal)

switch params.Transport {
case models.TransportEventSub:
body := *&models.HypeTrainEventSubResponse{
Expand Down Expand Up @@ -77,8 +83,8 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
},
},
LastContribution: models.ContributionData{
TotalContribution: util.RandomViewerCount(),
TypeOfContribution: util.RandomType(),
TotalContribution: lastTotal,
TypeOfContribution: lastType,
UserWhoMadeContribution: lastUser,
UserNameWhoMadeContribution: "cli_user2",
UserLoginWhoMadeContribution: "cli_user2",
Expand Down Expand Up @@ -109,22 +115,22 @@ func (e Event) GenerateEvent(params events.MockEventParameters) (events.MockEven
Goal: localGoal,
Id: util.RandomGUID(),
LastContribution: models.ContributionData{
TotalContribution: lastTotal,
TypeOfContribution: lastType,
UserWhoMadeContribution: lastUser,
TotalContribution: lastTotal,
TypeOfContribution: lastType,
WebSubUser: lastUser,
},
Level: util.RandomViewerCount() % 4,
StartedAtTimestamp: util.GetTimestamp().Format(time.RFC3339),
TopContributions: []models.ContributionData{
{
TotalContribution: lastTotal,
TypeOfContribution: lastType,
UserWhoMadeContribution: lastUser,
TotalContribution: lastTotal,
TypeOfContribution: lastType,
WebSubUser: lastUser,
},
{
TotalContribution: util.RandomViewerCount(),
TypeOfContribution: util.RandomType(),
UserWhoMadeContribution: util.RandomUserID(),
TotalContribution: util.RandomViewerCount(),
TypeOfContribution: util.RandomType(),
WebSubUser: util.RandomUserID(),
},
},
Total: localTotal,
Expand Down Expand Up @@ -159,4 +165,4 @@ func (e Event) ValidTrigger(t string) bool {
}
func (e Event) GetTopic(transport string, trigger string) string {
return triggerMapping[transport][trigger]
}
}
65 changes: 33 additions & 32 deletions internal/models/hype_train.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
package models

type ContributionData struct{
TotalContribution int64 `json:"total"`
TypeOfContribution string `json:"type"`
UserWhoMadeContribution string `json:"user_id"`
UserNameWhoMadeContribution string `json:"user_name"`
UserLoginWhoMadeContribution string `json:"user_login"`
type ContributionData struct {
TotalContribution int64 `json:"total"`
TypeOfContribution string `json:"type"`
WebSubUser string `json:"user,omitempty"`
UserWhoMadeContribution string `json:"user_id,omitempty"`
UserNameWhoMadeContribution string `json:"user_name,omitempty"`
UserLoginWhoMadeContribution string `json:"user_login,omitempty"`
}

type HypeTrainWebSubEvent struct {
Expand All @@ -19,39 +20,39 @@ type HypeTrainWebSubEvent struct {
}

type HypeTrainWebsubEventData struct {
BroadcasterID string `json:"broadcaster_id"`
CooldownEndTimestamp string `json:"cooldown_end_time"`
ExpiresAtTimestamp string `json:"expires_at"`
Goal int64 `json:"goal,omitempty"`
Id string `json:"id,omitempty"`
LastContribution ContributionData `json:"last_contribution,omitempty"`
Level int64 `json:"level,omitempty"`
StartedAtTimestamp string `json:"started_at,omitempty"`
TopContributions []ContributionData `json:"top_contributions"`
Total int64 `json:"total"`
BroadcasterID string `json:"broadcaster_id"`
CooldownEndTimestamp string `json:"cooldown_end_time"`
ExpiresAtTimestamp string `json:"expires_at"`
Goal int64 `json:"goal,omitempty"`
Id string `json:"id,omitempty"`
LastContribution ContributionData `json:"last_contribution,omitempty"`
Level int64 `json:"level,omitempty"`
StartedAtTimestamp string `json:"started_at,omitempty"`
TopContributions []ContributionData `json:"top_contributions"`
Total int64 `json:"total"`
}

type HypeTrainWebSubResponse struct {
Data []HypeTrainWebSubEvent `json:"data"`
}

type HypeTrainEventSubResponse struct {
Subscription EventsubSubscription `json:"subscription"`
Event HypeTrainEventSubEvent `json:"event"`
Subscription EventsubSubscription `json:"subscription"`
Event HypeTrainEventSubEvent `json:"event"`
}

type HypeTrainEventSubEvent struct {
BroadcasterUserID string `json:"broadcaster_user_id"`
BroadcasterUserLogin string `json:"broadcaster_user_login"`
BroadcasterUserName string `json:"broadcaster_user_name"`
Level int64 `json:"level,omitempty"`
Total int64 `json:"total"`
Progress int64 `json:"progress,omitempty"`
Goal int64 `json:"goal,omitempty"`
TopContributions []ContributionData `json:"top_contributions"`
LastContribution ContributionData `json:"last_contribution,omitempty"`
StartedAtTimestamp string `json:"started_at,omitempty"`
ExpiresAtTimestamp string `json:"expires_at,omitempty"`
EndedAtTimestamp string `json:"ended_at,omitempty"`
CooldownEndsAtTimestamp string `json:"cooldown_ends_at,omitempty"`
}
BroadcasterUserID string `json:"broadcaster_user_id"`
BroadcasterUserLogin string `json:"broadcaster_user_login"`
BroadcasterUserName string `json:"broadcaster_user_name"`
Level int64 `json:"level,omitempty"`
Total int64 `json:"total"`
Progress int64 `json:"progress,omitempty"`
Goal int64 `json:"goal,omitempty"`
TopContributions []ContributionData `json:"top_contributions"`
LastContribution ContributionData `json:"last_contribution,omitempty"`
StartedAtTimestamp string `json:"started_at,omitempty"`
ExpiresAtTimestamp string `json:"expires_at,omitempty"`
EndedAtTimestamp string `json:"ended_at,omitempty"`
CooldownEndsAtTimestamp string `json:"cooldown_ends_at,omitempty"`
}

0 comments on commit ca79191

Please sign in to comment.