clash

package module
v0.0.0-...-9842b2c Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 5 Imported by: 0

README

Clash of Clan API for GO

This is a simple fetch API for Clash of Clans in Go. It uses goroutines to fetch all members for a clan concurrently.

Installation

go get github.com/amir20/coc-api-go

Example Use

package main

import (
	"os"

	"github.com/amir20/coc-api-go"
)

func main() {
    token := os.Getenv("API_TOKEN")

    clashClient := clash.NewClient(token)
    clan, err := clashClient.Clan("#UGJPVJR")
    if err != nil {
        panic(err)
    }

    // Fetches all clash member list
    clashClient.FetchAllPlayers(clan)

    println(clan.Name)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clan

type Clan struct {
	BadgeUrls struct {
		Large  string `json:"large"`
		Medium string `json:"medium"`
		Small  string `json:"small"`
	} `json:"badgeUrls"`
	ClanLevel        int64  `json:"clanLevel"`
	ClanPoints       int64  `json:"clanPoints"`
	ClanVersusPoints int64  `json:"clanVersusPoints"`
	Description      string `json:"description"`
	IsWarLogPublic   bool   `json:"isWarLogPublic"`
	Location         struct {
		CountryCode string `json:"countryCode"`
		ID          int64  `json:"id"`
		IsCountry   bool   `json:"isCountry"`
		Name        string `json:"name"`
	} `json:"location"`
	MemberList       []*Player `json:"memberList"`
	Members          int64     `json:"members"`
	Name             string    `json:"name"`
	RequiredTrophies int64     `json:"requiredTrophies"`
	Tag              string    `json:"tag"`
	Type             string    `json:"type"`
	WarFrequency     string    `json:"warFrequency"`
	WarLosses        int64     `json:"warLosses"`
	WarTies          int64     `json:"warTies"`
	WarWinStreak     int64     `json:"warWinStreak"`
	WarWins          int64     `json:"warWins"`
}

Clan represent a model that is fetched from API.

type Client

type Client interface {
	Clan(tag string) (*Clan, error)
	Player(tag string) (*Player, error)
	FetchAllPlayers(clan *Clan) error
}

Client that fetches model objects from Clash of Clan's API

func NewClient

func NewClient(token string) Client

NewClient creates a new instance of API.

type Player

type Player struct {
	Achievements []struct {
		CompletionInfo string `json:"completionInfo"`
		Info           string `json:"info"`
		Name           string `json:"name"`
		Stars          int64  `json:"stars"`
		Target         int64  `json:"target"`
		Value          int64  `json:"value"`
		Village        string `json:"village"`
	} `json:"achievements"`
	AttackWins         int64 `json:"attackWins"`
	BestTrophies       int64 `json:"bestTrophies"`
	BestVersusTrophies int64 `json:"bestVersusTrophies"`
	BuilderHallLevel   int64 `json:"builderHallLevel"`
	Clan               struct {
		BadgeUrls struct {
			Large  string `json:"large"`
			Medium string `json:"medium"`
			Small  string `json:"small"`
		} `json:"badgeUrls"`
		ClanLevel int64  `json:"clanLevel"`
		Name      string `json:"name"`
		Tag       string `json:"tag"`
	} `json:"clan"`
	DefenseWins       int64 `json:"defenseWins"`
	Donations         int64 `json:"donations"`
	DonationsReceived int64 `json:"donationsReceived"`
	ExpLevel          int64 `json:"expLevel"`
	Heroes            []struct {
		Level    int64  `json:"level"`
		MaxLevel int64  `json:"maxLevel"`
		Name     string `json:"name"`
		Village  string `json:"village"`
	} `json:"heroes"`
	League struct {
		IconUrls struct {
			Medium string `json:"medium"`
			Small  string `json:"small"`
			Tiny   string `json:"tiny"`
		} `json:"iconUrls"`
		ID   int64  `json:"id"`
		Name string `json:"name"`
	} `json:"league"`
	LegendStatistics struct {
		BestSeason struct {
			ID       string `json:"id"`
			Rank     int64  `json:"rank"`
			Trophies int64  `json:"trophies"`
		} `json:"bestSeason"`
		CurrentSeason struct {
			Trophies int64 `json:"trophies"`
		} `json:"currentSeason"`
		LegendTrophies int64 `json:"legendTrophies"`
	} `json:"legendStatistics"`
	Name   string `json:"name"`
	Role   string `json:"role"`
	Spells []struct {
		Level    int64  `json:"level"`
		MaxLevel int64  `json:"maxLevel"`
		Name     string `json:"name"`
		Village  string `json:"village"`
	} `json:"spells"`
	Tag           string `json:"tag"`
	TownHallLevel int64  `json:"townHallLevel"`
	Troops        []struct {
		Level    int64  `json:"level"`
		MaxLevel int64  `json:"maxLevel"`
		Name     string `json:"name"`
		Village  string `json:"village"`
	} `json:"troops"`
	Trophies             int64 `json:"trophies"`
	VersusBattleWinCount int64 `json:"versusBattleWinCount"`
	VersusBattleWins     int64 `json:"versusBattleWins"`
	VersusTrophies       int64 `json:"versusTrophies"`
	WarStars             int64 `json:"warStars"`
}

Player model from the API

Jump to

Keyboard shortcuts

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