hsapi

package module
v0.0.0-...-22362df Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2017 License: MIT Imports: 11 Imported by: 2

README

Hearthstone API GoDoc Build Status Go Report Card

Golang Bindings for the hearthstoneapi.com API

Summary

Unoficial hearthstoneapi Go Client Library

Instalation

go get github.com/eefret/hsapi

Documentation

For the general api docs please see the Official Mashape Docs. For details on all the functionality on this library, see the GoDoc documentation.

Usage Example

import(
    "github.com/eefret/hsapi"
    "fmt"
)

  // Search Example
  func main() {
  	api := hsapi.NewHsAPI("tntkXJyM7EmshBgQYsXtCHHEX8Izp1uHrN1jsnTpw7tNCxEZIN") // Get yours in mashape
	api.Debug = true // Will print debug outputs
	config := hsapi.NewCardSearch("tirion fordring") // or any incomplete search
	config.Collectible = true // To narrow the search a little more
	resp, _ := api.Search(config)
	fmt.Println(resp[0].Name) // Tirion Fordring
	
	c := hsapi.NewCardImage(resp[0].CardID)
	c.Gold = true
	resp, _ := api.CardImage(c)
	f, _ := os.Create("Tirion_Fordring.gif")
	defer f.Close()
	f.Write(resp.Image) // Writing []byte into the file

	//Now featuring card sounds
	c2 := hs.NewCardSound("EX1_383", hs.PLAY)
    c2.Locale = hs.EsES
    c2.Extension = hs.MP3
    resp, _ := api.CardSound(c2)
	f, _ := os.Create("Tirion_Fordring_Play.mp3")
	defer f.Close()
	f.Write(resp.Sound) // Writing []byte into the file
  }

Documentation

Index

Constants

View Source
const (
	BaseURL       = "https://omgvamp-hearthstone-v1.p.mashape.com/"
	INFO          = "info"
	CARDS         = "cards"
	GetCARD       = "cards/%v"
	CardBACK      = "cardbacks"
	CardSEARCH    = "cards/search/%v"
	CardBySET     = "cards/sets/%v"
	CardByCLASS   = "cards/classes/%v"
	CardByRACE    = "cards/races/%v"
	CardByQUALITY = "cards/qualities/%v"
	CardByTYPE    = "cards/types/%v"
	CardByFACTION = "cards/factions/%v"
	SoundsURL     = "http://wowimg.zamimg.com/hearthhead/sounds%v/VO_%v_%v_%v.%v"
)

All constants

Variables

View Source
var ErrMultipleCards = errors.New("Multiple Cards obtained in a single card context.")

ErrMultipleCards is thrown when a single card is required but the query returns several

Functions

This section is empty.

Types

type AllCardResponse

type AllCardResponse struct {
	Basic              []Card `json:"Basic"`
	BlackrockMountain  []Card `json:"Blackrock Mountain"`
	Classic            []Card `json:"Classic"`
	Credits            []Card `json:"Credits"`
	Debug              []Card `json:"Debug"`
	GoblinsvsGnomes    []Card `json:"Goblins vs Gnomes"`
	HeroSkins          []Card `json:"Hero Skins"`
	Missions           []Card `json:"Missions"`
	Naxxramas          []Card `json:"Naxxramas"`
	Promotion          []Card `json:"Promotion"`
	Reward             []Card `json:"Reward"`
	System             []Card `json:"System"`
	TavernBrawl        []Card `json:"Tavern Brawl"`
	TheGrandTournament []Card `json:"The Grand Tournament"`
}

AllCardResponse is a struct for allcards method

type AllCardsConfig

type AllCardsConfig struct {
	Attack      int
	Collectible bool
	Cost        int
	Durability  int
	Health      int
	Locale      Locale
}

AllCardsConfig configuration of the AllCards method

func NewAllCards

func NewAllCards() AllCardsConfig

NewAllCards creates a new AllCardsConfig no mandatory parameters required default locale is enUS

type BaseConfig

type BaseConfig struct {
	Attack      int
	Collectible bool
	Cost        int
	Durability  int
	Health      int
	Locale      Locale
}

BaseConfig is the base for most of the configuration types

type Card

type Card struct {
	Artist      string `json:"artist"`
	Attack      int    `json:"attack"`
	CardID      string `json:"cardId"`
	CardSet     string `json:"cardSet"`
	Collectible bool   `json:"collectible"`
	Cost        int    `json:"cost"`
	Elite       bool   `json:"elite"`
	Faction     string `json:"faction"`
	Flavor      string `json:"flavor"`
	Health      int    `json:"health"`
	Img         string `json:"img"`
	PlayerClass string `json:"playerClass"`
	ImgGold     string `json:"imgGold"`
	Locale      string `json:"locale"`
	Mechanics   []struct {
		Name string `json:"name"`
	} `json:"mechanics"`
	Name   string `json:"name"`
	Rarity string `json:"rarity"`
	Text   string `json:"text"`
	Type   string `json:"type"`
}

Card is the main struct for cards

type CardBack

type CardBack struct {
	CardBackID   string `json:"cardBackId"`
	Description  string `json:"description"`
	Enabled      bool   `json:"enabled"`
	HowToGet     string `json:"howToGet"`
	Img          string `json:"img"`
	ImgAnimated  string `json:"imgAnimated"`
	Locale       string `json:"locale"`
	Name         string `json:"name"`
	SortCategory string `json:"sortCategory"`
	SortOrder    string `json:"sortOrder"`
	Source       string `json:"source"`
}

CardBack is the response returned by the cardbacks endpoint

type CardBacksConfig

type CardBacksConfig struct {
	Locale Locale
}

CardBacksConfig configuration of the CardBacks method

func NewCardBacks

func NewCardBacks() CardBacksConfig

NewCardBacks creates a new CardBacksConfig no mandatory parameters required default locale is enUS

type CardImageConfig

type CardImageConfig struct {
	CardID string
	Gold   bool
	Locale Locale
}

CardImageConfig configuration of the CardImage method

func NewCardImage

func NewCardImage(cardID string) CardImageConfig

NewCardImage creates a new CardImageConfig CardID is mandatory default locale is enUS Gold is default false

type CardImageResponse

type CardImageResponse struct {
	Image         []byte
	ContentLength int64
	Extension     FileExtension
}

CardImageResponse is the response returned by the CardImage endpoint

type CardSearchConfig

type CardSearchConfig struct {
	Name        string
	Collectible bool
	Locale      Locale
}

CardSearchConfig configuration of the CardSearch method

func NewCardSearch

func NewCardSearch(name string) CardSearchConfig

NewCardSearch creates a new CardSearchConfig name parameter is mandatory default locale is enUS

type CardSoundConfig

type CardSoundConfig struct {
	CardID    string
	Type      SoundType
	Locale    Locale
	Extension FileExtension
}

CardSoundConfig configudation of the GetCardSound method

func NewCardSound

func NewCardSound(cardID string, soundType SoundType) CardSoundConfig

NewCardSound creates a new CardSoundConfig CardID and SoundType are mandatory, default local is enUS and default extension is MP3

type CardSoundResponse

type CardSoundResponse struct {
	Sound         []byte
	ContentLength int64
	Extension     FileExtension
	Type          SoundType
}

CardSoundResponse is the response returned by the CardSound endpoint

type CardsByClassConfig

type CardsByClassConfig struct {
	Class Class
	BaseConfig
}

CardsByClassConfig configuration of the CardsByClassConfig method

func NewCardsByClass

func NewCardsByClass(class Class) CardsByClassConfig

NewCardsByClass creates a new CardsByClassConfig set parameter is mandatory default locale is enUS

type CardsByFactionConfig

type CardsByFactionConfig struct {
	Faction Faction
	BaseConfig
}

CardsByFactionConfig configuration of the CardsByFaction method

func NewCardsByFaction

func NewCardsByFaction(faction Faction) CardsByFactionConfig

NewCardsByFaction creates a new CardsByFactionConfig faction parameter is mandatory default locale is enUS

type CardsByQualityConfig

type CardsByQualityConfig struct {
	Quality Quality
	BaseConfig
}

CardsByQualityConfig configuration of the CardsByQuality method

func NewCardsByQuality

func NewCardsByQuality(quality Quality) CardsByQualityConfig

NewCardsByQuality creates a new CardsByQualityConfig quality parameter is mandatory default local is enUS

type CardsByRaceConfig

type CardsByRaceConfig struct {
	Race Race
	BaseConfig
}

CardsByRaceConfig configuration of the CardsByRace method

func NewCardsByRace

func NewCardsByRace(race Race) CardsByRaceConfig

NewCardsByRace creates a new CardsByQualityConfig race parameter is mandatory default local is enUS

type CardsBySetConfig

type CardsBySetConfig struct {
	Set Set
	BaseConfig
}

CardsBySetConfig configuration of the CardsBySet method

func NewCardsBySet

func NewCardsBySet(set Set) CardsBySetConfig

NewCardsBySet creates a new CardsBySetConfig set parameter is mandatory default locale is enUS

type CardsByTypeConfig

type CardsByTypeConfig struct {
	Type Type
	BaseConfig
}

CardsByTypeConfig configuration of the CardsByType method

func NewCardsByType

func NewCardsByType(typ Type) CardsByTypeConfig

NewCardsByType creates a new CardsByTypeConfig type parameter is mandatory default local is enUS

type Class

type Class int

Class is the enum to define the classes

const (
	Druid Class = iota + 1
	Hunter
	Mage
	Paladin
	Priest
	Rogue
	Shaman
	Warlock
	Warrior
	Dream
)

Class objects

func (Class) String

func (c Class) String() string

type Faction

type Faction int

Faction is the enum for the factions

const (
	Horde Faction = iota + 1
	Alliance
	Neutral
)

Faction objects

func (Faction) String

func (f Faction) String() string

type FileExtension

type FileExtension int

FileExtension is the enum for the extensions

const (
	JPG FileExtension = iota + 1
	JPEG
	GIF
	PNG
	MP3
	OGG
)

FileExtension objects

func (FileExtension) String

func (f FileExtension) String() string

type GetCardConfig

type GetCardConfig struct {
	Name        string
	Collectible bool
	Locale      Locale
}

GetCardConfig configuration of the GetCard method

func NewGetCard

func NewGetCard(id string) GetCardConfig

NewGetCard creates a new GetCardConfig name parameter is mandatory, should be exact name or ID default local is enUS

type HsAPI

type HsAPI struct {
	Token  string       `json:"token"`
	Debug  bool         `json:"debug"`
	Client *http.Client `json:"-"`
}

HsAPI is the main struct for our API

func NewHsAPI

func NewHsAPI(token string) *HsAPI

NewHsAPI creates a new API with a token

func NewHsAPIWithClient

func NewHsAPIWithClient(token string, client *http.Client) *HsAPI

NewHsAPIWithClient returns a new client with a custom client

func (*HsAPI) AllCards

func (hs *HsAPI) AllCards(config AllCardsConfig) (AllCardResponse, error)

AllCards obtain all cards in Hearthstone

func (*HsAPI) CardBacks

func (hs *HsAPI) CardBacks(config CardBacksConfig) ([]CardBack, error)

CardBacks obtain all cards backs in Hearthstone

func (*HsAPI) CardImage

func (hs *HsAPI) CardImage(config CardImageConfig) (CardImageResponse, error)

CardImage returns an Image given a Card

func (*HsAPI) CardSound

func (hs *HsAPI) CardSound(config CardSoundConfig) (CardSoundResponse, error)

CardSound search a the sound card scrapping HearthHead if there is any match it returns it.

func (*HsAPI) CardsByClass

func (hs *HsAPI) CardsByClass(config CardsByClassConfig) ([]Card, error)

CardsByClass obtains all cards by class Class param is mandatory

func (*HsAPI) CardsByFaction

func (hs *HsAPI) CardsByFaction(config CardsByFactionConfig) ([]Card, error)

CardsByFaction obtains all cards by faction Faction param is mandatory

func (*HsAPI) CardsByQuality

func (hs *HsAPI) CardsByQuality(config CardsByQualityConfig) ([]Card, error)

CardsByQuality obtains all cards by quality Quality param is mandatory

func (*HsAPI) CardsByRace

func (hs *HsAPI) CardsByRace(config CardsByRaceConfig) ([]Card, error)

CardsByRace obtains all cards by race Race param is mandatory

func (*HsAPI) CardsBySet

func (hs *HsAPI) CardsBySet(config CardsBySetConfig) ([]Card, error)

CardsBySet obtains all cards of the given Set Set param is mandatory

func (*HsAPI) CardsByType

func (hs *HsAPI) CardsByType(config CardsByTypeConfig) ([]Card, error)

CardsByType obtains all cards by type Type param is mandatory

func (*HsAPI) GetCard

func (hs *HsAPI) GetCard(config GetCardConfig) ([]Card, error)

GetCard obtain a single card Exact Name or ID is mandatory, please use ID for more accurate

func (*HsAPI) Info

func (hs *HsAPI) Info(config InfoConfig) InfoResponse

Info obtains info about the API

func (*HsAPI) Search

func (hs *HsAPI) Search(config CardSearchConfig) ([]Card, error)

Search search for a card given a name query the Name query is Mandatory

type InfoConfig

type InfoConfig struct {
	Locale Locale
}

InfoConfig configuration of the Info method

func NewInfo

func NewInfo() InfoConfig

NewInfo creates a new InfoConfig no mandatory params default locale is enUS

type InfoResponse

type InfoResponse struct {
	Classes   []string `json:"classes"`
	Factions  []string `json:"factions"`
	Locales   []string `json:"locales"`
	Patch     string   `json:"patch"`
	Qualities []string `json:"qualities"`
	Races     []string `json:"races"`
	Sets      []string `json:"sets"`
	Types     []string `json:"types"`
}

InfoResponse is the response returned by the info endpoint

type Locale

type Locale int

Locale is the type that defines the language for the endpoints

const (
	DeDE Locale = iota + 1
	EnGB
	EnUS
	EsES
	EsMX
	FrFR
	ItIT
	KoKR
	PtBR
	RuRU
	ZhCN
	ZhTW
)

Locales objects

func (Locale) String

func (l Locale) String() string

type Quality

type Quality int

Quality is the enum for the qualities

const (
	Free Quality = iota + 1
	Common
	Rare
	Epic
	Legendary
)

Quality objects

func (Quality) String

func (q Quality) String() string

type Race

type Race int

Race is the enum for the race

const (
	Demon Race = iota + 1
	Dragon
	Mech
	Murloc
	Beast
	Pirate
	Totem
)

Race objects

func (Race) String

func (r Race) String() string

type Set

type Set int

Set is the type that defines cardsets in some of the endpoints

const (
	Basic Set = iota + 1
	Classic
	Credits
	Naxxramas
	Debug
	GoblinsvsGnomes
	Missions
	Promotion
	Reward
	System
	BlackrockMountain
	HeroSkins
	TavernBrawl
	TheGrandTournament
)

Set objects

func (Set) String

func (s Set) String() string

type SoundType

type SoundType int

SoundType is the enum for the extensions

const (
	PLAY SoundType = iota + 1
	ATTACK
	DEATH
	TRIGGER
)

SoundType objects

func (SoundType) String

func (s SoundType) String() string

type Type

type Type int

Type is the enum for the type

const (
	Hero Type = iota + 1
	Minion
	Spell
	Enchantment
	Weapon
	HeroPower
)

Type objects

func (Type) String

func (t Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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