bungie

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//GetCurrentAccountEndpoint = "http://localhost:8000/account.json"
	//ItemsEndpointFormat       = "http://localhost:8000/%d/%s/items.json"
	//TransferItemEndpointURL           = "http://localhost:8000/d1/Platform/Destiny/TransferItem/"
	//EquipItemEndpointURL              = "http://localhost:8000/d1/Platform/Destiny/EquipItem/"
	GetCurrentAccountEndpoint            = "https://www.bungie.net/Platform/User/GetCurrentBungieAccount/"
	GetMembershipsForCurrentUserEndpoint = "https://www.bungie.net/Platform/User/GetMembershipsForCurrentUser/"
	GetProfileEndpointFormat             = "https://www.bungie.net/platform/Destiny2/%d/Profile/%s"
	TransferItemEndpointURL              = "https://www.bungie.net/Platform/Destiny2/Actions/Items/TransferItem/"
	EquipSingleItemEndpointURL           = "https://www.bungie.net/Platform/Destiny2/Actions/Items/EquipItem/"
	EquipMultiItemsEndpointURL           = "https://www.bungie.net/Platform/Destiny2/Actions/Items/EquipItems/"
)

Constant API endpoints

View Source
const (
	ProfilesComponent              = "100"
	VendorReceiptsComponent        = "101"
	ProfileInventoriesComponent    = "102"
	ProfileCurrenciesComponent     = "103"
	CharactersComponent            = "200"
	CharacterInventoriesComponent  = "201"
	CharacterProgressionsComponent = "202"
	CharacterRenderDataComponent   = "203"
	CharacterActivitiesComponent   = "204"
	CharacterEquipmentComponent    = "205"
	ItemInstancesComponent         = "300"
	ItemObjectivesComponent        = "301"
	ItemPerksComponent             = "302"
	ItemRenderDataComponent        = "303"
	ItemStatsComponent             = "304"
	ItemSocketsComponent           = "305"
	ItemTalentGridsComponent       = "306"
	ItemCommonDataComponent        = "307"
	ItemPlugStatesComponent        = "308"
	VendorsComponent               = "400"
	VendorCategoriesComponent      = "401"
	VendorSalesComponent           = "402"
	KiosksComponent                = "500"
)

Component constant values that are needed for certain Bungie API requests that specify which collections of values should be returned in the response.

View Source
const (
	UnknownTier  = 0
	CurrencyTier = 1
	BasicTier    = 2
	CommonTier   = 3
	RareTier     = 4
	SuperiorTier = 5
	ExoticTier   = 6
)

Destiny.TierType

View Source
const (
	CanTransfer         = 0
	ItemIsEquipped      = 1
	NotTransferrable    = 2
	NoRoomInDestination = 4
)

Destiny.TansferStatuses

View Source
const (
	UnknownLoc    = 0
	InventoryLoc  = 1
	VaultLoc      = 2
	VendorLoc     = 3
	PostmasterLoc = 4
)

Destiny.ItemLocation

View Source
const (
	WARLOCK = 2271682572
	TITAN   = 3655393761
	HUNTER  = 671679327
)

Hash values for different class types 'classHash' JSON key

View Source
const (
	TitanEnum        = 0
	HunterEnum       = 1
	WarlockEnum      = 2
	UnknownClassEnum = 3
)

Class Enum value passed in some of the Destiny API responses

View Source
const (
	AWOKEN = 2803282938
	HUMAN  = 3887404748
	EXO    = 898834093
)

Hash values for Race types 'raceHash' JSON key

View Source
const (
	MALE   = 3111576190
	FEMALE = 2204441813
)

Hash values for Gender 'genderHash' JSON key

View Source
const (
	MaleEnum          = 0
	FemaleEnum        = 1
	UnknownGenderEnum = 2
)

Gender Enum values used in some of the Bungie API responses

View Source
const (
	XBOX     = uint(1)
	PSN      = uint(2)
	BLIZZARD = uint(4)
	DEMON    = uint(10)
)

BungieMembershipType constant values

View Source
const (
	// TransferDelay will be the artificial between transfer requests to try and avoid throttling
	TransferDelay = 750 * time.Millisecond
)

Variables

This section is empty.

Functions

func CountItem

func CountItem(itemName, accessToken string) (*skillserver.EchoResponse, error)

CountItem will count the number of the specified item and return an EchoResponse that can be serialized and sent back to the Alexa skill.

func CreateLoadoutForCurrentCharacter added in v1.2.0

func CreateLoadoutForCurrentCharacter(accessToken, name string, shouldOverwrite bool) (*skillserver.EchoResponse, error)

CreateLoadoutForCurrentCharacter will create a new PersistedLoadout based on the items equipped to the user's current character and save them to the persistent storage.

func EquipMaxLightGear added in v0.3.0

func EquipMaxLightGear(accessToken string) (*skillserver.EchoResponse, error)

EquipMaxLightGear will equip all items that are required to have the maximum light on a character

func EquipNamedLoadout added in v1.2.0

func EquipNamedLoadout(accessToken, name string) (*skillserver.EchoResponse, error)

func GetOutboundIP added in v0.3.0

func GetOutboundIP() net.IP

GetOutboundIP gets preferred outbound ip of this machine

func GetProfileForCurrentUser added in v1.0.0

func GetProfileForCurrentUser(client *Client, responseChan chan *ProfileMsg)

GetProfileForCurrentUser will retrieve the Profile data for the currently logged in user (determined by the access_token)

func InitEnv added in v1.1.0

func InitEnv(apiKey string)

InitEnv provides a package level initialization point for any work that is environment specific

func PopulateBucketHashLookup added in v0.3.0

func PopulateBucketHashLookup() error

PopulateBucketHashLookup will fill the map that will be used to lookup bucket type hashes which will be used to determine which type of equipment a specific Item represents.

func PopulateEngramHashes added in v0.3.0

func PopulateEngramHashes() error

PopulateEngramHashes will intialize the map holding all item_hash values that represent engram types.

func PopulateItemMetadata added in v0.3.0

func PopulateItemMetadata() error

PopulateItemMetadata is responsible for loading all of the metadata fields that need to be loaded into memory for common inventory related operations.

func TransferItem

func TransferItem(itemName, accessToken, sourceClass, destinationClass string, count int) (*skillserver.EchoResponse, error)

TransferItem is responsible for calling the necessary Bungie.net APIs to transfer the specified item to the specified character. The quantity is optional as well as the source class. If no quantity is specified, all of the specific items will be transfered to the particular character.

func UnloadEngrams added in v0.3.0

func UnloadEngrams(accessToken string) (*skillserver.EchoResponse, error)

UnloadEngrams is responsible for transferring all engrams off of a character and

Types

type BaseResponse

type BaseResponse struct {
	ErrorCode       int         `json:"ErrorCode"`
	ThrottleSeconds int         `json:"ThrottleSeconds"`
	ErrorStatus     string      `json:"ErrorStatus"`
	Message         string      `json:"Message"`
	MessageData     interface{} `json:"MessageData"`
}

BaseResponse represents the data returned as part of all of the Bungie API requests.

type Character

type Character struct {
	//https://bungie-net.github.io/multi/schema_Destiny-Entities-Characters-DestinyCharacterComponent.html#schema_Destiny-Entities-Characters-DestinyCharacterComponent
	MembershipID         string    `json:"membershipId"`
	MembershipType       int       `json:"membershipType"`
	CharacterID          string    `json:"characterId"`
	DateLastPlayed       time.Time `json:"dateLastPlayed"`
	EmblemBackgroundPath string    `json:"emblemBackgroundPath"`
	RaceHash             uint      `json:"raceHash"`
	ClassHash            uint      `json:"classHash"`
	ClassType            int       `json:"classType"`
	Light                int       `json:"light"`
}

Character will represent a single in-game character as well as platform membership data, emblems, last played date, and character class and race.

func (*Character) String added in v1.1.0

func (c *Character) String() string

type CharacterList added in v0.3.0

type CharacterList []*Character

CharacterList represents a slice of Character pointers.

type CharacterMap added in v1.0.0

type CharacterMap map[string]*Character

CharacterMap will be a map that contains Character values with characterID keys.

type CharacterMappedItemListData added in v1.1.0

type CharacterMappedItemListData struct {
	Data map[string]*struct {
		Items ItemList `json:"items"`
	} `json:"data"`
}

type Client

type Client struct {
	*http.Client
	Address     string
	AccessToken string
	APIToken    string
}

Client is a type that contains all information needed to make requests to the Bungie API.

func NewCustomAddrClient added in v1.0.0

func NewCustomAddrClient(address string) (*Client, error)

NewCustomAddrClient will create a new Bungie Client instance with the provided local IP address.

func (*Client) AddAuthHeadersToRequest added in v1.0.0

func (c *Client) AddAuthHeadersToRequest(req *http.Request)

AddAuthHeadersToRequest will handle adding the authentication headers from the current client to the specified Request.

func (*Client) AddAuthValues added in v1.0.0

func (c *Client) AddAuthValues(accessToken, apiKey string)

AddAuthValues will add the specified access token and api key to the provided client

func (*Client) AuthenticationHeaders

func (c *Client) AuthenticationHeaders() map[string]string

AuthenticationHeaders will generate a map with the required headers to make an authenticated HTTP call to the Bungie API.

func (*Client) GetCurrentAccount

func (c *Client) GetCurrentAccount() (*CurrentUserMembershipsResponse, error)

GetCurrentAccount will request the user info for the current user based on the OAuth token provided as part of the request.

func (*Client) GetCurrentEquipment added in v1.2.0

func (c *Client) GetCurrentEquipment(membershipType int, membershipID string) (*GetProfileResponse, error)

func (*Client) GetUserProfileData added in v1.0.0

func (c *Client) GetUserProfileData(membershipType int, membershipID string) (*GetProfileResponse, error)

GetUserProfileData is responsible for loading all of the profiles, characters, equipments, and inventories for all of the supplied user's characters.

func (*Client) PostEquipItem added in v0.3.0

func (c *Client) PostEquipItem(body map[string]interface{}, isMultipleItems bool)

PostEquipItem is responsible for calling the Bungie.net API to equip an item on a specific character.

func (*Client) PostTransferItem

func (c *Client) PostTransferItem(body map[string]interface{})

PostTransferItem is responsible for calling the Bungie.net API to transfer an item from a source to a destination. This could be either a user's character or the vault.

type ClientPool added in v1.0.0

type ClientPool struct {
	Clients []*Client
	// contains filtered or unexported fields
}

ClientPool is a simple client buffer that will provided round robin access to a collection of Clients.

var Clients *ClientPool

Clients stores a list of bungie.Client instances that can be used to make HTTP requests to the Bungie API

func NewClientPool added in v1.0.0

func NewClientPool() *ClientPool

NewClientPool is a convenience initializer to create a new collection of Clients.

func (*ClientPool) Get added in v1.0.0

func (pool *ClientPool) Get() *Client

Get will return a pointer to the next Client that should be used.

type CurrentUserMembershipsResponse added in v1.0.0

type CurrentUserMembershipsResponse struct {
	*BaseResponse
	Response *struct {
		DestinyMemberships []*struct {
			DisplayName    string `json:"displayName"`
			MembershipType int    `json:"membershipType"`
			MembershipID   string `json:"membershipId"`
		} `json:"destinyMemberships"`
		BungieNetUser *struct {
			MembershipID string `json:"membershipId"`
		} `json:"bungieNetUser"`
	} `json:"Response"`
}

CurrentUserMembershipsResponse contains information about the membership data for the currently authorized user. The request for this information will use the access_token to determine the current user https://bungie-net.github.io/multi/operation_get_User-GetMembershipDataForCurrentUser.html#operation_get_User-GetMembershipDataForCurrentUser

type EquipmentBucket added in v0.3.0

type EquipmentBucket uint

EquipmentBucket is the type of the key for the bucket type hash lookup

const (
	Kinetic EquipmentBucket
	Energy
	Power
	Ghost
	Helmet
	Gauntlets
	Chest
	Legs
	ClassArmor
	Artifact
)

Equipment bucket type definitions

func (EquipmentBucket) String added in v0.3.0

func (bucket EquipmentBucket) String() string

type GetProfileResponse added in v1.0.0

type GetProfileResponse struct {
	*BaseResponse
	Response *struct {
		CharacterInventories *CharacterMappedItemListData `json:"characterInventories"`
		CharacterEquipment   *CharacterMappedItemListData `json:"characterEquipment"`
		ProfileInventory     *ItemListData                `json:"profileInventory"`
		ProfileCurrencies    *ItemListData                `json:"profileCurrencies"`
		ItemComponents       *struct {
			Instances *struct {
				Data map[string]*ItemInstance `json:"data"`
			} `json:"instances"`
		} `json:"itemComponents"`
		Profile *struct {
			//https://bungie-net.github.io/multi/schema_Destiny-Entities-Profiles-DestinyProfileComponent.html#schema_Destiny-Entities-Profiles-DestinyProfileComponent
			Data *struct {
				UserInfo *struct {
					MembershipType int    `json:"membershipType"`
					MembershipID   string `json:"membershipId"`
					DisplayName    string `json:"displayName"`
				} `json:"userInfo"`
			} `json:"data"`
		} `json:"profile"`
		Characters *struct {
			Data CharacterMap `json:"data"`
		} `json:"Characters"`
	} `json:"Response"`
}

GetProfileResponse is the response from the GetProfile endpoint. This data contains information about the characeters, inventories, profile inventory, and equipped loadouts. https://bungie-net.github.io/multi/operation_get_Destiny2-GetProfile.html#operation_get_Destiny2-GetProfile

type Item

type Item struct {
	// DestinyItemComponent https://bungie-net.github.io/multi/schema_Destiny-Entities-Items-DestinyItemComponent.html#schema_Destiny-Entities-Items-DestinyItemComponent
	ItemHash       uint   `json:"itemHash"`
	InstanceID     string `json:"itemInstanceId"`
	BucketHash     uint   `json:"bucketHash"`
	Lockable       bool   `json:"lockable"`
	BindStatus     int    `json:"bindStatus"`
	State          int    `json:"state"`
	Location       int    `json:"location"`
	TransferStatus int    `json:"transferStatus"`
	Quantity       int    `json:"quantity"`
	*ItemInstance
	*Character
}

Item represents a single inventory item returned usually by the GetProfile endpoint

func (*Item) IsInVault added in v1.1.0

func (i *Item) IsInVault() bool

IsInVault will determine if the item is in the vault or not. True if it is; False if it is not.

func (*Item) Power added in v1.0.0

func (i *Item) Power() int

Power is a convenience accessor to return the power level for a specific item or zero if it does not apply.

func (*Item) String added in v0.3.0

func (i *Item) String() string

type ItemFilter added in v0.3.0

type ItemFilter func(*Item, interface{}) bool

ItemFilter is a type that will be used as a paramter to a filter function. The parameter will be a function pointer. The function pointed to will need to return true if the element meets some criteria and false otherwise. If the result of this filter is false, then the item will be removed.

type ItemInstance added in v1.0.0

type ItemInstance struct {
	//https://bungie-net.github.io/multi/schema_Destiny-Entities-Items-DestinyItemInstanceComponent.html#schema_Destiny-Entities-Items-DestinyItemInstanceComponent
	IsEquipped        bool `json:"isEquipped"`
	CanEquip          bool `json:"canEquip"`
	Quality           int  `json:"quality"`
	CannotEquipReason int  `json:"cannotEquipReason"`
	DamageType        int
	PrimaryStat       *struct {
		//https://bungie-net.github.io/multi/schema_Destiny-DestinyStat.html#schema_Destiny-DestinyStat
		StatHash     uint `json:"statHash"`
		Value        int  `json:"value"`
		MaximumValue int  `json:"maximumValue"`
		ItemLevel    int  `json:"itemLevel"`
	} `json:"primaryStat"`
}

ItemInstance will hold information about a specific instance of an instanced item, this can include item stats, perks, etc. as well as equipped status and things like that.

type ItemList added in v0.3.0

type ItemList []*Item

ItemList is just a wrapper around a slice of Item pointers. This will make it possible to write a filter method that is called on a slice of Items.

func (ItemList) FilterItems added in v0.3.0

func (items ItemList) FilterItems(filter ItemFilter, arg interface{}) ItemList

FilterItems will filter the receiver slice of Items and return only the items that match the criteria specified in ItemFilter. If ItemFilter returns True, the element will be included, if it returns False the element will be removed.

type ItemListData added in v1.1.0

type ItemListData struct {
	Data *struct {
		Items ItemList `json:"items"`
	} `json:"data"`
}

type ItemMetadata added in v0.3.0

type ItemMetadata struct {
	TierType   int
	ClassType  int
	BucketHash uint
}

ItemMetadata is responsible for holding data from the manifest in-memory that is used often when interacting wth different character's inventories. These values are used so much that it would be a big waste of time to query the manifest data from the DB for every use.

type LastPlayedSort added in v0.3.0

type LastPlayedSort CharacterList

LastPlayedSort specifies a specific type for CharacterList that can be sorted by the date the character was last played.

func (LastPlayedSort) Len added in v0.3.0

func (characters LastPlayedSort) Len() int

func (LastPlayedSort) Less added in v0.3.0

func (characters LastPlayedSort) Less(i, j int) bool

func (LastPlayedSort) Swap added in v0.3.0

func (characters LastPlayedSort) Swap(i, j int)

type LightSort added in v0.3.0

type LightSort ItemList

LightSort specifies a specific type for ItemList that can be sorted by Light value of each item.

func (LightSort) Len added in v0.3.0

func (items LightSort) Len() int

func (LightSort) Less added in v0.3.0

func (items LightSort) Less(i, j int) bool

func (LightSort) Swap added in v0.3.0

func (items LightSort) Swap(i, j int)

type Loadout added in v0.3.0

type Loadout map[EquipmentBucket]*Item

Loadout will hold all items for a unique set of weapons, armor, ghost, class item, and artifact

type PersistedItem added in v1.2.0

type PersistedItem struct {
	ItemHash   uint   `json:"itemHash"`
	InstanceID string `json:"itemInstanceId"`
	BucketHash uint   `json:"bucketHash"`
}

PersistedItem represents the data from a specific Item entry that should be persisted. Not all of the Item data should be stored as most of it could/will change by the time it is read back from persistent storage

type PersistedLoadout added in v1.2.0

type PersistedLoadout map[EquipmentBucket]*PersistedItem

PersistedLoadout stores all of the PersistedItem entries that should be saved for a particular loadout.

type Profile added in v1.0.0

type Profile struct {
	MembershipType        int
	MembershipID          string
	BungieNetMembershipID string
	DateLastPlayed        time.Time
	DisplayName           string
	Characters            CharacterList

	AllItems ItemList
}

Profile contains all information about a specific Destiny membership, including character and inventory information.

type ProfileMsg added in v1.0.0

type ProfileMsg struct {
	*Profile
	// contains filtered or unexported fields
}

ProfileMsg is a wrapper around a Profile struct that should be used exclusively for sending a Profile over a channel, or at least in cases where an error also needs to be sent to indicate failures.

Jump to

Keyboard shortcuts

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