coc

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2023 License: GPL-3.0 Imports: 11 Imported by: 4

README

coc.go

Build Status codecov GoDoc Go Report Card

Getting Started

Installing
This assumes you already have a working Go environment, if not please see this page first

go get will always pull the latest tagged release from the master branch.

go get github.com/amaanq/coc.go

Usage

Import the package into your project.

import "github.com/amaanq/coc.go"

Construct a new Clash API Client which can be used to access the variety of Clash API functions. Please ENSURE your credentials are valid and please DO NOT use a password you use for important credentials, even though nothing is logged or stored here. Initialize automatically logs into your developer account, checks your keys, and adds or deletes them as necessary depending on your IP. You are able to login with multiple credentials in the event your application/project is large and draws a lot of users, key handling is done automatically for all logins.

package main

import (
    "github.com/amaanq/coc.go"
)

func main() {
    APIClient, err := coc.New(map[string]string{"email": "password", "email2": "password2", "email3": "password3"})
    if err != nil {
        // handle err
    }
}

You can add as many logins as you want, but it'll be slower with more logins. I recommend no more than 5.

See Documentation and /examples below for more detailed information

NOTICE: This library and the Clash API are unfinished

Because of that there may be major changes to library in the future.

The coc.go code is fairly well documented at this point and is currently the only documentation available. There are 4 main types of endpoints for the API. Player, Clan, Location, and League. Minor ones are label and goldpass. At the moment the CWL endpoints have yet to be implemented since I don't have sample json to base the structs off of yet. This will be done next cwl.

Here's how you can fetch player data and display it to your terminal.

import (
    "github.com/amaanq/coc.go"
)
// Obviously load a client first...
func main() {
  player, err := APIClient.GetPlayer("#YourTag")
  if err != nil {
    // handle err
  }

  fmt.Printf("Player: %+v\n", player)
  fmt.Println("My name is: ", player.Name)

  //Same for a clan:

  clan, err := APIClient.GetClan("#YourTag")
  if err != nil {
    // handle err
  }

  fmt.Printf("Clan: %+v\n", clan)
  fmt.Println("My clan name is", clan.Name,"and we have", clan.Members, "members in our clan. We have won", clan.WarWins, "wars so come join us!\nThese are our members:")
  for idx, member := range clan.MemberList {
    fmt.Printf("[%d]: %s (%s)\n", idx, member.Name, member.Role)
  }
}

IMPORTANT: There are some endpoints that can pass in a variety of arguments (i.e searching for clans)

This variety of arguments generally allows a limit, before, or after parameter to be set, however for clans there are a lot more options. So, you can make use SearchOptions or ClanSearchOptions accordingly. See example below:


NOTE: You cannot set before and after at the same time. The first one set will be used
import (
    "github.com/amaanq/coc.go"
)

// Obviously load a client first...
func main() {
  clans, err := APIClient.SearchClans(coc.ClanSearchOptions().SetName("test").SetLimit(10).SetMaxMembers(40))
  // which is the same as this (different order of setting)
  // clans, err := APIClient.SearchClans(coc.ClanSearchOptions().SetName("test").SetMaxMembers(40).SetLimit(10))
  if err != nil {
      // handle err
  }

  for _, clan := range clans.Clans {
      fmt.Println("data:", clan.Name, clan.RequiredTownhallLevel, clan.ClanLevel, clan.RequiredTrophies)
      if clan.ClanLevel >= 15 {
          fmt.Println("Found a clan you're looking for!", clan.Name, clan.Tag)
          break
      }
  }

  leagues, err := APIClient.GetLeagues(coc.SearchOptions().SetLimit(10).SetAfter(2))
  if err != nil {
    // handle err
  }
}

You can enter the map[string]string args as one map with several key-value pairs, or several maps with 1 key-value pair; this parsing is handled automatically. Enter every data type as a string, even ints. You can also leave the map empty, this is acceptable but some functions will error as one argument is required (SearchClans being one).

Subdirectories


Documentation

Index

Constants

View Source
const (
	GET  = "GET"
	POST = "POST"
)
View Source
const (
	DevBaseUrl        = "https://developer.clashofclans.com"
	LoginEndpoint     = "/api/login"
	KeyListEndpoint   = "/api/apikey/list"
	KeyCreateEndpoint = "/api/apikey/create"
	KeyRevokeEndpoint = "/api/apikey/revoke"

	BaseUrl           = "https://api.clashofclans.com/v1"
	ClanEndpoint      = "/clans"
	PlayerEndpoint    = "/players"
	LeagueEndpoint    = "/leagues"
	WarLeagueEndpoint = "/warleagues"
	LocationEndpoint  = "/locations"
	GoldpassEndpoint  = "/goldpass/seasons/current"
	LabelEndpoint     = "/labels"

	IPUrl = "https://api.ipify.org"
)
View Source
const (
	ClanLabelClanWars ClanLabelID = 56000000 + iota
	ClanLabelClanWarLeague
	ClanLabelTrophyPushing
	ClanLabelFriendlyWars
	ClanLabelClanGames
	ClanLabelBuilderBase
	ClanLabelBaseDesigning
	ClanLabelInternational
	ClanLabelFarming
	ClanLabelDonations
	ClanLabelFriendly
	ClanLabelTalkative
	ClanLabelUnderdog
	ClanLabelRelaxed
	ClanLabelCompetitive
	ClanLabelNewbieFriendly

	PlayerLabelClanWars PlayerLabelID = 57000000 + iota - 16
	PlayerLabelClanWarLeague
	PlayerLabelTrophyPushing
	PlayerLabelFriendlyWars
	PlayerLabelClanGames
	PlayerLabelBuilderBase
	PlayerLabelBaseDesigning
	PlayerLabelFarming
	PlayerLabelActiveDonator
	PlayerLabelActiveDaily
	PlayerLabelHungryLearner
	PlayerLabelFriendly
	PlayerLabelTalkative
	PlayerLabelTeacher
	PlayerLabelCompetitive
	PlayerLabelVeteran
	PlayerLabelNewbie
	PlayerLabelAmateurAttacker
)
View Source
const (
	TimestampFormat = "20060102T150405.000Z"
)

Variables

View Source
var (
	BadRequest           = "badRequest"
	InvalidAuthorization = "accessDenied"
	InvalidIP            = "accessDenied.invalidIp"
	NotFound             = "notFound"
)

Expand upon this later...

View Source
var ErrInvalidLeague = fmt.Errorf("only Legends League is supported, to avoid this error pass in 29000022 (or LegendLeague) for the LeagueID argument")

Functions

func ClanSearchOptions

func ClanSearchOptions() *clanSearchOptions

func CorrectTag

func CorrectTag(tag string) string

this function is inside /client/ but this makes it easier to use outside of the client package.

func SearchOptions

func SearchOptions() *searchOptions

func UseCache

func UseCache(b bool)

Caching is enabled by default, use this to disable it

Types

type APIAccount

type APIAccount struct {
	Credential Credential    // The credential used to log in.
	Response   LoginResponse // The response from the login.
	Keys       Keys          // The current account's keys.
}

Each API account used to log in, with a unique credential.

type APIError

type APIError struct {
	Err        error
	Reason     string `json:"reason,omitempty"`
	Message    string `json:"message,omitempty"`
	StatusCode int
}

func (*APIError) Error

func (a *APIError) Error() string

type Achievement

type Achievement struct {
	Name           string `json:"name"`
	Info           string `json:"info"`
	CompletionInfo string `json:"completionInfo"`
	Village        string `json:"village"`
	Stars          int    `json:"stars"`
	Value          int    `json:"value"`
	Target         int    `json:"target"`
}
var (
	None                    Achievement = Achievement{}
	BiggerCoffers           Achievement = Achievement{Name: "Bigger Coffers"}
	GetThoseGoblins         Achievement = Achievement{Name: "Get those Goblins!"}
	BiggerAndBetter         Achievement = Achievement{Name: "Bigger & Better"}
	NiceAndTidy             Achievement = Achievement{Name: "Nice and Tidy"}
	DiscoverNewTroops       Achievement = Achievement{Name: "Discover New Troops"}
	GoldGrab                Achievement = Achievement{Name: "Gold Grab"}
	ElixirEscapade          Achievement = Achievement{Name: "Elixir Escapade"}
	SweetVictory            Achievement = Achievement{Name: "Sweet Victory!"}
	EmpireBuilder           Achievement = Achievement{Name: "Empire Builder"}
	WallBuster              Achievement = Achievement{Name: "Wall Buster"}
	Humiliator              Achievement = Achievement{Name: "Humiliator"}
	UnionBuster             Achievement = Achievement{Name: "Union Buster"}
	Conqueror               Achievement = Achievement{Name: "Conqueror"}
	Unbreakable             Achievement = Achievement{Name: "Unbreakable"}
	FriendInNeed            Achievement = Achievement{Name: "Friend in Need"}
	MortarMauler            Achievement = Achievement{Name: "Mortar Mauler"}
	HeroicHeist             Achievement = Achievement{Name: "Heroic Heist"}
	LeagueAllStar           Achievement = Achievement{Name: "League All-Star"}
	XBowExterminator        Achievement = Achievement{Name: "X-Bow Exterminator"}
	Firefighter             Achievement = Achievement{Name: "Firefighter"}
	WarHero                 Achievement = Achievement{Name: "War Hero"}
	ClanWarWealth           Achievement = Achievement{Name: "Clan War Wealth"}
	AntiArtillery           Achievement = Achievement{Name: "Anti-Artillery"}
	SharingIsCaring         Achievement = Achievement{Name: "Sharing is caring"}
	KeepYourAccountSafeOld  Achievement = Achievement{Name: "Keep Your Account Safe!", Info: "Protect your village by connecting to a social network"}
	MasterEngineering       Achievement = Achievement{Name: "Master Engineering"}
	NextGenerationModel     Achievement = Achievement{Name: "Next Generation Model"}
	UnBuildIt               Achievement = Achievement{Name: "Un-Build It"}
	ChampionBuilder         Achievement = Achievement{Name: "Champion Builder"}
	HighGear                Achievement = Achievement{Name: "High Gear"}
	HiddenTreasures         Achievement = Achievement{Name: "Hidden Treasures"}
	GamesChampion           Achievement = Achievement{Name: "Games Champion"}
	DragonSlayer            Achievement = Achievement{Name: "Dragon Slayer"}
	WarLeagueLegend         Achievement = Achievement{Name: "War League Legend"}
	KeepYourAccountSafeSCID Achievement = Achievement{Name: "Keep Your Account Safe!", Info: "Connect your account to Supercell ID for safe keeping."}
	WellSeasoned            Achievement = Achievement{Name: "Well Seasoned"}
	ShatteredAndScattered   Achievement = Achievement{Name: "Shattered and Scattered"}
	NotSoEasyThisTime       Achievement = Achievement{Name: "Not So Easy This Time"}
	BustThis                Achievement = Achievement{Name: "Bust This"}
	SuperbWork              Achievement = Achievement{Name: "Superb Work"}
	SiegeSharer             Achievement = Achievement{Name: "Siege Sharer"}
	Counterspell            Achievement = Achievement{Name: "Counterspell"}
	MonolithMasher          Achievement = Achievement{Name: "Monolith Masher"}
	GetThoseOtherGoblins    Achievement = Achievement{Name: "Get those other Goblins!"}
	GetEvenMoreGoblins      Achievement = Achievement{Name: "Get even more Goblins!"}
	UngratefulChild         Achievement = Achievement{Name: "Ungrateful Child"}
	AggressiveCapitalism    Achievement = Achievement{Name: "Aggressive Capitalism"}
	MostValuableClanmate    Achievement = Achievement{Name: "Most Valuable Clanmate"}
)

If you're peering into this and I've typo'd an achievement name causing an error when fetching it, please let me know.

func GetAchievement

func GetAchievement(givenAchievements []Achievement, wantedAchievement Achievement) (Achievement, error)

type AchievementID

type AchievementID string

type Auth

type Auth struct {
	Ua    any    `json:"ua"`
	IP    any    `json:"ip"`
	Uid   string `json:"uid"`
	Token string `json:"token"`
}

type Base64String

type Base64String string

type ChatLanguage

type ChatLanguage struct {
	Name         string `json:"name"`
	LanguageCode string `json:"languageCode"`
	ID           int    `json:"id"`
}

type Clan

type Clan struct {
	MemberList             *[]ClanMember `json:"memberList"`
	WarTies                *int          `json:"warTies"`
	Description            *string       `json:"description"`
	Location               *Location     `json:"location"`
	WarLosses              *int          `json:"warLosses"`
	ChatLanguage           *ChatLanguage `json:"chatLanguage"`
	ClanCapital            *ClanCapital  `json:"clanCapital"`
	WarLeague              WarLeague     `json:"warLeague"`
	BadgeURLs              IconURLs      `json:"badgeUrls"`
	Tag                    string        `json:"tag"`
	WarFrequency           WarFrequency  `json:"warFrequency"`
	Privacy                Privacy       `json:"type"`
	Name                   string        `json:"name"`
	Labels                 []Label       `json:"labels"`
	ClanLevel              int           `json:"clanLevel"`
	WarWins                int           `json:"warWins"`
	Members                int           `json:"members"`
	WarWinStreak           int           `json:"warWinStreak"`
	RequiredTrophies       int           `json:"requiredTrophies"`
	RequiredVersusTrophies int           `json:"requiredVersusTrophies"`
	RequiredTownhallLevel  int           `json:"requiredTownhallLevel"`
	ClanVersusPoints       int           `json:"clanVersusPoints"`
	ClanPoints             int           `json:"clanPoints"`
	IsWarLogPublic         bool          `json:"isWarLogPublic"`
}
func (c *Clan) ChocolateClashLink() string
func (c *Clan) ClashOfStatsLink() string
func (c *Clan) GameLink() string

type ClanCapital

type ClanCapital struct {
	CapitalHallLevel *int        `json:"capitalHallLevel"`
	Districts        *[]District `json:"districts"`
}

type ClanLabelID

type ClanLabelID int

func (ClanLabelID) Valid

func (c ClanLabelID) Valid() bool

type ClanList

type ClanList struct {
	Paging Paging `json:"paging,omitempty"`
	Clans  []Clan `json:"items,omitempty"`
}

type ClanMember

type ClanMember struct {
	Tag               string `json:"tag"`
	Name              string `json:"name"`
	Role              Role   `json:"role"`
	League            League `json:"league"`
	ExpLevel          int    `json:"expLevel"`
	Trophies          int    `json:"trophies"`
	VersusTrophies    int    `json:"versusTrophies"`
	ClanRank          int    `json:"clanRank"`
	PreviousClanRank  int    `json:"previousClanRank"`
	Donations         int    `json:"donations"`
	DonationsReceived int    `json:"donationsReceived"`
}

type ClanMembers

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

type ClanRanking

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

type ClanRankingList

type ClanRankingList struct {
	Paging Paging        `json:"paging,omitempty"`
	Clans  []ClanRanking `json:"items,omitempty"`
}

type ClanTag

type ClanTag string

func (ClanTag) OpenInGameURL

func (c ClanTag) OpenInGameURL() string

func (ClanTag) String

func (c ClanTag) String() string

type ClanVersusRanking

type ClanVersusRanking struct {
	BadgeURLs        IconURLs `json:"badgeUrls,omitempty"`
	Tag              string   `json:"tag,omitempty"`
	Name             string   `json:"name,omitempty"`
	Location         Location `json:"location,omitempty"`
	ClanVersusPoints int      `json:"clanVersusPoints,omitempty"`
	ClanLevel        int      `json:"clanLevel,omitempty"`
	Rank             int      `json:"rank,omitempty"`
	PreviousRank     int      `json:"previousRank,omitempty"`
	Members          int      `json:"members,omitempty"`
}

type ClanVersusRankingList

type ClanVersusRankingList struct {
	Paging      Paging              `json:"paging,omitempty"`
	ClansVersus []ClanVersusRanking `json:"items,omitempty"`
}

type Client

type Client struct {
	StatusCode int
	sync.Mutex
	// contains filtered or unexported fields
}

func New

func New(credentials map[string]string) (*Client, error)

Pass in a map which maps a username to a password

func (*Client) GetCWLWars

func (h *Client) GetCWLWars(WarTag string)

func (*Client) GetClan

func (h *Client) GetClan(ClanTag string) (*Clan, error)

func (*Client) GetClanCurrentWar

func (h *Client) GetClanCurrentWar(ClanTag string) (*CurrentWar, error)

func (*Client) GetClanLabels

func (h *Client) GetClanLabels(options *searchOptions) (*LabelsData, error)

func (*Client) GetClanMembers

func (h *Client) GetClanMembers(ClanTag string) ([]ClanMember, error)

func (*Client) GetClanWarLeagueGroup

func (h *Client) GetClanWarLeagueGroup(ClanTag string)

func (*Client) GetClanWarLog

func (h *Client) GetClanWarLog(ClanTag string) (*WarLog, error)

func (*Client) GetGoldPass

func (h *Client) GetGoldPass() (*GoldPassSeason, error)

func (*Client) GetLeague

func (h *Client) GetLeague(LeagueID LeagueID) (*League, error)

func (*Client) GetLeagueSeasonInfo

func (h *Client) GetLeagueSeasonInfo(LeagueID LeagueID, SeasonID string, options *searchOptions) (*SeasonInfo, error)

Be cautious when using this. the data returned is massive. recommended to add args of {"limit": limit} and use the cursors for more data

func (*Client) GetLeagueSeasons

func (h *Client) GetLeagueSeasons(LeagueID LeagueID, options *searchOptions) (*SeasonData, error)

Ensure you pass in 29000022 for LeagueID

func (*Client) GetLeagues

func (h *Client) GetLeagues(options *searchOptions) (*LeagueData, error)

func (*Client) GetLocation

func (h *Client) GetLocation(LocationID LocationID) (*Location, error)

func (*Client) GetLocationClans

func (h *Client) GetLocationClans(LocationID LocationID, options *searchOptions) (*ClanRankingList, error)

Main Village Clan Rankings

func (*Client) GetLocationClansVersus

func (h *Client) GetLocationClansVersus(LocationID LocationID, options *searchOptions) (*ClanVersusRankingList, error)

Builder Hall Clan Rankings

func (*Client) GetLocationPlayers

func (h *Client) GetLocationPlayers(LocationID LocationID, options *searchOptions) (*PlayerRankingList, error)

Main Village Player Rankings

func (*Client) GetLocationPlayersVersus

func (h *Client) GetLocationPlayersVersus(LocationID LocationID, options *searchOptions) (*PlayerVersusRankingList, error)

Builder Hall Player Rankings

func (*Client) GetLocations

func (h *Client) GetLocations(options *searchOptions) (*LocationData, error)

This should be passed ideally with nothing, kwargs aren't necessary here but only for the sake of completeness.

func (*Client) GetPlayer

func (h *Client) GetPlayer(PlayerTag string) (*Player, error)

func (*Client) GetPlayerLabels

func (h *Client) GetPlayerLabels(options *searchOptions) (*LabelsData, error)

func (*Client) GetPlayers

func (h *Client) GetPlayers(PlayerTags []string) []*Player

Note: This is a custom method I made to make use of concurrency. A slice of players will be returned with no error, however players that had an error (i.e are banned or the tag never existed) will be nil inside the slice. The order of the player tags is kept intact.

func (*Client) GetWarLeague

func (h *Client) GetWarLeague(WarLeagueID WarLeagueID) (*League, error)

func (*Client) GetWarLeagues

func (h *Client) GetWarLeagues(options *searchOptions) (*LeagueData, error)

func (*Client) SearchClans

func (h *Client) SearchClans(options *clanSearchOptions) (*ClanList, error)

func (*Client) VerifyPlayerToken

func (h *Client) VerifyPlayerToken(PlayerTag string, Token string) (*PlayerVerification, error)

Side note: This is the only POST method for the API so far

type Credential

type Credential struct {
	Email    string
	Password string
}

type CurrentSeason

type CurrentSeason struct {
	Rank     int `json:"rank,omitempty"`
	Trophies int `json:"trophies,omitempty"`
}

type CurrentWar

type CurrentWar struct {
	State            string  `json:"state"`
	PreparationStart string  `json:"preparationStartTime"`
	Start            string  `json:"startTime"`
	End              string  `json:"endTime"`
	Clan             WarClan `json:"clan"`
	Opponent         WarClan `json:"opponent"`
	TeamSize         int     `json:"teamSize"`
	AttacksPerMember int     `json:"attacksPerMember"`
}

func (*CurrentWar) EndTime

func (c *CurrentWar) EndTime() time.Time

Returns the War End as a time.Time object

func (*CurrentWar) PreparationStartTime

func (c *CurrentWar) PreparationStartTime() time.Time

Returns the War PerparationStart as a time.Time object

func (*CurrentWar) StartTime

func (c *CurrentWar) StartTime() time.Time

Returns the War Start as a time.Time object

type Cursors

type Cursors struct {
	Before string `json:"before,omitempty"`
	After  string `json:"after,omitempty"`
}

type Developer

type Developer struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	Game          string `json:"game"`
	Email         string `json:"email"`
	Tier          string `json:"tier"`
	AllowedScopes any    `json:"allowedScopes"`
	MaxCidrs      any    `json:"maxCidrs"`
	PrevLoginTs   string `json:"prevLoginTs"`
	PrevLoginIP   string `json:"prevLoginIp"`
	PrevLoginUa   string `json:"prevLoginUa"`
}

type District

type District struct {
	Name              string `json:"name"`
	ID                int    `json:"id"`
	DistrictHallLevel int    `json:"districtHallLevel"`
}

type GoldPassSeason

type GoldPassSeason struct {
	Start string `json:"startTime,omitempty"`
	End   string `json:"endTime,omitempty"`
}

func (*GoldPassSeason) EndTime

func (g *GoldPassSeason) EndTime() time.Time

func (*GoldPassSeason) StartTime

func (g *GoldPassSeason) StartTime() time.Time

type Hero

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

type IconURLs

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

type Index

type Index struct {
	KeyAccountIndex int // Index of the credential we're at.
	KeyIndex        int // Index of the key we're at.
}

Keep track of what key we're at and what credential we're at.

type Key

type Key struct {
	Origins     any      `json:"origins"`
	ValidUntil  any      `json:"validUntil"`
	ID          string   `json:"id"`
	Developerid string   `json:"developerId"`
	Tier        string   `json:"tier"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Key         string   `json:"key"`
	Scopes      []string `json:"scopes"`
	Cidrranges  []string `json:"cidrRanges"`
}

type KeyResponse

type KeyResponse struct {
	Key                     Key    `json:"key,omitempty"`
	Status                  Status `json:"status"`
	SessionExpiresInSeconds int    `json:"sessionExpiresInSeconds"`
}

type Keys

type Keys struct {
	Status        Status `json:"status"`
	Keys          []Key  `json:"keys"`
	SessionExpire int    `json:"sessionExpiresInSeconds"`
}

type Label

type Label struct {
	IconUrls IconURLs `json:"iconUrls,omitempty"`
	Name     string   `json:"name,omitempty"`
	ID       int      `json:"id,omitempty"`
}

type LabelsData

type LabelsData struct {
	Paging Paging  `json:"paging,omitempty"`
	Labels []Label `json:"items,omitempty"`
}

type League

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

type LeagueData

type LeagueData struct {
	Paging  Paging   `json:"paging,omitempty"`
	Leagues []League `json:"items,omitempty"`
}

type LeagueID

type LeagueID int
const (
	Unranked LeagueID = 29000000 + iota
	BronzeLeagueIII
	BronzeLeagueII
	BronzeLeagueI
	SilverLeagueIII
	SilverLeagueII
	SilverLeagueI
	GoldLeagueIII
	GoldLeagueII
	GoldLeagueI
	CrystalLeagueIII
	CrystalLeagueII
	CrystalLeagueI
	MasterLeagueIII
	MasterLeagueII
	MasterLeagueI
	ChampionLeagueIII
	ChampionLeagueII
	ChampionLeagueI
	TitanLeagueIII
	TitanLeagueII
	TitanLeagueI
	LegendLeague
)

func (LeagueID) Valid

func (l LeagueID) Valid() bool

type LeagueIconUrls

type LeagueIconUrls struct {
	Small  string `json:"small"`
	Tiny   string `json:"tiny"`
	Medium string `json:"medium"`
}

type LegendStatistics

type LegendStatistics struct {
	PreviousSeason   Season        `json:"previousSeason"`
	BestSeason       Season        `json:"bestSeason"`
	BestVersusSeason Season        `json:"bestVersusSeason"`
	CurrentSeason    CurrentSeason `json:"currentSeason"`
	LegendTrophies   int           `json:"legendTrophies"`
}

type Location

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

type LocationData

type LocationData struct {
	Paging    Paging     `json:"paging,omitempty"`
	Locations []Location `json:"items,omitempty"`
}

type LocationID

type LocationID int
const (
	Europe LocationID = 32000000 + iota
	NorthAmerica
	SouthAmerica
	Asia
	AustraliaContinent
	Africa
	International
	Afghanistan
	ÅlandIslands
	Albania
	Algeria
	AmericanSamoa
	Andorra
	Angola
	Anguilla
	Antarctica
	AntiguaandBarbuda
	Argentina
	Armenia
	Aruba
	AscensionIsland
	Australia
	Austria
	Azerbaijan
	Bahamas
	Bahrain
	Bangladesh
	Barbados
	Belarus
	Belgium
	Belize
	Benin
	Bermuda
	Bhutan
	Bolivia
	BosniaandHerzegovina
	Botswana
	BouvetIsland
	Brazil
	BritishIndianOceanTerritory
	BritishVirginIslands
	Brunei
	Bulgaria
	BurkinaFaso
	Burundi
	Cambodia
	Cameroon
	Canada
	CanaryIslands
	CapeVerde
	CaribbeanNetherlands
	CaymanIslands
	CentralAfricanRepublic
	CeutaandMelilla
	Chad
	Chile
	China
	ChristmasIsland
	CocosIslands
	Colombia
	Comoros
	DRCCongo
	RepublicOfCongo
	CookIslands
	CostaRica
	CôtedIvoire
	Croatia
	Cuba
	Curaçao
	Cyprus
	CzechRepublic
	Denmark
	DiegoGarcia
	Djibouti
	Dominica
	DominicanRepublic
	Ecuador
	Egypt
	ElSalvador
	EquatorialGuinea
	Eritrea
	Estonia
	Ethiopia
	FalklandIslands
	FaroeIslands
	Fiji
	Finland
	France
	FrenchGuiana
	FrenchPolynesia
	FrenchSouthernTerritories
	Gabon
	Gambia
	Georgia
	Germany
	Ghana
	Gibraltar
	Greece
	Greenland
	Grenada
	Guadeloupe
	Guam
	Guatemala
	Guernsey
	Guinea
	GuineaBissau
	Guyana
	Haiti
	HeardAndMcDonaldIslands
	Honduras
	HongKong
	Hungary
	Iceland
	India
	Indonesia
	Iran
	Iraq
	Ireland
	IsleofMan
	Israel
	Italy
	Jamaica
	Japan
	Jersey
	Jordan
	Kazakhstan
	Kenya
	Kiribati
	Kosovo
	Kuwait
	Kyrgyzstan
	Laos
	Latvia
	Lebanon
	Lesotho
	Liberia
	Libya
	Liechtenstein
	Lithuania
	Luxembourg
	Macau
	Macedonia
	Madagascar
	Malawi
	Malaysia
	Maldives
	Mali
	Malta
	MarshallIslands
	Martinique
	Mauritania
	Mauritius
	Mayotte
	Mexico
	Micronesia
	Moldova
	Monaco
	Mongolia
	Montenegro
	Montserrat
	Morocco
	Mozambique
	Myanmar
	Namibia
	Nauru
	Nepal
	Netherlands
	NewCaledonia
	NewZealand
	Nicaragua
	Niger
	Nigeria
	Niue
	NorfolkIsland
	NorthKorea
	NorthernMarianaIslands
	Norway
	Oman
	Pakistan
	Palau
	Palestine
	Panama
	PapuaNewGuinea
	Paraguay
	Peru
	Philippines
	PitcairnIslands
	Poland
	Portugal
	PuertoRico
	Qatar
	Réunion
	Romania
	Russia
	Rwanda
	SaintBarthélemy
	SaintHelena
	SaintKittsandNevis
	SaintLucia
	SaintMartin
	SaintPierreandMiquelon
	Samoa
	SanMarino
	SãoToméandPríncipe
	SaudiArabia
	Senegal
	Serbia
	Seychelles
	SierraLeone
	Singapore
	SintMaarten
	Slovakia
	Slovenia
	SolomonIslands
	Somalia
	SouthAfrica
	SouthKorea
	SouthSudan
	Spain
	SriLanka
	StVincentAndGrenadines
	Sudan
	Suriname
	SvalbardandJanMayen
	Swaziland
	Sweden
	Switzerland
	Syria
	Taiwan
	Tajikistan
	Tanzania
	Thailand
	TimorLeste
	Togo
	Tokelau
	Tonga
	TrinidadandTobago
	TristandaCunha
	Tunisia
	Turkey
	Turkmenistan
	TurksandCaicosIslands
	Tuvalu
	USOutlyingIslands
	USVirginIslands
	Uganda
	Ukraine
	UnitedArabEmirates
	UnitedKingdom
	UnitedStates
	Uruguay
	Uzbekistan
	Vanuatu
	VaticanCity
	Venezuela
	Vietnam
	WallisandFutuna
	WesternSahara
	Yemen
	Zambia
	Zimbabwe
)

func (LocationID) Valid

func (l LocationID) Valid() bool

type LoginResponse

type LoginResponse struct {
	Auth                    Auth      `json:"auth"`
	Developer               Developer `json:"developer"`
	TemporaryAPIToken       string    `json:"temporaryAPIToken"`
	SwaggerURL              string    `json:"swaggerUrl"`
	Status                  Status    `json:"status"`
	SessionExpiresInSeconds int       `json:"sessionExpiresInSeconds"`
}

type Paging

type Paging struct {
	Cursors Cursors `json:"cursors,omitempty"`
}

type Player

type Player struct {
	League               League           `json:"league"`
	Role                 string           `json:"role"`
	Name                 string           `json:"name"`
	Tag                  string           `json:"tag"`
	WarPreference        string           `json:"warPreference"`
	Spells               []Hero           `json:"spells"`
	Heroes               []Hero           `json:"heroes"`
	Troops               []Hero           `json:"troops"`
	Labels               []Label          `json:"labels"`
	Achievements         []Achievement    `json:"achievements"`
	LegendStatistics     LegendStatistics `json:"legendStatistics"`
	Clan                 Clan             `json:"clan"`
	BestTrophies         int              `json:"bestTrophies"`
	DefenseWins          int              `json:"defenseWins"`
	BestVersusTrophies   int              `json:"bestVersusTrophies"`
	VersusTrophies       int              `json:"versusTrophies"`
	Donations            int              `json:"donations"`
	DonationsReceived    int              `json:"donationsReceived"`
	BuilderHallLevel     int              `json:"builderHallLevel"`
	VersusBattleWINS     int              `json:"versusBattleWins"`
	AttackWins           int              `json:"attackWins"`
	WarStars             int              `json:"warStars"`
	VersusBattleWinCount int              `json:"versusBattleWinCount"`
	Trophies             int              `json:"trophies"`
	ExpLevel             int              `json:"expLevel"`
	TownHallWeaponLevel  int              `json:"townHallWeaponLevel"`
	TownHallLevel        int              `json:"townHallLevel"`
}

type PlayerLabelID

type PlayerLabelID int

func (PlayerLabelID) Valid

func (p PlayerLabelID) Valid() bool

type PlayerRanking

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

type PlayerRankingClan

type PlayerRankingClan struct {
	Tag       string   `json:"tag,omitempty"`
	Name      string   `json:"name,omitempty"`
	BadgeURLs IconURLs `json:"badgeUrls,omitempty"`
}

type PlayerRankingList

type PlayerRankingList struct {
	Paging  Paging          `json:"paging,omitempty"`
	Players []PlayerRanking `json:"items,omitempty"`
}

type PlayerTag

type PlayerTag string

func (PlayerTag) OpenInGameURL

func (p PlayerTag) OpenInGameURL() string

func (PlayerTag) String

func (p PlayerTag) String() string

type PlayerVerification

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

type PlayerVersusRanking

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

type PlayerVersusRankingList

type PlayerVersusRankingList struct {
	Paging        Paging                `json:"paging,omitempty"`
	PlayersVersus []PlayerVersusRanking `json:"items,omitempty"`
}

type Privacy

type Privacy string
const (
	Open       Privacy = "open"
	InviteOnly Privacy = "inviteOnly"
	Closed     Privacy = "closed"
)

func (Privacy) IsClosed

func (p Privacy) IsClosed() bool

func (Privacy) IsInviteOnly

func (p Privacy) IsInviteOnly() bool

func (Privacy) IsOpen

func (p Privacy) IsOpen() bool

func (Privacy) String

func (p Privacy) String() string

type RankedPlayer

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

type Result

type Result string
const (
	Lose Result = "lose"
	Tie  Result = "tie"
	Win  Result = "win"
)

type Role

type Role string
const (
	NotMember Role = "notMember"
	Member    Role = "member"
	Elder     Role = "admin"
	CoLeader  Role = "coLeader"
	Leader    Role = "leader"
)

func (Role) IsCoLeader

func (r Role) IsCoLeader() bool

func (Role) IsElder

func (r Role) IsElder() bool

func (Role) IsLeader

func (r Role) IsLeader() bool

func (Role) IsMember

func (r Role) IsMember() bool

func (Role) IsNotMember

func (r Role) IsNotMember() bool

func (Role) String

func (r Role) String() string

type Season

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

type SeasonData

type SeasonData struct {
	Paging  Paging   `json:"paging,omitempty"`
	Seasons []Season `json:"items,omitempty"`
}

type SeasonInfo

type SeasonInfo struct {
	Paging  Paging         `json:"paging,omitempty"`
	Players []RankedPlayer `json:"items,omitempty"`
}

type Status

type Status struct {
	Detail  any    `json:"detail"`
	Message string `json:"message,omitempty"`
	Code    int    `json:"code,omitempty"`
}

type Village

type Village string
const (
	BuilderBase Village = "builderBase"
	Home        Village = "home"
)

type War

type War struct {
	Result           Result  `json:"result"`
	Start            string  `json:"startTime"`
	End              string  `json:"endTime"`
	Clan             WarClan `json:"clan"`
	Opponent         WarClan `json:"opponent"`
	TeamSize         int     `json:"teamSize"`
	AttacksPerMember int     `json:"attacksPerMember"`
}

func (*War) EndTime

func (w *War) EndTime() time.Time

Returns the War End as a time.Time object

func (*War) Lost

func (w *War) Lost() bool

func (*War) StartTime

func (w *War) StartTime() time.Time

Returns the War Start as a time.Time object

func (*War) Tied

func (w *War) Tied() bool

func (*War) Won

func (w *War) Won() bool

type WarAttack

type WarAttack struct {
	AttackerTag           string `json:"attackerTag"`
	DefenderTag           string `json:"defenderTag"`
	Stars                 int    `json:"stars"`
	DestructionPercentage int    `json:"destructionPercentage"`
	Order                 int    `json:"order"`
	Duration              int    `json:"duration"`
}

type WarClan

type WarClan struct {
	BadgeURLs             IconURLs    `json:"badgeUrls"`
	Tag                   string      `json:"tag"`
	Name                  string      `json:"name"`
	Members               []WarMember `json:"members"`
	ClanLevel             int         `json:"clanLevel"`
	Attacks               int         `json:"attacks"`
	Stars                 int         `json:"stars"`
	DestructionPercentage float64     `json:"destructionPercentage"`
	ExpEarned             int         `json:"expEarned"`
}

type WarFrequency

type WarFrequency string
const (
	Unknown             WarFrequency = "unknown" // Doesn't seem to work..
	Always              WarFrequency = "always"
	MoreThanOncePerWeek WarFrequency = "moreThanOncePerWeek"
	OncePerWeek         WarFrequency = "oncePerWeek"
	LessThanOncePerWeek WarFrequency = "lessThanOncePerWeek"
	Never               WarFrequency = "never"
	Any                 WarFrequency = "any"
)

func (WarFrequency) IsAlways

func (w WarFrequency) IsAlways() bool

func (WarFrequency) IsAny

func (w WarFrequency) IsAny() bool

func (WarFrequency) IsLessThanOncePerWeek

func (w WarFrequency) IsLessThanOncePerWeek() bool

func (WarFrequency) IsMoreThanOncePerWeek

func (w WarFrequency) IsMoreThanOncePerWeek() bool

func (WarFrequency) IsNever

func (w WarFrequency) IsNever() bool

func (WarFrequency) IsOncePerWeek

func (w WarFrequency) IsOncePerWeek() bool

func (WarFrequency) IsUnknown

func (w WarFrequency) IsUnknown() bool

func (WarFrequency) Valid

func (w WarFrequency) Valid() bool

type WarLeague

type WarLeague struct {
	IconUrls IconURLs `json:"iconUrls,omitempty"`
	Name     string   `json:"name,omitempty"`
	ID       int      `json:"id,omitempty"`
}

type WarLeagueData

type WarLeagueData struct {
	Paging  Paging   `json:"paging,omitempty"`
	Leagues []League `json:"items,omitempty"`
}

type WarLeagueID

type WarLeagueID int
const (
	UnrankedWarLeague WarLeagueID = 48000000 + iota
	BronzeWarLeagueIII
	BronzeWarLeagueII
	BronzeWarLeagueI
	SilverWarLeagueIII
	SilverWarLeagueII
	SilverWarLeagueI
	GoldWarLeagueIII
	GoldWarLeagueII
	GoldWarLeagueI
	CrystalWarLeagueIII
	CrystalWarLeagueII
	CrystalWarLeagueI
	MasterWarLeagueIII
	MasterWarLeagueII
	MasterWarLeagueI
	ChampionWarLeagueIII
	ChampionWarLeagueII
	ChampionWarLeagueI
)

func (WarLeagueID) Valid

func (w WarLeagueID) Valid() bool

type WarLog

type WarLog struct {
	Log []War `json:"items"`
}

type WarMember

type WarMember struct {
	Tag                string      `json:"tag"`
	Name               string      `json:"name"`
	Attacks            []WarAttack `json:"attacks"`
	BestOpponentAttack WarAttack   `json:"bestOpponentAttack"`
	TownhallLevel      int         `json:"townhallLevel"`
	MapPosition        int         `json:"mapPosition"`
	OpponentAttacks    int         `json:"opponentAttacks"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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