forked from nicklaw5/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add get / create / end prediction features
Add few fix on polls keys End of second part of 2021‑05‑03 changelog
- Loading branch information
Showing
7 changed files
with
484 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Predictions Documentation | ||
|
||
## Get Predictions | ||
|
||
This is an example of how to get predictions. | ||
|
||
```go | ||
client, err := helix.NewClient(&helix.Options{ | ||
ClientID: "your-client-id", | ||
}) | ||
if err != nil { | ||
// handle error | ||
} | ||
|
||
resp, err := client.GetPredictions(&helix.PredictionsParams{ | ||
BroadcasterID: "145328278", | ||
}) | ||
if err != nil { | ||
// handle error | ||
} | ||
|
||
fmt.Printf("%+v\n", resp) | ||
``` | ||
|
||
## Create Prediction | ||
|
||
This is an example of how to create a prediction. | ||
|
||
```go | ||
client, err := helix.NewClient(&helix.Options{ | ||
ClientID: "your-client-id", | ||
}) | ||
if err != nil { | ||
// handle error | ||
} | ||
|
||
resp, err := client.CreatePrediction(&helix.CreatePredictionParams{ | ||
BroadcasterID: "145328278", | ||
Title: "Test", | ||
Outcomes: []helix.PredictionChoiceParam{ | ||
helix.PredictionChoiceParam{ Title: "choice 1" }, | ||
helix.PredictionChoiceParam{ Title: "choice 2" }, | ||
}, | ||
PredictionWindow: 300, | ||
}) | ||
if err != nil { | ||
// handle error | ||
} | ||
|
||
fmt.Printf("%+v\n", resp) | ||
``` | ||
|
||
## End Prediction | ||
|
||
This is an example of how to end a prediction. | ||
|
||
```go | ||
client, err := helix.NewClient(&helix.Options{ | ||
ClientID: "your-client-id", | ||
}) | ||
if err != nil { | ||
// handle error | ||
} | ||
|
||
resp, err := client.EndPrediction(&helix.EndPredictionParams{ | ||
BroadcasterID: "145328278", | ||
ID: "c36165d9-d5f5-4f81-ab56-17e7347110c8", | ||
Status: "RESOLVED", | ||
WinningOutcomeID: "d0c0194a-6016-4ca3-b8eb-0c61183758ab", | ||
}) | ||
if err != nil { | ||
// handle error | ||
} | ||
|
||
fmt.Printf("%+v\n", resp) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package helix | ||
|
||
// Prediction ... same struct as Poll | ||
type Prediction struct { | ||
ID string `json:"id"` | ||
BroadcasterUserID string `json:"broadcaster_id"` | ||
BroadcasterUserLogin string `json:"broadcaster_login"` | ||
BroadcasterUserName string `json:"broadcaster_name"` | ||
Title string `json:"title"` | ||
WinningOutcomeID string `json:"winning_outcome_id"` | ||
Outcomes []Outcomes `json:"outcomes"` | ||
PredictionWindow int `json:"prediction_window"` | ||
Status string `json:"status"` | ||
CreatedAt Time `json:"created_at"` | ||
EndedAt Time `json:"ended_at"` | ||
LockedAt Time `json:"locked_at"` | ||
} | ||
|
||
// Outcomes ... | ||
type Outcomes struct { | ||
ID string `json:"id"` | ||
Title string `json:"title"` | ||
Users int `json:"users"` | ||
ChannelPoints int `json:"channel_points"` | ||
TopPredictors []TopPredictor `json:"top_predictors"` | ||
Color string `json:"color"` | ||
} | ||
|
||
// TopPredictor ... | ||
type TopPredictor struct { | ||
UserID string `json:"user_id"` | ||
UserName string `json:"user_name"` | ||
UserLogin string `json:"user_login"` | ||
ChannelPointsUsed int `json:"channel_points_used"` | ||
ChannelPointsWon int `json:"channel_points_won"` | ||
} | ||
|
||
// ManyPredictions ... | ||
type ManyPredictions struct { | ||
Predictions []Prediction `json:"data"` | ||
Pagination Pagination `json:"pagination"` | ||
} | ||
|
||
// PredictionsResponse ... | ||
type PredictionsResponse struct { | ||
ResponseCommon | ||
Data ManyPredictions | ||
} | ||
|
||
// PredictionsParams ... | ||
type PredictionsParams struct { | ||
BroadcasterID string `query:"broadcaster_id"` | ||
ID string `query:"id"` | ||
After string `query:"after"` | ||
First string `query:"first` | ||
} | ||
|
||
// GetPredictionsResponse ... | ||
type GetPredictionsResponse struct { | ||
ResponseCommon | ||
Data ManyPredictions | ||
} | ||
|
||
// GetPredictions ... | ||
// Required scope: channel:read:predictions | ||
func (c *Client) GetPredictions(params *PredictionsParams) (*PredictionsResponse, error) { | ||
resp, err := c.get("/predictions", &ManyPredictions{}, params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
predictions := &PredictionsResponse{} | ||
resp.HydrateResponseCommon(&predictions.ResponseCommon) | ||
predictions.Data.Predictions = resp.Data.(*ManyPredictions).Predictions | ||
predictions.Data.Pagination = resp.Data.(*ManyPredictions).Pagination | ||
|
||
return predictions, nil | ||
} | ||
|
||
// CreatePredictionParams ... | ||
type CreatePredictionParams struct { | ||
BroadcasterID string `json:"broadcaster_id"` | ||
Title string `json:"title"` // Maximum: 45 characters. | ||
Outcomes []PredictionChoiceParam `json:"outcomes"` // 2 choices mandatory | ||
PredictionWindow int `json:"prediction_window"` // Minimum: 1. Maximum: 1800. | ||
} | ||
|
||
// PredictionChoiceParam ... | ||
type PredictionChoiceParam struct { | ||
Title string `json:"title"` // Maximum: 25 characters. | ||
} | ||
|
||
// CreatePrediction ... | ||
// Required scope: channel:manage:predictions | ||
func (c *Client) CreatePrediction(params *CreatePredictionParams) (*PredictionsResponse, error) { | ||
resp, err := c.postAsJSON("/predictions", &ManyPredictions{}, params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
predictions := &PredictionsResponse{} | ||
resp.HydrateResponseCommon(&predictions.ResponseCommon) | ||
predictions.Data.Predictions = resp.Data.(*ManyPredictions).Predictions | ||
predictions.Data.Pagination = resp.Data.(*ManyPredictions).Pagination | ||
|
||
return predictions, nil | ||
} | ||
|
||
// EndPredictionParams ... | ||
type EndPredictionParams struct { | ||
BroadcasterID string `json:"broadcaster_id"` | ||
ID string `json:"id"` | ||
Status string `json:"status"` | ||
WinningOutcomeID string `json:"winning_outcome_id"` | ||
} | ||
|
||
// EndPrediction ... | ||
// Required scope: channel:manage:predictions | ||
func (c *Client) EndPrediction(params *EndPredictionParams) (*PredictionsResponse, error) { | ||
resp, err := c.patchAsJSON("/predictions", &ManyPredictions{}, params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
predictions := &PredictionsResponse{} | ||
resp.HydrateResponseCommon(&predictions.ResponseCommon) | ||
predictions.Data.Predictions = resp.Data.(*ManyPredictions).Predictions | ||
predictions.Data.Pagination = resp.Data.(*ManyPredictions).Pagination | ||
|
||
return predictions, nil | ||
} | ||
|
||
|
Oops, something went wrong.