swgohhelp

package
v0.0.0-...-b00e405 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Overview

Package swgohhelp provides the API client interface for the https://api.swgoh.help/ service.

How to use

This package provides typed datas structures to interface with the website payloads and higher level methods for consuming the services.

You start by initializing the client and authenticating:

swcli := swgohhelp.New(context.Background())
if err := swcli.SignIn(username, password); err != nil {
	log.Fatalf("Unable to authenticate: %v", err)
}

There is no current session state so you may need to reauth by hand.

Fetching player profiles

You call the Client.Players() method, passing in the array of desired ally codes to be fetched:

players, err := swcli.Player("335-983-287")
if err != nil {
	log.Fatalf("Unable to fetch players: %v". err)
}
log.Printf("Found %d players", len(players))
for i := range players {
	log.Printf("Player #%d: %s, last updated at %v", i, players[i], players[i].UpdatedAt)
}

Debugging your API calls

Sometimes it may be usefull to see the raw request and response data sent/received by the client. Use the .SetDebug method to enable file-based logging of each request and response payloads to the default OS temporary folder.

Index

Constants

This section is empty.

Variables

View Source
var (
	GameDataCacheFile       = "gamedata.db"
	GameDataCacheExpiration = 7 * 24 * time.Hour

	PlayerCacheFile       = "players.db"
	PlayerCacheExpiration = 24 * time.Hour

	GuildCacheFile       = "guilds.db"
	GuildCacheExpiration = 20 * time.Hour
)

Game data related caching parameters

View Source
var DefaultEndpoint = "https://api.swgoh.help"

DefaultEndpoint is the default target host for API calls

View Source
var (
	EnvDataCacheDir = "SWGOH_CACHE_DIR"
)

Cache related environment variables

Functions

This section is empty.

Types

type Arena

type Arena struct {
	Char ArenaRanking `json:"char"`
	Ship ArenaRanking `json:"ship"`
}

Arena wraps both arena rankings for the player.

type ArenaRanking

type ArenaRanking struct {
	Rank  int         `json:"rank"`
	Squad []SquadUnit `json:"squad"`
}

ArenaRanking holds player arena ranking.

type AuthResponse

type AuthResponse struct {
	TokenType   string `json:"token_type"`
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

AuthResponse represents the authentication response data.

type Client

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

Client implements an authenticated callee to the https://api.swgoh.help service.

func New

func New(ctx context.Context) *Client

New initializes an instance of Client making it ready to use.

func (*Client) DataPlayerTitles

func (c *Client) DataPlayerTitles() (result map[string]DataPlayerTitle, err error)

DataPlayerTitles retrieves the data collection for player titles.

func (*Client) DataUnitAbilities

func (c *Client) DataUnitAbilities() (result map[string]DataUnitAbility, err error)

DataUnitAbilities returns a map of ability IDs to their descriptions.

func (*Client) DataUnitCategories

func (c *Client) DataUnitCategories() (result map[string]DataUnitCategory, err error)

DataUnitCategories returns a map of category IDs to their descriptions.

func (*Client) DataUnitSkills

func (c *Client) DataUnitSkills() (result map[string]DataUnitSkill, err error)

DataUnitSkills returns a map of skill IDs to their ability IDs.

func (*Client) DataUnits

func (c *Client) DataUnits() (result map[string]DataUnit, err error)

DataUnits returns a map of unit IDs to their details in game.

func (*Client) Guild

func (c *Client) Guild(allyCode string) (guild *Guild, err error)

Players retrieves all the players from a specified guild including roster details.

func (*Client) Players

func (c *Client) Players(allyCodes ...string) (players []Player, err error)

Players retrieves several player profile stats and roster details.

func (*Client) SetDebug

func (c *Client) SetDebug(debug bool) *Client

SetDebug defines the debug state for the client.

func (*Client) SignIn

func (c *Client) SignIn(username, password string) (accessToken string, err error)

SignIn authenticates the client and returns the accessToken or an error if authentication fails.

type CombatType

type CombatType int

CombatType is the enum value for an Unit combat type

const (
	// CombatTypeChar represents character units
	CombatTypeChar CombatType = 1
	// CombatTypeShip represents shipts units
	CombatTypeShip CombatType = 2
)

type DataPlayerTitle

type DataPlayerTitle struct {
	ID      string `json:"id,omitempty"`
	Name    string `json:"nameKey,omitempty"`
	Desc    string `json:"descKey,omitempty"`
	Details string `json:"shortDescKey,omitempty"`
}

DataPlayerTitle is the data library information about player titles.

type DataUnit

type DataUnit struct {
	ID             string `json:"baseId,omitempty"`
	Name           string `json:"nameKey,omitempty"`
	MaxRarity      int    `json:"maxRarity,omitempty"`
	ForceAlignment int    `json:"forceAlignment,omitempty"`
	CombatType     int    `json:"combatType,omitempty"`
	CombatTypeName string `json:"combatTypeName,omitempty"`

	CategoryRefs []string `json:"categoryIdList,omitempty"`
	Categories   []string `json:"categoryList,omitempty"`

	SkillRefs []DataUnitSkillList `json:"skillReferenceList,omitempty"`
	Skills    []UnitSkill         `json:"skillList,omitempty"`
}

DataUnit is the unit basic data info.

type DataUnitAbility

type DataUnitAbility struct {
	ID   string `json:"id,omitempty"`
	Name string `json:"nameKey,omitempty"`
	Icon string `json:"icon,omitempty"`
}

DataUnitAbility is the ability display name and icon

type DataUnitCategory

type DataUnitCategory struct {
	ID      string `json:"id,omitempty"`
	Name    string `json:"descKey,omitempty"`
	Visible bool   `json:"visible"`
}

DataUnitCategory is the category "tags" labels for characters and ships.

type DataUnitSkill

type DataUnitSkill struct {
	ID        string `json:"id,omitempty"`
	AbilityID string `json:"abilityReference,omitempty"`
	Type      int    `json:"skillType,omitempty"`
	IsZeta    bool   `json:"isZeta,omitempty"`
}

DataUnitSkill is the map for units and their abilities

type DataUnitSkillList

type DataUnitSkillList struct {
	ID             string `json:"skillId,omitempty"`
	RequiredTier   int    `json:"requiredTier,omitempty"`
	RequiredRarity int    `json:"requiredRarity,omitempty"`
}

DataUnitSkillList is an unit skill identifier and requirements.

type Guild

type Guild struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Desc     string `json:"desc"`
	Members  int    `json:"members"`
	Status   int    `json:"status"`
	Required int    `json:"required"`

	BannerColor string `json:"bannerColor"`

	Message string `json:"message"`
	GP      int    `json:"gp"`

	Raid Raid `json:"raid"`

	Roster []Player `json:"roster"`

	UpdatedAt Timestamp `json:"updated"`
}

Guild represents the full guild profile with abbreviated roster info.

type Mod

type Mod struct {
	ID          string    `json:"id"`
	Level       int       `json:"level"`
	Set         ModSet    `json:"set"`
	Tier        int       `json:"tier"`
	Pips        int       `json:"pips"`
	Slot        ModSlot   `json:"slot"`
	UnitEquiped string    `json:"unit_equiped"`
	Primary     ModStat   `json:"primaryStat"`
	Secondaries []ModStat `json:"secondaryStat"`
}

Mod is a character mod detailed value.

func (Mod) String

func (m Mod) String() string

type ModSet

type ModSet int

ModSet is the enum for possible mod bonus set

const (
	ModSetHealth     ModSet = 1
	ModSetOffense    ModSet = 2
	ModSetDefense    ModSet = 3
	ModSetSpeed      ModSet = 4
	ModSetCritChance ModSet = 5
	ModSetCritDamage ModSet = 6
	ModSetPotency    ModSet = 7
	ModSetTenacity   ModSet = 8
)

Possible bonus set values

func (ModSet) MarshalText

func (m ModSet) MarshalText() string

MarshalText implements encoding.TextMarshaler

func (ModSet) MarshalYAML

func (m ModSet) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler

func (ModSet) String

func (m ModSet) String() string

type ModSlot

type ModSlot int

ModSlot is the mod slot enum

const (
	ModSlotSquare   ModSlot = 1
	ModSlotArrow    ModSlot = 2
	ModSlotDiamond  ModSlot = 3
	ModSlotTriangle ModSlot = 4
	ModSlotCircle   ModSlot = 5
	ModSlotCross    ModSlot = 6
)

Available mod slots

func (ModSlot) MarshalText

func (s ModSlot) MarshalText() string

MarshalText implements encoding.TextMarshaler

func (ModSlot) MarshalYAML

func (s ModSlot) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler

func (ModSlot) String

func (s ModSlot) String() string

type ModStat

type ModStat struct {
	Unit  ModUnitStat `json:"unitStat"`
	Value float64     `json:"value"`
	Roll  int         `json:"roll"`
}

ModStat is a single mod stat name and value. Unit is the key name of the modified character stat attribute, and value is always a floating point even when precision is zero.

func (ModStat) String

func (s ModStat) String() string

type ModUnitStat

type ModUnitStat int

ModUnitStat is the enum with mod unit stat values

const (
	StatHealth                                ModUnitStat = 1
	StatStrength                              ModUnitStat = 2
	StatAgility                               ModUnitStat = 3
	StatIntelligence                          ModUnitStat = 4
	StatSpeed                                 ModUnitStat = 5
	StatAttackDamage                          ModUnitStat = 6
	StatAbilityPower                          ModUnitStat = 7
	StatArmor                                 ModUnitStat = 8
	StatSuppression                           ModUnitStat = 9
	StatArmorPenetration                      ModUnitStat = 10
	StatSuppressionPenetration                ModUnitStat = 11
	StatDodgeRating                           ModUnitStat = 12
	StatDeflectionRating                      ModUnitStat = 13
	StatAttackCriticalRating                  ModUnitStat = 14
	StatAbilityCriticalRating                 ModUnitStat = 15
	StatCriticalDamage                        ModUnitStat = 16
	StatAccuracy                              ModUnitStat = 17
	StatResistance                            ModUnitStat = 18
	StatDodgePercentAdditive                  ModUnitStat = 19
	StatDeflectionPercentAdditive             ModUnitStat = 20
	StatAttackCriticalPercentAdditive         ModUnitStat = 21
	StatAbilityCriticalPercentAdditive        ModUnitStat = 22
	StatArmorPercentAdditive                  ModUnitStat = 23
	StatSuppressionPercentAdditive            ModUnitStat = 24
	StatArmorPenetrationPercentAdditive       ModUnitStat = 25
	StatSuppressionPenetrationPercentAdditive ModUnitStat = 26
	StatHealthSteal                           ModUnitStat = 27
	StatMaxShield                             ModUnitStat = 28
	StatShieldPenetration                     ModUnitStat = 29
	StatHealthRegen                           ModUnitStat = 30
	StatAttackDamagePercentAdditive           ModUnitStat = 31
	StatAbilityPowerPercentAdditive           ModUnitStat = 32
	StatDodgeNegatePercentAdditive            ModUnitStat = 33
	StatDeflectionNegatePercentAdditive       ModUnitStat = 34
	StatAttackCriticalNegatePercentAdditive   ModUnitStat = 35
	StatAbilityCriticalNegatePercentAdditive  ModUnitStat = 36
	StatDodgeNegateRating                     ModUnitStat = 37
	StatDeflectionNegateRating                ModUnitStat = 38
	StatAttackCriticalNegateRating            ModUnitStat = 39
	StatAbilityCriticalNegateRating           ModUnitStat = 40
	StatOffense                               ModUnitStat = 41
	StatDefense                               ModUnitStat = 42
	StatDefensePenetration                    ModUnitStat = 43
	StatEvasionRating                         ModUnitStat = 44
	StatCriticalRating                        ModUnitStat = 45
	StatEvasionNegateRating                   ModUnitStat = 46
	StatCriticalNegateRating                  ModUnitStat = 47
	StatOffensePercentAdditive                ModUnitStat = 48
	StatDefensePercentAdditive                ModUnitStat = 49
	StatDefensePenetrationPercentAdditive     ModUnitStat = 50
	StatEvasionPercentAdditive                ModUnitStat = 51
	StatEvasionNegatePercentAdditive          ModUnitStat = 52
	StatCriticalChancePercentAdditive         ModUnitStat = 53
	StatCriticalNegateChancePercentAdditive   ModUnitStat = 54
	StatMaxHealthPercentAdditive              ModUnitStat = 55
	StatMaxShieldPercentAdditive              ModUnitStat = 56
	StatSpeedPercentAdditive                  ModUnitStat = 57
	StatCounterAttackRating                   ModUnitStat = 58
	StatTaunt                                 ModUnitStat = 59
)

Possible values for unit stats

func (ModUnitStat) MarshalText

func (s ModUnitStat) MarshalText() string

MarshalText implements encoding.TextMarshaler

func (ModUnitStat) MarshalYAML

func (s ModUnitStat) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler

func (ModUnitStat) String

func (s ModUnitStat) String() string

type Player

type Player struct {
	Name     string `json:"name"`
	AllyCode int    `json:"allyCode"`
	Level    int    `json:"level"`

	GuildName  string `json:"guildName"`
	GuildRefID string `json:"guildRefId"`

	Titles PlayerTitle `json:"titles"`

	Stats  []PlayerStat `json:"stats"`
	Roster Roster       `json:"roster"`

	Arena Arena `json:"arena"`

	UpdatedAt Timestamp `json:"updated"`
}

Player represents the full player profile information.

type PlayerStat

type PlayerStat struct {
	Name  string `json:"nameKey"`
	Value int64  `json:"value"`
	Index int64  `json:"index"`
}

PlayerStat is a single player profile statistic info, like how many battles won.

type PlayerTitle

type PlayerTitle struct {
	Selected string   `json:"selected"`
	Unlocked []string `json:"unlocked"`
}

PlayerTitle is a list of player unlocked and selected titles.

type Raid

type Raid struct {
	Rancor   string `json:"rancor"`
	AAT      string `json:"aat"`
	SithRaid string `json:"sith_raid"`
}

Raid contains information about the last performed raid for a guild.

type Relic

type Relic struct {
	Tier int `json:"currentTier"`
}

Relic contains the characte relic stats, such as tier.

type Roster

type Roster []Unit

Roster is a helper collection to manipulate player roster

func (Roster) FindByID

func (r Roster) FindByID(defID string) (*Unit, bool)

FindByID filter the unit collection by the DefID attribute

func (Roster) FindByName

func (r Roster) FindByName(unitName string) (*Unit, bool)

FindByName filter the unit collection by name attribute

func (Roster) Mods

func (r Roster) Mods() (mods []Mod)

Mods returns the roster equiped mods

type SquadUnit

type SquadUnit struct {
	ID     string        `json:"id"`
	UnitID string        `json:"defId"`
	Type   SquadUnitType `json:"squadUnitType"`
}

SquadUnit represents an arena squad unit identifier set.

type SquadUnitType

type SquadUnitType int

SquadUnitType is the enum value of an arena unit type

const (
	// SquadUnitNormal normal arena unit
	SquadUnitNormal SquadUnitType = 1
	// SquadUnitLeader leader arena unit
	SquadUnitLeader SquadUnitType = 2
	// SquadUnitCapitalShip captial ship arena unit
	SquadUnitCapitalShip SquadUnitType = 3
	// SquadUnitReinforcement reinforcement ship arena unit
	SquadUnitReinforcement SquadUnitType = 5
)

func (SquadUnitType) MarshalText

func (s SquadUnitType) MarshalText() string

MarshalText implemnts the encoding.TextMarshaler

func (SquadUnitType) String

func (s SquadUnitType) String() string

type Timestamp

type Timestamp time.Time

Timestamp is a helper unix timestamp JSON marshaller/unmarshaller. Source: https://gist.github.com/alexmcroberts/219127816e7a16c7bd70

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Timestamp) String

func (t Timestamp) String() string

String implements the Stringer interface.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(s []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface.

type Unit

type Unit struct {
	ID            string          `json:"id"`
	DefID         string          `json:"defId"`
	Name          string          `json:"nameKey"`
	Rarity        int             `json:"rarity"`
	Level         int             `json:"level"`
	XP            int             `json:"xp"`
	GalacticPower int             `json:"gp"`
	Gear          int             `json:"gear"`
	Equiped       []UnitEquipment `json:"equipped"`

	CombatType CombatType `json:"combatType"`

	Skills []UnitSkill `json:"skills"`
	Mods   []Mod       `json:"mods"`
	Crew   []Unit      `json:"crew"`
	Relic  Relic       `json:"relic"`

	Stats *UnitStats `json:"stats,omitempty"`
	Data  *DataUnit  `json:"data,omitempty"`
}

Unit is a game unit entity, character or ship.

type UnitEquipment

type UnitEquipment struct {
	EquipmentID string `json:"equipmentId"`
	Slot        int    `json:"slot"`
	NameKey     string `json:"nameKey"`
}

UnitEquipment is the unit equiped gear at the current level

type UnitSkill

type UnitSkill struct {
	ID     string `json:"id"`
	Tier   int    `json:"tier"`
	Name   string `json:"nameKey"`
	IsZeta bool   `json:"isZeta"`
}

UnitSkill is a single unit skill, with level and value

type UnitStatItems

type UnitStatItems struct {
	// Primary attributes
	Strength int `json:"Strength"`
	Agility  int `json:"Agility"`
	Tactics  int `json:"Tactics"`

	// General
	Health         int     `json:"Health"`
	Protection     int     `json:"Protection"`
	Speed          int     `json:"Speed"`
	CriticalDamage float64 `json:"Critical Damage"`
	Potency        float64 `json:"Potency"`
	Tenacity       float64 `json:"Tenacity"`
	HealthSteal    float64 `json:"Helth Steal"`

	// Physical Offense
	PhysicalDamage         int     `json:"Physical Damage"`
	PhysicalCriticalChance float64 `json:"Physical Critical Chance"`
	ArmorPenetration       int     `json:"Armor Penetration"`
	PhysicalAccuracy       float64 `json:"Physical Accuracy"`

	// Physical Survivability
	Armor                     float64 `json:"Armor"`
	DodgeChance               float64 `json:"Dodge Chance"`
	PhysicalCriticalAvoidance float64 `json:"Physical Critical Avoidance"`

	// Special Offense
	SpecialDamage         int     `json:"Special Damage"`
	SpecialCriticalChance float64 `json:"Special Critical Chance"`
	ResistancePenetration int     `json:"Resistance Penetration"`
	SpecialAccuracy       float64 `json:"Special Accuracy"`

	// Special Survivability
	Resistance               float64 `json:"Resistance"`
	DeflectionChance         float64 `json:"Deflection Chance"`
	SpecialCriticalAvoidance float64 `json:"Special Critical Avoidance"`
}

UnitStatItems is a set of character statistics such as health, speed, etc.

type UnitStats

type UnitStats struct {
	Final    UnitStatItems `json:"final"`
	FromMods UnitStatItems `json:"mods"`
}

UnitStats unit statis information split by Final and FromMods

Jump to

Keyboard shortcuts

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