clash

package module
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2018 License: MIT Imports: 7 Imported by: 0

README

go-clash

API bindings for the public Clash Royale API, for Go.

https://developer.clashroyale.com/#/documentation

These bindings provide time.Time castings for the (non-standard) datestamps. Such properties are still accessible as strings, though you are more likely to appreciate the helper methods that parse these timestamps into date values.

Usage

client := clash.NewClient("Your bearer token"),

player := client.Player("9PLJLPQ8G") // "#9PLJLPQ8G" is also fine

chests, _ := player.UpcomingChests()

for _, chest := range chests.Items {
    fmt.Printf("Chest %s is %d drops away!\n", chest.Name, chest.Index)
}

Error handling

Any issues with HTTP transport or response codes >=400 will be reflected in the returned error.

Cast the error to an API error structure. If casting wasn't successful, the error must be from net/http.

if err, ok := err.(clash.APIError); ok {
    // handle a clash API error response
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TimeLayout = "20060102T150405.000Z"

This is the time format used by time fields -- we'll be using it to provide cleaner APIs.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Response *http.Response
	Body     *ErrorBody
}

func (*APIError) Error

func (e *APIError) Error() string

type Achievement

type Achievement struct {
	Name   string `json:"name"`
	Stars  int    `json:"stars"`
	Value  int    `json:"value"`
	Target int    `json:"target"`
	Info   string `json:"info"`
}

type Arena

type Arena struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type BattleLogEntries

type BattleLogEntries []BattleLogEntry

type BattleLogEntry

type BattleLogEntry struct {
	Type          string            `json:"type"`
	RawBattleTime string            `json:"battleTime"`
	Arena         Arena             `json:"arena"`
	GameMode      GameMode          `json:"gameMode"`
	DeckSelection string            `json:"deckSelection"`
	Team          []BattleLogPlayer `json:"team"`
	Opponent      []BattleLogPlayer `json:"opponent"`
}

func (*BattleLogEntry) BattleTime

func (b *BattleLogEntry) BattleTime() time.Time

type BattleLogPlayer

type BattleLogPlayer struct {
	Tag              string `json:"tag"`
	Name             string `json:"name"`
	StartingTrophies int    `json:"startingTrophies"`
	TrophyChange     int    `json:"trophyChange"`
	Crowns           int    `json:"crowns"`
	Clan             struct {
		Tag     string `json:"tag"`
		Name    string `json:"name"`
		BadgeId int    `json:"badgeId"`
	} `json:"clan"`
	Cards []Card `json:"cards"`
}

type Card

type Card struct {
	Name     string       `json:"name"`
	Level    int          `json:"level"`
	MaxLevel int          `json:"maxLevel"`
	Count    int          `json:"count"`
	IconUrls CardIconUrls `json:"iconUrls"`
}

type CardIconUrls

type CardIconUrls struct {
	Medium string `json:"medium"`
}

type Clan

type Clan struct {
	Tag               string       `json:"tag"`
	Name              string       `json:"name"`
	Type              string       `json:"type"`
	Description       string       `json:"description"`
	BadgeId           int          `json:"badgeId"`
	ClanScore         int          `json:"clanScore"`
	Location          Location     `json:"location"`
	RequiredTrophies  int          `json:"requiredTrophies"`
	DonationsPerWeek  int          `json:"donationsPerWeek"`
	ClanChestStatus   string       `json:"clanChestStatus"`
	ClanChestPoints   int          `json:"clanChestPoints"`
	ClanChestLevel    int          `json:"clanChestLevel"`
	ClanChestMaxLevel int          `json:"clanChestMaxLevel"`
	Members           int          `json:"members"`
	MemberList        []ClanMember `json:"memberList"`
}

type ClanInterface

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

func (*ClanInterface) CurrentWar

func (i *ClanInterface) CurrentWar() (ClanWar, error)

Retrieve information about clan's current clan war

func (*ClanInterface) Get

func (i *ClanInterface) Get() (Clan, error)

Get information about a single clan by clan tag. Clan tags can be found using clan search operation.

func (*ClanInterface) Members

func (i *ClanInterface) Members() (MemberPaging, error)

List clan members

func (*ClanInterface) WarLog

func (i *ClanInterface) WarLog() (WarLogPaging, error)

Retrieve clan's clan war log

type ClanMember

type ClanMember struct {
	Tag               string `json:"tag"`
	Name              string `json:"name"`
	Role              string `json:"role"`
	ExpLevel          int    `json:"expLevel"`
	Trophies          int    `json:"trophies"`
	Arena             Arena  `json:"arena"`
	ClanRank          int    `json:"clanRank"`
	PreviousClanRank  int    `json:"previousClanRank"`
	Donations         int    `json:"donations"`
	DonationsReceived int    `json:"donationsReceived"`
	ClanChestPoints   int    `json:"clanChestPoints"`
}

type ClanPaging

type ClanPaging struct {
	Items  []Clan `json:"items"`
	Paging Paging `json:"paging"`
}

type ClanQuery

type ClanQuery struct {
	PagedQuery
	LocationId int
	MinScore   int
	MinMembers int
	MaxMembers int
	Name       string
}

type ClanWar

type ClanWar struct {
	State                string               `json:"state"`
	RawCollectionEndTime string               `json:"collectionEndTime"`
	Clan                 ClanWarStanding      `json:"clan"`
	Participants         []ClanWarParticipant `json:"participants"`
}

func (*ClanWar) CollectionEndTime

func (w *ClanWar) CollectionEndTime() time.Time

type ClanWarParticipant

type ClanWarParticipant struct {
	Tag           string `json:"tag"`
	Name          string `json:"name"`
	CardsEarned   int    `json:"cardsEarned"`
	BattlesPlayed int    `json:"battlesPlayed"`
	Wins          int    `json:"wins"`
}

type ClanWarStanding

type ClanWarStanding struct {
	Tag           string `json:"tag"`
	Name          string `json:"name"`
	BadgeId       int    `json:"badgeId"`
	ClanScore     int    `json:"clanScore"`
	Participants  int    `json:"participants"`
	BattlesPlayed int    `json:"battlesPlayed"`
	Wins          int    `json:"wins"`
	Crowns        int    `json:"crowns"`
}

type ClansInterface

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

func (*ClansInterface) Search

func (i *ClansInterface) Search(query *ClanQuery) (ClanPaging, error)

Search all clans by name and/or filtering the results using various criteria. At least one filtering criteria must be defined and if name is used as part of search, it is required to be at least three characters long.

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string
	Bearer    string
	// contains filtered or unexported fields
}

func NewClient added in v1.1.0

func NewClient(token string) *Client

func (*Client) Clan

func (c *Client) Clan(tag string) *ClanInterface

func (*Client) Clans

func (c *Client) Clans() *ClansInterface

func (*Client) Location

func (c *Client) Location(id int) *LocationInterface

func (*Client) Locations

func (c *Client) Locations() *LocationsInterface

func (*Client) Player

func (c *Client) Player(tag string) *PlayerInterface

func (*Client) Tournament

func (c *Client) Tournament(tag string) *TournamentInterface

func (*Client) Tournaments

func (c *Client) Tournaments() *TournamentsInterface

type ErrorBody

type ErrorBody struct {
	Reason  string `json:"reason"`
	Message string `json:"message"`
}

The error response sent by the API if 4xx/5xx status code.

type FavouriteCard

type FavouriteCard struct {
	Name     string       `json:"name"`
	ID       int          `json:"id"`
	MaxLevel int          `json:"maxLevel"`
	IconUrls CardIconUrls `json:"iconUrls"`
}

type GameMode

type GameMode struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type LeagueStatistics

type LeagueStatistics struct {
	BestSeason     Season `json:"bestSeason"`
	PreviousSeason Season `json:"previousSeason"`
	CurrentSeason  Season `json:"currentSeason"`
}

type Location

type Location struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	IsCountry   bool   `json:"isCountry"`
	CountryCode string `json:"countryCode,omitempty"`
}

type LocationClanRanking

type LocationClanRanking struct {
	Tag          string   `json:"tag"`
	Name         string   `json:"name"`
	Rank         int      `json:"rank"`
	PreviousRank int      `json:"previousRank"`
	Location     Location `json:"location"`
	BadgeId      int      `json:"badgeId"`
	ClanScore    int      `json:"clanScore"`
	Members      int      `json:"members"`
}

type LocationClanRankingPager

type LocationClanRankingPager struct {
	Items  []LocationClanRanking `json:"items"`
	Paging Paging                `json:"paging"`
}

type LocationInterface

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

func (*LocationInterface) ClanRankings

func (i *LocationInterface) ClanRankings(query *PagedQuery) (LocationClanRankingPager, error)

Get clan rankings for a specific location

func (*LocationInterface) ClanWarRankings added in v1.1.0

func (i *LocationInterface) ClanWarRankings(query *PagedQuery) (LocationClanRankingPager, error)

Get clan war rankings for a specific location

func (*LocationInterface) Get

func (i *LocationInterface) Get() (Location, error)

Get information about specific location

func (*LocationInterface) PlayerRankings

func (i *LocationInterface) PlayerRankings(query *PagedQuery) (LocationPlayerRankingPager, error)

Get player rankings for a specific location

type LocationPager

type LocationPager struct {
	Items  []Location `json:"items"`
	Paging Paging     `json:"paging"`
}

type LocationPlayerRanking

type LocationPlayerRanking struct {
	Tag          string     `json:"tag"`
	Name         string     `json:"name"`
	ExpLevel     int        `json:"expLevel"`
	Trophies     int        `json:"trophies"`
	Clan         PlayerClan `json:"clan"`
	Rank         int        `json:"Rank"`
	PreviousRank int        `json:"previousRank"`
	Arena        Arena      `json:"arena"`
}

type LocationPlayerRankingPager

type LocationPlayerRankingPager struct {
	Items  []LocationPlayerRanking `json:"items"`
	Paging Paging                  `json:"paging"`
}

type LocationsInterface

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

func (*LocationsInterface) All

List all available locations

type MemberPaging

type MemberPaging struct {
	Items  []ClanMember `json:"items"`
	Paging Paging       `json:"paging"`
}

type PagedQuery added in v1.1.0

type PagedQuery struct {
	Limit  int
	After  int
	Before int
}

Base struct for paged queries.

type Paging added in v1.1.0

type Paging struct {
	Cursors struct {
		Before string `json:"before"`
		After  string `json:"after"`
	} `json:"cursors"`
}

Paging for pager responses. 'before' and 'after' may be empty if there are no more results to return.

type Player

type Player struct {
	Tag                   string           `json:"tag"`
	Name                  string           `json:"name"`
	ExpLevel              int              `json:"expLevel"`
	Trophies              int              `json:"trophies"`
	BestTrophies          int              `json:"bestTrophies"`
	Wins                  int              `json:"wins"`
	Losses                int              `json:"losses"`
	BattleCount           int              `json:"battleCount"`
	ThreeCrownWins        int              `json:"threeCrownWins"`
	ChallengeCardsWon     int              `json:"challengeCardsWon"`
	ChallengeMaxWins      int              `json:"challengeMaxWins"`
	TournamentCardsWon    int              `json:"tournamentCardsWon"`
	TournamentBattleCount int              `json:"tournamentBattleCount"`
	Role                  string           `json:"role"`
	Donations             int              `json:"donations"`
	DonationsReceived     int              `json:"donationsReceived"`
	TotalDonations        int              `json:"totalDonations"`
	WarDayWins            int              `json:"warDayWins"`
	ClanCardsCollected    int              `json:"clanCardsCollected"`
	Clan                  PlayerClan       `json:"clan"`
	Arena                 Arena            `json:"arena"`
	Achievements          []Achievement    `json:"achievements"`
	Cards                 []Card           `json:"cards"`
	CurrentDeck           []Card           `json:"currentDeck"`
	CurrentFavouriteCard  FavouriteCard    `json:"currentFavouriteCard"`
	LeagueStatistics      LeagueStatistics `json:"leagueStatistics"`
}

type PlayerClan

type PlayerClan struct {
	Tag     string `json:"tag"`
	Name    string `json:"name"`
	BadgeID int    `json:"badgeId"`
}

type PlayerInterface

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

func (*PlayerInterface) BattleLog

func (i *PlayerInterface) BattleLog() (BattleLogEntries, error)

Get list of recent battle results for a player.

func (*PlayerInterface) Get

func (i *PlayerInterface) Get() (Player, error)

Get information about a single player by player tag. Player tags can be found either in game or by from clan member lists.

func (*PlayerInterface) UpcomingChests

func (i *PlayerInterface) UpcomingChests() (UpcomingChests, error)

Get list of reward chests that the player will receive next in the game.

func (*PlayerInterface) VerifyToken

func (i *PlayerInterface) VerifyToken(token string) (VerificationResult, error)

Verifies a player token and returns whether or not the token was associated with the given player.

This API call can be used by a player to prove that they own a particular game account as the token can only be retrieved inside the game from settings view.

type Season

type Season struct {
	Rank         int    `json:"rank"`
	Trophies     int    `json:"trophies"`
	BestTrophies int    `json:"bestTrophies"`
	ID           string `json:"id"`
}

type Tournament

type Tournament struct {
	Tag                 string             `json:"tag"`
	Type                string             `json:"type"`
	Status              string             `json:"status"`
	CreatorTag          string             `json:"creatorTag"`
	Name                string             `json:"name"`
	Description         string             `json:"description"`
	Capacity            int                `json:"capacity"`
	MaxCapacity         int                `json:"maxCapacity"`
	PreparationDuration int                `json:"preparationDuration"`
	Duration            int                `json:"duration"`
	RawCreatedTime      string             `json:"createdTime"`
	RawStartedTime      string             `json:"startedTime"`
	MembersList         []TournamentMember `json:"membersList"`
}

func (*Tournament) CreatedTime

func (t *Tournament) CreatedTime() time.Time

func (*Tournament) StartedTime

func (t *Tournament) StartedTime() time.Time

type TournamentInterface

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

func (*TournamentInterface) Get

func (i *TournamentInterface) Get() (Tournament, error)

Get information about a single tournament by a tournament tag.

type TournamentMember

type TournamentMember struct {
	Tag   string     `json:"tag"`
	Name  string     `json:"name"`
	Score int        `json:"score"`
	Rank  int        `json:"rank"`
	Clan  PlayerClan `json:"clan"`
}

type TournamentPaging

type TournamentPaging struct {
	Items  []Tournament `json:"items"`
	Paging Paging       `json:"paging"`
}

type TournamentQuery

type TournamentQuery struct {
	PagedQuery
	Name string
}

type TournamentsInterface

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

func (*TournamentsInterface) Search

Search all tournaments by name.

It is not possible to specify ordering for results so clients should not rely on any specific ordering as that may change in the future releases of the API.

type UpcomingChest

type UpcomingChest struct {
	Index int    `json:"index"`
	Name  string `json:"name"`
}

type UpcomingChests

type UpcomingChests struct {
	Items []UpcomingChest `json:"items"`
}

type VerificationResult

type VerificationResult struct {
	Tag    string `json:"tag"`
	Token  string `json:"token"`
	Status string `json:"status"`
}

type WarLogEntry

type WarLogEntry struct {
	SeasonId       int                  `json:"seasonId"`
	RawCreatedDate string               `json:"createdDate"`
	Participants   []ClanWarParticipant `json:"participants"`
	Standings      []WarLogStanding     `json:"standings"`
}

func (*WarLogEntry) CreatedDate

func (w *WarLogEntry) CreatedDate() time.Time

type WarLogPaging

type WarLogPaging struct {
	Items  []WarLogEntry `json:"items"`
	Paging Paging        `json:"paging"`
}

type WarLogStanding

type WarLogStanding struct {
	Clan         ClanWarStanding `json:"clan"`
	TrophyChange int             `json:"trophyChange"`
}

Jump to

Keyboard shortcuts

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