battlenet

package module
v0.0.0-...-3525954 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2019 License: MIT Imports: 9 Imported by: 6

README

BattleNet

Build Status Go Report Card GoDoc

A Golang library for retrieving data from Blizzard's Battle.net API.

Requires Go 1.12 or higher.

Install

$ go get github.com/munsy/battlenet

Example

package main

import (
        "flag"
        "fmt"
        "net/http"
        "time"

        "github.com/munsy/battlenet"
)

var tokenFlag = flag.String("t", "", "Battle.net API token (required).")

func main() {
        flag.Parse()

        if *tokenFlag == "" {
                fmt.Println("No token provided.")
                return
        }

        // Create settings for the client. This is not required, but
        // is necessary for non-default settings.
        settings := &battlenet.Settings{
                Client: &http.Client{Timeout: (10 * time.Second)},
                Locale: battlenet.Locale.AmericanEnglish,
                Region: battlenet.Regions.US,
        }

        // Create a new client for accessing the Battle.net Account API.
        // There are also clients for Diablo III, Starcraft II, and WoW.
        client, err := battlenet.AccountClient(settings, *tokenFlag)

        if nil != err {
                panic(err)
        }

        // Make a request. Each method corresponds to a Battle.net endpoint.
        response, err := client.BattleID()

        if nil != err {
                panic(err)
        }

        // Get the underlying data. You can also see the endpoint that was called,
        // as well as your quota usage.
        bid := response.Data

        fmt.Printf("ID: %d\n", bid.ID)
        fmt.Printf("BattleTag: %s\n", bid.BattleTag)
}

$ go build -o account.exe
$ ./account.exe -t $YOUR_API_TOKEN_HERE
ID: 12345654321
BattleTag: Munsy#78910

Additional examples for Diablo III, Starcraft II, and World of Warcraft can be found in the examples package.

Bug Reporting/Fixing

Please submit all bug reports as issues. This section will be updated in the future with a more comprehensive guide to submitting helpful bug reports and/or bug fixes.

Contributing

  • Testing is mostly what is needed right now
  • Submit contributions as pull requests

Licensing

GoBattleNet is licensed under the MIT License. See LICENSE for the full license text.

Documentation

Overview

Package battlenet provides clients for accessing Blizzard Entertainment's various Battle.net API endpoints, including ones for Diablo III, Starcraft II, Overwatch, and World of Warcraft.

Official Battle.net API documentation can be found at: https://dev.battle.net/io-docs

Index

Constants

This section is empty.

Variables

View Source
var Endpoint = func(r regions.Region) oauth2.Endpoint {
	return oauth2.Endpoint{
		AuthURL:  r.AuthURL(),
		TokenURL: r.TokenURL(),
	}
}

Endpoint is Battle.net's OAuth 2.0 endpoint. Defaults to US if Region is not otherwise defined.

For more information see: https://dev.battle.net/docs/read/oauth

View Source
var Locale = struct {
	AmericanEnglish     locale.Locale
	BrazilianPortuguese locale.Locale
	BritishEnglish      locale.Locale
	CastilianSpanish    locale.Locale
	EuropeanPortuguese  locale.Locale
	MexicanSpanish      locale.Locale
	SimplifiedChinese   locale.Locale
	StandardFrench      locale.Locale
	StandardGerman      locale.Locale
	StandardItalian     locale.Locale
	StandardKorean      locale.Locale
	StandardRussian     locale.Locale
	TraditionalChinese  locale.Locale
}{
	locale.AmericanEnglish,
	locale.BrazilianPortuguese,
	locale.BritishEnglish,
	locale.CastilianSpanish,
	locale.EuropeanPortuguese,
	locale.MexicanSpanish,
	locale.SimplifiedChinese,
	locale.StandardFrench,
	locale.StandardGerman,
	locale.StandardItalian,
	locale.StandardKorean,
	locale.StandardRussian,
	locale.TraditionalChinese,
}

Locale holds all of the possible Battle.net locale definitions.

View Source
var Regions = struct {
	US  regions.Region
	EU  regions.Region
	KR  regions.Region
	TW  regions.Region
	SEA regions.Region
	CN  regions.Region
}{
	US:  regions.US,
	EU:  regions.EU,
	KR:  regions.KR,
	TW:  regions.TW,
	SEA: regions.SEA,
	CN:  regions.CN,
}

Regions holds all of the possible Battle.net regions.

Functions

func AccountClient

func AccountClient(s *Settings, token string) (*account.Client, error)

AccountClient returns a new client for accessing the Battle.net Account API.

func D3Client

func D3Client(s *Settings, key string) (*d3.Client, error)

D3Client returns a new client for accessing the Diablo III API.

func SC2Client

func SC2Client(s *Settings, key string) (*sc2.Client, error)

SC2Client returns a new client for accessing the Starcraft II API.

func WoWClient

func WoWClient(s *Settings, key string) (*wow.Client, error)

WoWClient returns a new client for accessing the World of Warcraft API.

Types

type Client

type Client interface {
	// Region returns the client's current region as a string.
	Region() string

	// Locale returns the client's current locale as a string.
	Locale() string

	// UserAgent returns the client User-Agent header used in API requests.
	UserAgent() string
}

Client defines the Battle.net API client interface.

type Quota

type Quota interface {
	// QPSAllotted returns the allotted QPS.
	QPSAllotted() int

	// QPSCurrent returns the current QPS.
	QPSCurrent() int

	// QuotaAlloted returns the alloted quota.
	QuotaAlloted() int

	// QuotaCurrent returns the current quota.
	QuotaCurrent() int

	// QuotaReset returns the time the quota will reset.
	QuotaReset() time.Time
}

Quota defines the battlenet.Quota interface.

type Settings

type Settings struct {
	Client *http.Client
	Locale locale.Locale
	Region regions.Region
}

Settings defines settings for a Client.

Directories

Path Synopsis
Package errors defines errors that are potentially returned from gobattlenet clients.
Package errors defines errors that are potentially returned from gobattlenet clients.
Package examples provides various examples for using the gobattlenet library.
Package examples provides various examples for using the gobattlenet library.
d3
sc2
wow
Package http contains all of the clients for accessing and obtaining data from the Battle.net API.
Package http contains all of the clients for accessing and obtaining data from the Battle.net API.
account
Package account contains the account client defintions for accessing and obtaining data from the Battle.net API.
Package account contains the account client defintions for accessing and obtaining data from the Battle.net API.
account/response
Package response contains all of the account response defintions returned by the Battle.net API.
Package response contains all of the account response defintions returned by the Battle.net API.
d3
Package d3 contains the Diablo III client defintions for accessing and obtaining data from the Battle.net API.
Package d3 contains the Diablo III client defintions for accessing and obtaining data from the Battle.net API.
d3/response
Package response contains all of the Diablo III response defintions returned by the Battle.net API.
Package response contains all of the Diablo III response defintions returned by the Battle.net API.
sc2
Package sc2 contains the Starcraft II client defintions for accessing and obtaining data from the Battle.net API.
Package sc2 contains the Starcraft II client defintions for accessing and obtaining data from the Battle.net API.
sc2/response
Package response contains all of the Starcraft II response defintions returned by the Battle.net API.
Package response contains all of the Starcraft II response defintions returned by the Battle.net API.
wow
Package wow contains the World of Warcraft client defintions for accessing and obtaining data from the Battle.net API.
Package wow contains the World of Warcraft client defintions for accessing and obtaining data from the Battle.net API.
wow/response
Package response contains all of the World of Warcraft response defintions returned by the Battle.net API.
Package response contains all of the World of Warcraft response defintions returned by the Battle.net API.
Package locale defines valid language and country sets for accessing the Battle.net API.
Package locale defines valid language and country sets for accessing the Battle.net API.
Package models defines all data models returned by the Battle.net API.
Package models defines all data models returned by the Battle.net API.
account
Package account defines profile data models returned by the Battle.net API.
Package account defines profile data models returned by the Battle.net API.
d3
Package d3 defines Diablo III data models returned by the Battle.net API.
Package d3 defines Diablo III data models returned by the Battle.net API.
sc2
Package sc2 defines Starcraft II data models returned by the Battle.net API.
Package sc2 defines Starcraft II data models returned by the Battle.net API.
wow
Package wow defines World of Warcraft data models returned by the Battle.net API.
Package wow defines World of Warcraft data models returned by the Battle.net API.
Package quota contains usage data about the Battle.net API, which comes back as part of the response headers after you make a call with one of the gobattlenet clients.
Package quota contains usage data about the Battle.net API, which comes back as part of the response headers after you make a call with one of the gobattlenet clients.
Package regions defines all possible Blizzard regions for communicating with the Battle.net API.
Package regions defines all possible Blizzard regions for communicating with the Battle.net API.

Jump to

Keyboard shortcuts

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