bnet

package
v0.0.0-...-7360598 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidRegion

func IsValidRegion(region string) bool

IsValidRegion accepts region strings "us" or "eu"

func RealmSlug

func RealmSlug(realm string) string

RealmSlug returns the normalized realm slug representation of a realm string

Types

type Accessor

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

Accessor handles OAuth and rate limiting for the BNet API

func NewAccessor

func NewAccessor(h Client, cacheAccessor cache.ICache) *Accessor

NewAccessor creates a new accessor while allowing the caller to provide a custom or mocked http accessor

func (*Accessor) ConnectedRealmID

func (a *Accessor) ConnectedRealmID(abLog *model.AucBotContext, realmSlug, region string) (int, error)

ConnectedRealmID retrieves a connected realm given the region and realm slug.

func (*Accessor) Get

func (a *Accessor) Get(abLog *model.AucBotContext, region, endpoint string) ([]byte, error)

Get wraps http.Get, monitoring rate limits. If limit is exceeded, will block until more requests can be sent. Get also handles OAuth credentials and retries

func (*Accessor) GetIfNotModified

func (a *Accessor) GetIfNotModified(abLog *model.AucBotContext, region, endpoint, since string) (string, []byte, error)

GetIfNotModified sets the If-Modified-Since header and returns true if a response was received, false otherwise

func (*Accessor) GetItemInfo

func (a *Accessor) GetItemInfo(abLog *model.AucBotContext, id int) (*model.Item, error)

GetItemInfo retrieves the item info from the api directly

func (*Accessor) GetItemInfoNoCache

func (a *Accessor) GetItemInfoNoCache(abLog *model.AucBotContext, id int) (*model.Item, error)

GetItemInfoNoCache retrieves the item while bypassing the item cache

func (*Accessor) IsValidRealm

func (a *Accessor) IsValidRealm(abLog *model.AucBotContext, realmSlug, region string) bool

IsValidRealm tests the given realmSlug and returns if it is valid

func (*Accessor) ParseRawRealmString

func (a *Accessor) ParseRawRealmString(ctx *model.AucBotContext, raw string) (string, string, error)

ParseRawRealmString tests if a raw realm string is valid Input looks like "arthas-us" This includes a connected realm check to Returns the region and realm slug if valid

func (*Accessor) SetRealmLists

func (a *Accessor) SetRealmLists(abLog *model.AucBotContext) error

SetRealmLists attempts to populate the list of connected realms accessible on all regions

type Client

type Client interface {
	Get(region string, endpoint string) ([]byte, http.Header, error)
	GetIfNotModified(region string, endpoint string, since string) (string, []byte, error)
}

type MockHTTP

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

MockHTTP implements HTTP and allows for supplying responses based on URL called

func NewMockHTTP

func NewMockHTTP(responseData map[string][]byte, urlShouldError []string) *MockHTTP

NewMockHTTP creates a mocked http accessor that returns data provided for a given url. keys are urls, values are json-encoded data urlShouldError can be nil, if not any url provided will throw an error in Get

func (*MockHTTP) Get

func (m *MockHTTP) Get(abLog *model.AucBotContext, endpoint string) (*[]byte, error)

Get gets a mocked value by endpoint

type OAuthResponse

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

OAuthResponse is the response struct for a client_credentials request

type RateLimitEntry

type RateLimitEntry struct {
	Timeout time.Time
	Count   int
}

RateLimitEntry stores information about a rate

Jump to

Keyboard shortcuts

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