Categorygithub.com/mitchellh/go-bnet
modulepackage
0.0.0-20170611095832-bdcec587acb8
Repository: https://github.com/mitchellh/go-bnet.git
Documentation: pkg.go.dev

# README

go-bnet

go-bnet is a Go client library for accessing the Battle.net API. In addition to providing an API client, this package provides OAuth endpoints.

Documentation: GoDoc

Build Status: Build Status

API Coverage: Currently only the account information API is implemented. However, the base helpers are there to easily and quickly implement any other APIs such as the WoW or SC2 data.

Usage

import "github.com/mitchellh/go-bnet"

Authentication

Authenticate using the Go OAuth2 library. Endpoints are provided via the Endpoint function. A guide to using OAuth2 to authenticate is available in this blog post. The blog post uses GitHub as an example but it is almost identical for Battle.net and this library.

Battle.net endpoints are region-specific, so specify the region to the Endpoint function and use the resulting value. Example:

oauthCfg := &oauth2.Config{
    // Get from dev.battle.net
    ClientID:     "",
    ClientSecret: "",

    // Endpoint from this library
    Endpoint: bnet.Endpoint("us"),
}

Once you have access to the OAuth client, you can initilize the Battle.net API client:

// Token from prior auth
authClient := oauthCfg.Client(oauth2.NoContext, token)

// Initialize the client
client := bnet.NewClient(oauthClient)

// ... API calls

API Calls

Once a client is made, basic API calls can easliy be made:

user, resp, err := client.Account().User()
fmt.Printf("User: %#v", user)

All API calls return a *Response value in addition to a richer type and error. The response contains the http.Response as well as metadata such as quotas, QPS, etc. from Battle.net

# Functions

CheckError checks for an error in the given response.
Endpoint returns the endpoint for the given region.
NewClient creates a new Battle.net client.

# Structs

AccountService has account-related APIs.
Achievement represents a single Starcraft 2 achievement.
Achievements represents achievement information for a Starcraft 2 profile.
Career represents game statistics for a character's Battle.net career.
CharacterImage is a character's portrait or avatar.
Client is the API client for Battle.net.
ErrorResponse is the error response structure from the Battle.net API.
Level is the current level and XP a character has earned.
Points holds a character's total achievement points.
ProfileService has OAuth Profile APIs.
Reponse is a Battle.net API response.
Rewards represents selected and earned rewards for a profile.
SC2Character represents a character in a user's Starcraft 2 profile.
SC2Profile represents the profile information for a user's Starcraft 2 profile.
SC2Service has Starcraft2-related APIs.
Season is the current Starcraft 2 online multiplayer season.
SwarmLevels represents a character's level for each swarm (race) as well as their overall level.
User represents the user information for a Battle.net account.