challonge

package module
v0.0.0-...-03aa8d4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2015 License: GPL-2.0 Imports: 8 Imported by: 0

README

go-challonge

Golang API client for retrieving (and potentially updating) tournaments in Challonge.

Install

$ go get github.com/aspic/go-challonge

Usage

Load and initialize
package main
import "github.com/aspic/go-challonge"

fun main() {
    client := challonge.New("challonge-user", "challonge-key")
}
Tournaments

Retrieve tournament

t, err := client.NewTournamentRequest("tournament").Get()

if err != nil {
    // invalid tournament name, unable to reach host etc.
    log.Fatal("unable to retrieve tournament ", err)
}

Retrieve tournament with matches and participants

t, err := client.NewTournamentRequest("tournament").
        WithMatches().
        WithParticipants().
        Get()

To re-fetch a tournament

newTournament, err := oldTournament.Update().Get()

Create a new tournament. Requires name, url, subdomain (can be an empty string), whether to be open or not and tournament type (defaults to single for empty string).

t, err := client.CreateTournament("name", "url", "subdomain", true, "single")
Matches

Get a list of all open matches:

matches := t.GetOpenMatches()

Get a specific match:

match := t.GetMatch(id)
Participants

Add participant to tournament. Misc-field is an API specific field which can be used to identify users.

p, err := t.AddParticipant("name", "misc")

Remove a participant

// by name
err := t.RemoveParticipant("name")
// by id
err := t.RemoveParticipantById(id)

Documentation

Index

Constants

View Source
const (
	API_VERSION = "v1"

	STATE_OPEN = "open"
	STATE_ALL  = "all"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	Tournament  *Tournament  `json:"tournament"`
	Participant *Participant `json:"participant"`
	Match       Match        `json:"match"`

	Errors []string `json:"errors"`
}

type Client

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

func New

func New(user string, key string) *Client

func (*Client) CreateTournament

func (c *Client) CreateTournament(name string, subUrl string, domain string, open bool, tType string) (*Tournament, error)

* creates a new tournament

func (*Client) Debug

func (c *Client) Debug()

func (*Client) NewTournamentRequest

func (c *Client) NewTournamentRequest(id string) *TournamentRequest

func (*Client) Print

func (c *Client) Print()

type Match

type Match struct {
	Id             int    `json:"id"`
	Identifier     string `json:"identifier"`
	State          string `json:"state"`
	PlayerOneId    int    `json:"player1_id"`
	PlayerTwoId    int    `json:"player2_id"`
	PlayerOneScore int
	PlayerTwoScore int
	UpdatedAt      *time.Time `json:"updated_at,omitempty"`

	WinnerId int `json:"winner_id"`

	PlayerOne *Participant
	PlayerTwo *Participant
	Winner    *Participant

	Scores string `json:"scores_csv"`
}

func DiffMatches

func DiffMatches(matches1 []*Match, matches2 []*Match) []*Match

func (*Match) ResolveParticipants

func (m *Match) ResolveParticipants(t *Tournament)

type MatchItem

type MatchItem struct {
	Match *Match `json:"match"`
}

type Participant

type Participant struct {
	Id         int    `json:"id"`
	Name       string `json:"display_name"`
	Misc       string `json:"misc"`
	Seed       int    `json:"seed"`
	Wins       int
	Losses     int
	TotalScore int
}

func (*Participant) Lose

func (p *Participant) Lose()

func (*Participant) Win

func (p *Participant) Win()

type ParticipantItem

type ParticipantItem struct {
	Participant Participant `json:"participant"`
}

type Tournament

type Tournament struct {
	Name              string     `json:"name"`
	Id                int        `json:"id"`
	Url               string     `json:"url"`
	FullUrl           string     `json:"full_challonge_url"`
	State             string     `json:"state"`
	SubDomain         string     `json:"subdomain"`
	ParticipantsCount int        `json:"participants_count"`
	StartedAt         *time.Time `json:"started_at,mitempty"`
	UpdatedAt         *time.Time `json:"updated_at,omitempty"`
	Type              string     `json:"tournament_type"`
	Description       string     `json:"description"`
	GameName          string     `json:"game_name"`
	Progress          int        `json:"progress_meter"`

	SubUrl string `json:"sub_url"`

	ParticipantItems []*ParticipantItem `json:"participants,omitempty"`
	MatchItems       []*MatchItem       `json:"matches,omitempty"`

	Participants []*Participant `json:"resolved_participants"`
	Matches      []*Match       `json:"resolved_matches"`
}

func (*Tournament) AddParticipant

func (t *Tournament) AddParticipant(name string, misc string) (*Participant, error)

* adds participant to tournament

func (*Tournament) GetMatch

func (t *Tournament) GetMatch(id int) *Match

* returns match with resolved participants

func (*Tournament) GetMatches

func (t *Tournament) GetMatches() []*Match

* returns all matches for tournament

func (*Tournament) GetOpenMatchForParticipant

func (t *Tournament) GetOpenMatchForParticipant(p *Participant) *Match

func (*Tournament) GetOpenMatches

func (t *Tournament) GetOpenMatches() []*Match

* returns all open matches

func (*Tournament) GetParticipant

func (t *Tournament) GetParticipant(id int) *Participant

func (*Tournament) GetParticipantByMisc

func (t *Tournament) GetParticipantByMisc(misc string) *Participant

func (*Tournament) GetParticipantByName

func (t *Tournament) GetParticipantByName(name string) *Participant

func (*Tournament) GetUrl

func (t *Tournament) GetUrl() string

* returns "domain-url" or "url"

func (*Tournament) IsCompleted

func (t *Tournament) IsCompleted() bool

func (*Tournament) RemoveParticipant

func (t *Tournament) RemoveParticipant(name string) error

* removes participant from tournament

func (*Tournament) RemoveParticipantById

func (t *Tournament) RemoveParticipantById(id int) error

* removes participant by id

func (*Tournament) Start

func (t *Tournament) Start() error

func (*Tournament) SubmitMatch

func (t *Tournament) SubmitMatch(m *Match) (*Match, error)

func (*Tournament) UnmarshalJSON

func (t *Tournament) UnmarshalJSON(b []byte) (err error)

func (*Tournament) Update

func (t *Tournament) Update() *TournamentRequest

type TournamentItem

type TournamentItem struct {
	Tournament Tournament `json:"tournament"`
}

* items to flatten json structure

type TournamentRequest

type TournamentRequest struct {
	Id     string
	Params map[string]string
	// contains filtered or unexported fields
}

func (*TournamentRequest) Get

func (r *TournamentRequest) Get() (*Tournament, error)

func (*TournamentRequest) WithMatches

func (r *TournamentRequest) WithMatches() *TournamentRequest

func (*TournamentRequest) WithParticipants

func (r *TournamentRequest) WithParticipants() *TournamentRequest

Jump to

Keyboard shortcuts

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