helix

package
v4.0.0-...-ac11496 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ChannelAvatarQuery       = PersistedQuerySpec{OperationName: "ChannelAvatar", Sha256Hash: "84ed918aaa9aaf930e58ac81733f552abeef8ac26c0117746865428a7e5c8ab0"}
	PlaybackAccessTokenQuery = PersistedQuerySpec{OperationName: "VideoAccessToken_Clip", Sha256Hash: "36b89d2507fce29e5ca551df756d27c1cfe079e2609642b4390aa4c35796eb11"}
	HomeShelfVideos          = PersistedQuerySpec{OperationName: "HomeShelfVideos", Sha256Hash: "d61bcfa277e9c3839fc468031eaf5a73c94726ff8d3155d28fb68c1505b5ab88"}
)

Functions

func ArgumentToKeyPart

func ArgumentToKeyPart(keyBuilder *strings.Builder, argument any)

func SliceArgumentToKeyPart

func SliceArgumentToKeyPart(keyBuilder *strings.Builder, value *reflect.Value)

Types

type AppTokenResponse

type AppTokenResponse struct {
	AccessToken string `json:"access_token,omitempty"`
	ExpiresIn   int    `json:"expires_in,omitempty"`
	TokenType   string `json:"token_type,omitempty"`
}

type AvatarQueryPayload

type AvatarQueryPayload struct {
	User struct {
		ID        string `json:"ID,omitempty"`
		Followers struct {
			TotalCount int `json:"totalCount,omitempty"`
		} `json:"followers"`
		IsPartner       bool   `json:"isPartner,omitempty"`
		PrimaryColorHex string `json:"primaryColorHex,omitempty"`
	}
}

type Client

type Client struct {
	Client         http.Client
	ClientID       string
	ClientSecret   string
	AppToken       string
	TokenExpires   time.Time
	LastTokenCheck time.Time
	Redis          *redis.Client
}

func NewClient

func NewClient(clientID string, clientSecret string) *Client

func (*Client) CreateAppToken

func (client *Client) CreateAppToken() error

func (*Client) DoGQL

func (client *Client) DoGQL(queries ...PersistedQuery) ([]PersistedQueryResponse, error)

func (*Client) EnableCache

func (client *Client) EnableCache(redisAddress string, redisDatabase int)

func (*Client) EnsureAppToken

func (client *Client) EnsureAppToken() error

func (*Client) FetchCached

func (client *Client) FetchCached(key string, target any) bool

func (*Client) GetAllClipsForBroadcaster

func (client *Client) GetAllClipsForBroadcaster(broadcasterID string) ([]Clip, error)

func (*Client) GetChannelAvatar

func (client *Client) GetChannelAvatar(login string) (*AvatarQueryPayload, error)

func (*Client) GetClipPlaybackUrl

func (client *Client) GetClipPlaybackUrl(clipSlug string) (string, error)

func (*Client) GetClipsForBroadcaster

func (client *Client) GetClipsForBroadcaster(broadcasterID string) (*ClipsResponse, error)

func (*Client) GetClipsForBroadcasterWithinTimeframe

func (client *Client) GetClipsForBroadcasterWithinTimeframe(broadcasterID string, startTime time.Time, endTime time.Time) (*ClipsResponse, error)

func (*Client) GetUsersByIDs

func (client *Client) GetUsersByIDs(userIDs ...string) (*UsersResponse, error)

func (*Client) GetUsersByLogins

func (client *Client) GetUsersByLogins(logins ...string) (*UsersResponse, error)

func (*Client) GetVideoHomeShelfForLogin

func (client *Client) GetVideoHomeShelfForLogin(login string) (*HomeShelfVideoPayload, error)

func (*Client) IsAppTokenValid

func (client *Client) IsAppTokenValid() (bool, error)

func (*Client) MakeGetRequest

func (client *Client) MakeGetRequest(endpoint string, parameters url.Values, headers url.Values, returnObject any) (int, error)

func (*Client) MakeHttpRequest

func (client *Client) MakeHttpRequest(method string, endpoint string, parameters url.Values, headers url.Values, body io.Reader, returnObject any) (int, error)

func (*Client) MakePostRequest

func (client *Client) MakePostRequest(endpoint string, parameters url.Values, headers url.Values, payload io.Reader, returnObject any) (int, error)

func (*Client) MakeRedisKey

func (client *Client) MakeRedisKey(arguments ...any) string

func (*Client) SetCached

func (client *Client) SetCached(key string, data any, ttl time.Duration)

type Clip

type Clip struct {
	ID              string  `json:"id,omitempty"`
	Url             string  `json:"url,omitempty"`
	EmbedUrl        string  `json:"embed_url,omitempty"`
	BroadcasterId   string  `json:"broadcaster_id,omitempty"`
	BroadcasterName string  `json:"broadcaster_name,omitempty"`
	CreatorId       string  `json:"creator_id,omitempty"`
	CreatorName     string  `json:"creator_name,omitempty"`
	VideoID         string  `json:"video_id,omitempty"`
	GameID          string  `json:"game_id,omitempty"`
	Language        string  `json:"language,omitempty"`
	Title           string  `json:"title,omitempty"`
	ViewCount       int     `json:"view_count,omitempty"`
	CreatedAt       string  `json:"created_at,omitempty"`
	ThumbnailUrl    string  `json:"thumbnail_url,omitempty"`
	Duration        float64 `json:"duration,omitempty"`
	VodOffset       int     `json:"vod_offset,omitempty"`
}

type ClipsQueryPayload

type ClipsQueryPayload struct {
	Clip struct {
		PlaybackAccessToken struct {
			Signature string `json:"signature,omitempty"`
			Value     string `json:"value,omitempty"`
		} `json:"playbackAccessToken"`
	} `json:"clip"`
}

type ClipsResponse

type ClipsResponse struct {
	Data []Clip `json:"data"`
	PaginationMeta
	ErrorMeta
}

type ErrorMeta

type ErrorMeta struct {
	Error   string `json:"error,omitempty"`
	Status  int    `json:"status,omitempty"`
	Message string `json:"message,omitempty"`
}

func (*ErrorMeta) ToError

func (meta *ErrorMeta) ToError() error

type HomeShelfVideoPayload

type HomeShelfVideoPayload struct {
	User struct {
		ID           string `json:"ID,omitempty"`
		VideoShelves struct {
			Edges []struct {
				Node struct {
					ID          string `json:"ID,omitempty"`
					Title       string `json:"title,omitempty"`
					Type        string `json:"type,omitempty"`
					Description string `json:"description,omitempty"`
					Items       []struct {
						Broadcaster struct {
							ID              string `json:"ID,omitempty"`
							Login           string `json:"login,omitempty"`
							DisplayName     string `json:"displayName,omitempty"`
							PrimaryColorHex string `json:"primaryColorHex,omitempty"`
							ProfileImageURL string `json:"profileImageURL,omitempty"`
						} `json:"broadcaster"`
						ClipGame struct {
							ID          string `json:"ID,omitempty"`
							Name        string `json:"name,omitempty"`
							DisplayName string `json:"displayName,omitempty"`
							BoxArtURL   string `json:"boxArtURL,omitempty"`
						} `json:"clipGame"`
						ClipTitle     string `json:"clipTitle,omitempty"`
						ClipViewCount int    `json:"clipViewCount,omitempty"`
						CreatedAt     string `json:"createdAt,omitempty"`
						Curator       struct {
							ID          string `json:"ID,omitempty"`
							Login       string `json:"login,omitempty"`
							DisplayName string `json:"displayName,omitempty"`
						} `json:"curator"`
						DurationSeconds int    `json:"durationSeconds,omitempty"`
						ID              string `json:"ID,omitempty"`
						IsFeatured      bool   `json:"isFeatured,omitempty"`
						Slug            string `json:"slug,omitempty"`
						ThumbnailURL    string `json:"thumbnailURL,omitempty"`
					} `json:"items,omitempty"`
				} `json:"node"`
			} `json:"edges"`
		} `json:"videoShelves"`
	} `json:"user"`
}

type Pagination

type Pagination struct {
	Cursor string `json:"cursor"`
}

type PaginationMeta

type PaginationMeta struct {
	Pagination Pagination `json:"pagination"`
}

type PersistedQuery

type PersistedQuery struct {
	OperationName string                   `json:"operationName"`
	Extensions    PersistedQueryExtensions `json:"extensions"`
	Variables     map[string]any           `json:"variables"`
}

type PersistedQueryExtension

type PersistedQueryExtension struct {
	Sha256Hash string `json:"sha256Hash"`
	Version    int    `json:"version"`
}

type PersistedQueryExtensions

type PersistedQueryExtensions struct {
	PersistedQuery PersistedQueryExtension `json:"persistedQuery"`
}

type PersistedQueryResponse

type PersistedQueryResponse struct {
	Data       any `json:"data,omitempty"`
	Extensions struct {
		DurationMilliseconds int
		OperationName        string `json:"operationName,omitempty"`
		RequestID            string `json:"requestID,omitempty"`
	} `json:"extensions,omitempty"`
}

func (*PersistedQueryResponse) Bind

func (response *PersistedQueryResponse) Bind(target any) error

type PersistedQuerySpec

type PersistedQuerySpec struct {
	OperationName string
	Sha256Hash    string
}

func (*PersistedQuerySpec) Prepare

func (query *PersistedQuerySpec) Prepare(variables map[string]any) PersistedQuery

type PlaybackAccessToken

type PlaybackAccessToken struct {
	Authorization struct {
		Forbidden bool   `json:"forbidden,omitempty"`
		Reason    string `json:"reason,omitempty"`
	} `json:"authorization"`
	ClipUri  string `json:"clip_uri,omitempty"`
	DeviceID string `json:"device_id,omitempty"`
	Expires  int    `json:"expires,omitempty"`
	UserID   string `json:"user_id,omitempty"`
	Version  int    `json:"version,omitempty"`
}

type User

type User struct {
	ID              string `json:"id,omitempty"`
	Login           string `json:"login,omitempty"`
	DisplayName     string `json:"display_name,omitempty"`
	Type            string `json:"type,omitempty"`
	BroadcasterType string `json:"broadcaster_type,omitempty"`
	Description     string `json:"description,omitempty"`
	ProfileImageUrl string `json:"profile_image_url,omitempty"`
	OfflineImageUrl string `json:"offline_image_url,omitempty"`
	ViewCould       int    `json:"view_could,omitempty"`
	Email           string `json:"email,omitempty"`
	CreatedAt       string `json:"created_at,omitempty"`
}

type UsersResponse

type UsersResponse struct {
	Data []User `json:"data"`
	ErrorMeta
}

type V

type V map[string]any

type ValidationResponse

type ValidationResponse struct {
	ClientID  string   `json:"clientID,omitempty"`
	Login     string   `json:"login,omitempty"`
	Scopes    []string `json:"scopes,omitempty"`
	UserID    string   `json:"userID,omitempty"`
	ExpiresIn int      `json:"expiresIn,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL