twitch

package module
v0.0.0-...-f5168a8 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2019 License: MIT Imports: 10 Imported by: 0

README

go-new-twitch

Description

I decided to write this api wrapper because there were none for the New Twitch Api and all the other ones are fairly outdated.

It's still pretty early in development and not all api endpoints are added.

There are still a lot of endpoints added to the API and they might not immediately be added here but I'll try to keep this as updated as possible.

Usage

Create a new Twitch Application here to get a client id. You can then create a new twitch client with the NewClient method and start using all the methods.

Documentation can be found here https://godoc.org/github.com/Onestay/go-new-twitch and the oficiall New Twich API reference here https://dev.twitch.tv/docs/api/reference

Example

package main
import (
	"fmt"
	twitch "github.com/Onestay/go-new-twitch"
)

func main() {
	client := twitch.NewClient("<your client_id>")
    
    users, err := client.GetUsersByLogin("lirik")
    if err != nil {
		fmt.Printf("Error getting twitch user: %v", err)
	}
    
    fmt.Println(users[0].Login)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ClientID string
	// contains filtered or unexported fields
}

Client represents a client to interact with the twitch API

func NewClient

func NewClient(cid string) *Client

NewClient will initialize a new client for the twitch api

func (Client) GetClips

func (c Client) GetClips(i GetClipsInput) ([]ClipData, *Pagination, error)

GetClips will get a list of clips The url query parameters are defined by the GetClipsInput struct

func (Client) GetGameByName

func (c Client) GetGameByName(names ...string) ([]GameData, error)

GetGameByName will get info on games by name. Game name. The name must be an exact match. For instance, “Pokemon” will not return a list of Pokemon games; instead, query the specific Pokemon game(s) in which you are interested. This is a limitation by the twitch api At most 100 name values can be specified.

func (Client) GetGamesByID

func (c Client) GetGamesByID(ids ...string) ([]GameData, error)

GetGamesByID will get info on games by id. At most 100 id values can be specified

func (Client) GetStreams

func (c Client) GetStreams(i GetStreamsInput) ([]StreamData, error)

GetStreams will get a list of live streams The url query parameter are defined by the GetStreamsInput struct

func (Client) GetUsersByID

func (c Client) GetUsersByID(ids ...string) ([]UserData, error)

GetUsersByID gets information about one or more specified Twitch users. Users are identified by ID. Limit are 100 users per request

func (Client) GetUsersByLogin

func (c Client) GetUsersByLogin(names ...string) ([]UserData, error)

GetUsersByLogin gets information about one or more specified Twitch users. Users are identified by login name. Limit are 100 users per request.

type ClipData

type ClipData struct {
	// ID of the clip being queried.
	ID string `json:"id"`
	// User ID of the stream from which the clip was created.
	BroadcasterID string `json:"broadcaster_id"`
	// Display name corresponding to broadcaster_id.
	BroadcasterName string `json:"broadcaster_name"`
	// Date when the clip was created.
	CreatedAt string `json:"created_at"`
	// ID of the user who created the clip.
	CreatorID string `json:"creator_id"`
	// Display name corresponding to creator_id.
	CreatorName string `json:"creator_name"`
	// URL to embed the clip.
	EmbedURL string `json:"embed_url"`
	// ID of the game assigned to the stream when the clip was created.
	GameID string `json:"game_id"`
	// Language of the stream from which the clip was created.
	Language string `json:"language"`
	// URL of the clip thumbnail.
	ThumbnailURL string `json:"thumbnail_url"`
	// Title of the clip.
	Title string `json:"title"`
	// URL where the clip can be viewed.
	URL string `json:"url"`
	// ID of the video from which the clip was created.
	VideoID string `json:"video_id"`
	// Number of times the clip has been viewed.
	ViewCount uint `json:"view_count"`
}

ClipData represents the data in a single clip

type GameData

type GameData struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	BoxArtURL string `json:"box_art_url"`
}

GameData represents the data of a single game

type GetClipsInput

type GetClipsInput struct {
	// Cursor for forward pagination: tells the server where to start fetching the next set of results, in a multi-page response. This applies only to queries specifying broadcaster_id or game_id. The cursor value specified here is from the pagination response field of a prior query.
	After string `url:"after"`
	// Cursor for backward pagination: tells the server where to start fetching the next set of results, in a multi-page response. This applies only to queries specifying broadcaster_id or game_id. The cursor value specified here is from the pagination response field of a prior query.
	Before string `url:"before"`
	// ID of the broadcaster for whom clips are returned. The number of clips returned is determined by the first query-string parameter (default: 20). Results are ordered by view count.
	BroadcasterID string `url:"broadcaster_id"`
	// Ending date/time for returned clips, in RFC3339 format. (Note that the seconds value is ignored.) If this is specified, started_at also must be specified; otherwise, the time period is ignored.
	EndedAt string `url:"ended_at"`
	// Maximum number of objects to return. Maximum: 100. Default: 20.
	First uint `url:"first"`
	// ID of the game for which clips are returned. The number of clips returned is determined by the first query-string parameter (default: 20). Results are ordered by view count.
	GameID string `url:"game_id"`
	// ID of the clip being queried. Limit: 100.
	ID string `url:"id"`
	// Starting date/time for returned clips, in RFC3339 format. (Note that the seconds value is ignored.) If this is specified, ended_at also should be specified; otherwise, the ended_at date/time will be 1 week after the started_at value.
	StartedAt string `url:"started_id"`
}

GetClipsInput represents the query string parameters to get clips https://dev.twitch.tv/docs/api/reference#get-clips

type GetStreamsInput

type GetStreamsInput struct {
	// Cursor for forward pagination: tells the server where to start fetching the next set of results, in a multi-page response.
	After string `url:"after"`
	// Cursor for backward pagination: tells the server where to start fetching the next set of results, in a multi-page response.
	Before string `url:"before"`
	// Returns streams in a specified community ID. You can specify up to 100 IDs.
	CommunityID []string `url:"community_id"`
	// Maximum number of objects to return. Maximum: 100. Default: 20.
	First int `url:"first"`
	// Returns streams broadcasting a specified game ID. You can specify up to 100 IDs.
	GameID []string `url:"game_id"`
	// Stream language. You can specify up to 100 languages.
	Language []string `url:"language"`
	// Stream type: "all", "live", "vodcast". Default: "all".
	Type string `url:"type"`
	// Returns streams broadcast by one or more specified user IDs. You can specify up to 100 IDs.
	UserID []string `url:"user_id"`
	// Returns streams broadcast by one or more specified user login names. You can specify up to 100 names.
	UserLogin []string `url:"user_login"`
}

GetStreamsInput represents the query string parameters to get streams https://dev.twitch.tv/docs/api/reference#get-streams

type Pagination

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

Pagination data returned from helix paged requests

type StreamData

type StreamData struct {
	ID           string    `json:"id"`
	UserID       string    `json:"user_id"`
	GameID       string    `json:"game_id"`
	CommunityIds []string  `json:"community_ids"`
	Type         string    `json:"type"`
	Title        string    `json:"title"`
	ViewerCount  int       `json:"viewer_count"`
	StartedAt    time.Time `json:"started_at"`
	Language     string    `json:"language"`
	ThumbnailURL string    `json:"thumbnail_url"`
}

StreamData represents the data a single stream

type UserData

type UserData struct {
	ID              string `json:"id"`
	Login           string `json:"login"`
	DisplayName     string `json:"display_name"`
	Type            string `json:"type"`
	BroadcasterType string `json:"broadcaster_type"`
	Description     string `json:"description"`
	ProfileImageURL string `json:"profile_image_url"`
	OfflineImageURL string `json:"offline_image_url"`
	ViewCount       int    `json:"view_count"`
	Email           string `json:"email"`
}

UserData struct represents a user as defined by the twitch api

Jump to

Keyboard shortcuts

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