clash

package
v0.0.0-...-a0c948e Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range or equal to 202 Accepted. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.

The error type will be *RateLimitError for rate limit exceeded errors, *AcceptedError for 202 Accepted status codes, and *TwoFactorAuthError for two-factor authentication errors.

Types

type Achievement

type Achievement struct {
	Name           string `json:"name,omitempty"`
	Stars          int    `json:"stars,omitempty"`
	Value          int    `json:"value,omitempty"`
	Target         int    `json:"target,omitempty"`
	Info           string `json:"info,omitempty"`
	CompletionInfo string `json:"completionInfo,omitempty"`
	Village        string `json:"village,omitempty"`
}

Player represents a Clash of Clan player

type Clan

type Clan struct {
	Tag              string       `json:"tag,omitempty"`
	Name             string       `json:"name,omitempty"`
	Location         Location     `json:"location,omitempty"`
	ClanLevel        int          `json:"clanLevel,omitempty"`
	ClanPoints       int          `json:"clanPoints,omitempty"`
	ClanVersusPoints int          `json:"clanVersusPoints,omitempty"`
	BadgeUrls        UrlContainer `json:"badgeUrls,omitempty"`
	Members          int          `json:"members,omitempty"`
}

type ClanList

type ClanList struct {
	Items []Clan `json:"items,omitempty"`
}

type ClanMember

type ClanMember struct {
	Player
	ClanRank         int `json:"clanRank,omitempty"`
	PreviousClanRank int `json:"previousClanRank,omitempty"`
}

type ClanMemberList

type ClanMemberList struct {
	Items []ClanMember `json:"items,omitempty"`
}

type ClanRanking

type ClanRanking struct {
	Tag              string       `json:"tag,omitempty"`
	Name             string       `json:"name,omitempty"`
	Location         Location     `json:"location,omitempty"`
	BadgeUrls        UrlContainer `json:"badgeUrls,omitempty"`
	ClanLevel        int          `json:"clanLevel,omitempty"`
	ClanPoints       int          `json:"clanPoints,omitempty"`
	ClanVersusPoints int          `json:"clanVersusPoints,omitempty"`
	Members          int          `json:"members,omitempty"`
	Rank             int          `json:"rank,omitempty"`
	PreviousRank     int          `json:"previousRank,omitempty"`
}

type ClanRankingList

type ClanRankingList struct {
	Items []ClanRanking `json:"items,omitempty"`
}

type ClanWarAttack

type ClanWarAttack struct {
	AttackerTag           string `json:"attackerTag,omitempty"`
	DefenderTag           string `json:"defenderTag,omitempty"`
	Stars                 int    `json:"stars,omitempty"`
	DestructionPercentage int    `json:"destructionPercentage,omitempty"`
	Order                 int    `json:"order,omitempty"`
}

type ClanWarLeagueWar

type ClanWarLeagueWar struct {
	Tag                  string `json:"tag,omitempty"`
	State                string `json:"state,omitempty"`
	TeamSize             int    `json:"teamSize,omitempty"`
	PreparationStartTime string `json:"preparationStartTime,omitempty"`
	StartTime            string `json:"startTime,omitempty"`
	EndTime              string `json:"endTime,omitempty"`
	Clan                 string `json:"clan,omitempty"`
	Opponent             string `json:"opponent,omitempty"`
}

type ClanWarLeagueWarClan

type ClanWarLeagueWarClan struct {
	Tag                   string        `json:"tag,omitempty"`
	Name                  string        `json:"name,omitempty"`
	BadgeUrls             UrlContainer  `json:"badgeUrls,omitempty"`
	ClanLevel             int           `json:"clanLevel,omitempty"`
	Attacks               int           `json:"attacks,omitempty"`
	Stars                 int           `json:"stars,omitempty"`
	DestructionPercentage int           `json:"destructionPercentage,omitempty"`
	Members               ClanWarMember `json:"members,omitempty"`
}

type ClanWarMember

type ClanWarMember struct {
	Tag                string          `json:"tag,omitempty"`
	Name               string          `json:"name,omitempty"`
	TownHallLevel      int             `json:"townHallLevel,omitempty"`
	MapPosition        int             `json:"mapPosition,omitempty"`
	Attacks            []ClanWarAttack `json:"attacks,omitempty"`
	OpponentAttacks    int             `json:"opponentAttacks,omitempty"`
	BestOpponentAttack ClanWarAttack   `json:"bestOpponentAttack,omitempty"`
}

type ClansService

type ClansService service

func (*ClansService) Get

func (s *ClansService) Get(ctx context.Context, clanTag string) (*Clan, *Response, error)

Get fetches information about a single clan by clan tag.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/clans/getClan

func (*ClansService) GetClanLeagueWar

func (s *ClansService) GetClanLeagueWar(ctx context.Context, warTag string) (*ClanWarLeagueWar, *Response, error)

GetClanLeagueWar fetches information about clan's current clan war league war.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/clans/getClanWarLeagueWar

func (*ClansService) GetCurrentWar

func (s *ClansService) GetCurrentWar(ctx context.Context, clanTag string) (*CurrentWar, *Response, error)

GetCurrentWar fetches information about clan's current clan war.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/clans/getCurrentWar

func (*ClansService) GetCurrentWarLeagueGroup

func (s *ClansService) GetCurrentWarLeagueGroup(ctx context.Context, clanTag string) (*CurrentWarLeagueGroup, *Response, error)

GetCurrentWarLeagueGroup fetches information about clan's current clan war league group.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/clans/getClanWarLeagueGroup

func (*ClansService) GetMembers

func (s *ClansService) GetMembers(ctx context.Context, clanTag string, opt *Options) (*ClanMemberList, *Response, error)

GetMembers fetches a list of clan members.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/clans/getClanMembers

func (*ClansService) GetWarLog

func (s *ClansService) GetWarLog(ctx context.Context, clanTag string, opt *Options) (*WarLogList, *Response, error)

GetWarLog fetches clan's clan war log.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/clans/getClanWarLog

func (*ClansService) Search

func (s *ClansService) Search(ctx context.Context, opt *SearchOptions) (*ClanList, *Response, error)

List the repositories for a user. Passing the empty string will list repositories for the authenticated user.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/clans/searchClans

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string
	Token     string

	Players   *PlayersService
	Clans     *ClansService
	Locations *LocationsService
	Leagues   *LeaguesService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client, token string) *Client

NewClient returns a new ClashOfClan API client. If a nil httpClient is provided, a new http.Client will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If rate limit is exceeded and reset time is in the future, Do returns *RateLimitError immediately without making a network API call.

The provided ctx must be non-nil. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type CurrentWar

type CurrentWar struct {
	State                string  `json:"state,omitempty"`
	TeamSize             int     `json:"teamSize,omitempty"`
	PreparationStartTime string  `json:"preparationStartTime,omitempty"`
	StartTime            string  `json:"startTime,omitempty"`
	EndTime              string  `json:"endTime,omitempty"`
	Clan                 WarClan `json:"clan,omitempty"`
	Opponent             WarClan `json:"opponent,omitempty"`
}

type CurrentWarLeagueGroup

type CurrentWarLeagueGroup struct {
	Tag    string   `json:"tag,omitempty"`
	State  string   `json:"state,omitempty"`
	Season string   `json:"season,omitempty"`
	Clans  WarClan  `json:"clans,omitempty"`
	Rounds []WarTag `json:"rounds,omitempty"`
}

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Reason   string         `json:"reason,omitempty"`
	Message  string         `json:"message,omitempty"`
}

An ErrorResponse reports one or more errors caused by an API request. GitHub API docs: https://developer.github.com/v3/#client-errors

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Hero

type Hero struct {
	Name     string `json:"name,omitempty"`
	Level    int    `json:"level,omitempty"`
	MaxLevel int    `json:"maxLevel,omitempty"`
	Village  string `json:"village,omitempty"`
}

Player represents a Clash of Clan player

type League

type League struct {
	Id       int          `json:"id,omitempty"`
	Name     string       `json:"name,omitempty"`
	IconUrls UrlContainer `json:"iconUrls,omitempty"`
}

type LeagueList

type LeagueList struct {
	Items []League `json:"items,omitempty"`
}

type LeagueSeason

type LeagueSeason struct {
	Id string `json:"id,omitempty"`
}

type LeagueSeasonList

type LeagueSeasonList struct {
	Items []LeagueSeason `json:"items,omitempty"`
}

type LeaguesService

type LeaguesService service

func (*LeaguesService) Get

func (s *LeaguesService) Get(ctx context.Context, leagueId string) (*League, *Response, error)

Get fetches information about specific league.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/leagues/getLeague

func (*LeaguesService) GetLeagueSeason

func (s *LeaguesService) GetLeagueSeason(ctx context.Context, leagueId string, opt *Options) (*LeagueSeasonList, *Response, error)

GetLeagueSeason fetches league seasons. Note that league season information is available only for Legend League.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/leagues/getLeagueSeasons

func (*LeaguesService) GetLeagueSeasonRankings

func (s *LeaguesService) GetLeagueSeasonRankings(ctx context.Context, leagueId string, seasonId string, opt *Options) (*SeasonPlayerRankingList, *Response, error)

GetLeagueSeason fetches league season rankings. Note that league season information is available only for Legend League.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/leagues/getLeagueSeasonRankings

func (*LeaguesService) List

func (s *LeaguesService) List(ctx context.Context, opt *Options) (*LeagueList, *Response, error)

List fetches a list of all leagues.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/leagues/getLeagues

type Location

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

type LocationList

type LocationList struct {
	Items []Location `json:"items,omitempty"`
}

type LocationsService

type LocationsService service

func (*LocationsService) Get

func (s *LocationsService) Get(ctx context.Context, locationId string) (*Location, *Response, error)

Get fetches information about specific location.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/locations/getLocation

func (*LocationsService) GetClanRankings

func (s *LocationsService) GetClanRankings(ctx context.Context, locationId string, opt *Options) (*ClanRankingList, *Response, error)

GetClanRankings fetches clan rankings for a specific location.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/locations/getClanRanking

func (*LocationsService) GetClanVersusRankings

func (s *LocationsService) GetClanVersusRankings(ctx context.Context, locationId string, opt *Options) (*ClanRankingList, *Response, error)

GetClanVersusRankings fetches clan versus rankings for a specific location.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/locations/getClanVersusRanking

func (*LocationsService) GetPlayerRankings

func (s *LocationsService) GetPlayerRankings(ctx context.Context, locationId string, opt *Options) (*PlayerRankingList, *Response, error)

GetPlayerRankings fetches player rankings for a specific location.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/locations/getPlayerRanking

func (*LocationsService) GetPlayerVersusRankings

func (s *LocationsService) GetPlayerVersusRankings(ctx context.Context, locationId string, opt *Options) (*PlayerVersusRankingList, *Response, error)

GetClanVersusRankings fetches player versus rankings for a specific location.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/locations/getPlayerVersusRanking

func (*LocationsService) List

List fetches a list of all available locations.

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/locations/getLocations

type Options

type Options struct {
	Limit  int `url:"limit,omitempty"`
	After  int `url:"after,omitempty"`
	Before int `url:"before,omitempty"`
}

type Player

type Player struct {
	Tag                  string        `json:"tag,omitempty"`
	Name                 string        `json:"name,omitempty"`
	TownHallLevel        int           `json:"townHallLevel,omitempty"`
	ExpLevel             int           `json:"expLevel,omitempty"`
	Trophies             int           `json:"trophies,omitempty"`
	BestTrophies         int           `json:"bestTrophies,omitempty"`
	WarStars             int           `json:"warStars,omitempty"`
	AttackWins           int           `json:"attackWins,omitempty"`
	DefenseWins          int           `json:"defenseWins,omitempty"`
	BuilderHallLevel     int           `json:"builderHallLevel,omitempty"`
	VersusTrophies       int           `json:"versusTrophies,omitempty"`
	BestVersusTrophies   int           `json:"bestVersusTrophies,omitempty"`
	VersusBattleWins     int           `json:"versusBattleWins,omitempty"`
	VersusBattleWinCount int           `json:"versusBattleWinCount,omitempty"`
	Role                 string        `json:"role,omitempty"`
	Donations            int           `json:"donations,omitempty"`
	DonationsReceived    int           `json:"donationsReceived,omitempty"`
	Clan                 Clan          `json:"clan,omitempty"`
	Achievements         []Achievement `json:"achievements,omitempty"`
	Troops               []Troop       `json:"troops,omitempty"`
	Heroes               []Hero        `json:"heroes,omitempty"`
	Spells               []Spell       `json:"spells,omitempty"`
}

Player represents a Clash of Clan player

type PlayerRanking

type PlayerRanking struct {
	Tag            string `json:"tag,omitempty"`
	Name           string `json:"name,omitempty"`
	ExpLevel       int    `json:"expLevel,omitempty"`
	League         League `json:"league,omitempty"`
	Trophies       int    `json:"trophies,omitempty"`
	VersusTrophies int    `json:"versusTrophies,omitempty"`
	AttackWins     int    `json:"attackWins,omitempty"`
	DefenseWins    int    `json:"defenseWins,omitempty"`
	Clan           Clan   `json:"clan,omitempty"`
	Rank           int    `json:"rank,omitempty"`
	PreviousRank   int    `json:"previousRank,omitempty"`
}

type PlayerRankingList

type PlayerRankingList struct {
	Items []PlayerRanking `json:"items,omitempty"`
}

type PlayerVersusRanking

type PlayerVersusRanking struct {
	Tag              string `json:"tag,omitempty"`
	Name             string `json:"name,omitempty"`
	ExpLevel         int    `json:"exp_level,omitempty"`
	Rank             int    `json:"rank,omitempty"`
	PreviousRank     int    `json:"previousRank,omitempty"`
	VersusTrophies   int    `json:"versusTrophies,omitempty"`
	Clan             Clan   `json:"clan,omitempty"`
	VersusBattleWins int    `json:"versusBattleWins,omitempty"`
}

type PlayerVersusRankingList

type PlayerVersusRankingList struct {
	Items []PlayerVersusRanking `json:"items,omitempty"`
}

type PlayersService

type PlayersService service

PlayersService handles communication with the players related methods of the Clash of Clan API.

func (*PlayersService) Get

func (s *PlayersService) Get(ctx context.Context, playerTag string) (*Player, *Response, error)

Get fetches a player by its tag

Clash of Clan API docs: https://developer.clashofclans.com/api-docs/index.html#!/players/getPlayer

type Response

type Response struct {
	*http.Response
}

Response is a GitHub API response. This wraps the standard http.Response returned from GitHub and provides convenient access to things like pagination links.

type SearchOptions

type SearchOptions struct {
	Options
	Name          string `url:"name,omitempty"`
	WarFrequency  string `url:"warFrequency,omitempty"`
	MinMembers    int    `url:"minMembers,omitempty"`
	MaxMembers    int    `url:"maxMembers,omitempty"`
	MinClanPoints int    `url:"minClanPoints,omitempty"`
	MinClanLevel  string `url:"minClanLevel,omitempty"`
}

ClanOptions specifies the optional parameters for clan search

type SeasonPlayerRanking

type SeasonPlayerRanking struct {
	Tag            string `json:"tag,omitempty"`
	Name           string `json:"name,omitempty"`
	ExpLevel       int    `json:"expLevel,omitempty"`
	League         League `json:"league,omitempty"`
	Trophies       int    `json:"trophies,omitempty"`
	VersusTrophies int    `json:"versusTrophies,omitempty"`
	AttackWins     int    `json:"attackWins,omitempty"`
	DefenseWins    int    `json:"defenseWins,omitempty"`
	Clan           Clan   `json:"clan,omitempty"`
	Rank           int    `json:"rank,omitempty"`
}

type SeasonPlayerRankingList

type SeasonPlayerRankingList struct {
	Items []SeasonPlayerRanking `json:"items,omitempty"`
}

type Spell

type Spell struct {
	Name     string `json:"name,omitempty"`
	Level    int    `json:"level,omitempty"`
	MaxLevel int    `json:"maxLevel,omitempty"`
	Village  string `json:"village,omitempty"`
}

Player represents a Clash of Clan player

type Troop

type Troop struct {
	Name     string `json:"name,omitempty"`
	Level    int    `json:"level,omitempty"`
	MaxLevel int    `json:"maxLevel,omitempty"`
	Village  string `json:"village,omitempty"`
}

Player represents a Clash of Clan player

type UrlContainer

type UrlContainer struct {
	Small  string `json:"small,omitempty"`
	Large  string `json:"large,omitempty"`
	Medium string `json:"medium,omitempty"`
}

type WarClan

type WarClan struct {
	Tag       string          `json:"tag,omitempty"`
	Name      string          `json:"name,omitempty"`
	BadgeUrls UrlContainer    `json:"badgeUrls,omitempty"`
	ClanLevel int             `json:"clanLevel,omitempty"`
	Attacks   int             `json:"attacks,omitempty"`
	Stars     int             `json:"stars,omitempty"`
	ExpEarned int             `json:"expEarned,omitempty"`
	Members   []ClanWarMember `json:"members,omitempty"`
}

type WarLog

type WarLog struct {
	Result   string  `json:"result,omitempty"`
	EndTime  string  `json:"endTime,omitempty"`
	TeamSize int     `json:"teamSize,omitempty"`
	Clan     WarClan `json:"clan,omitempty"`
	Opponent WarClan `json:"opponent,omitempty"`
}

type WarLogList

type WarLogList struct {
	Items []WarLog `json:"items,omitempty"`
}

type WarTag

type WarTag struct {
	Tag           string `json:"tag,omitempty"`
	Name          string `json:"name,omitempty"`
	TownHallLevel int    `json:"townHallLevel,omitempty"`
}

Jump to

Keyboard shortcuts

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