Skip to content

Commit

Permalink
Add type version support for subscribe requests (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Sage <24928223+dnsge@users.noreply.github.com>
  • Loading branch information
Satont and dnsge authored Mar 11, 2023
1 parent f246a96 commit c6b2c5f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"context"
"encoding/json"
"fmt"
esb "github.com/dnsge/twitch-eventsub-bindings"
"net/http"
"net/url"
"time"

esb "github.com/dnsge/twitch-eventsub-bindings"
)

const (
Expand All @@ -26,6 +27,8 @@ type SubRequest struct {
Callback string
// The HMAC secret used to verify the event data.
Secret string
// The subscription type version.
Version string
}

type Status string
Expand All @@ -45,11 +48,12 @@ const (
// TwitchError describes an error from the Twitch API.
//
// For example:
// {
// "error": "Unauthorized",
// "status": 401,
// "message": "Invalid OAuth token"
// }
//
// {
// "error": "Unauthorized",
// "status": 401,
// "message": "Invalid OAuth token"
// }
type TwitchError struct {
ErrorText string `json:"error"`
Status int `json:"status"`
Expand Down Expand Up @@ -130,9 +134,14 @@ func (s *SubClient) do(req *http.Request) (*http.Response, error) {

// Subscribe creates a new Webhook subscription.
func (s *SubClient) Subscribe(ctx context.Context, srq *SubRequest) (*esb.RequestStatus, error) {
// set default version to 1, so we can omit that parameter in request for backward compatibility
if srq.Version == "" {
srq.Version = "1"
}

reqJSON := esb.Request{
Type: srq.Type,
Version: "1",
Version: srq.Version,
Condition: srq.Condition,
Transport: esb.Transport{
Method: "webhook",
Expand Down

0 comments on commit c6b2c5f

Please sign in to comment.