From 21f44ebc06deebd5d01894f03f812f78bfd7e9d7 Mon Sep 17 00:00:00 2001 From: Allen Flickinger Date: Sat, 10 Apr 2021 17:31:15 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20=F0=9F=93=9A=20fix=20header=20ti?= =?UTF-8?q?me=20format=20/=20update=20README.md=20(#35)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 23 ++++++++++++++++++++++- examples/v2/authCodeFlow/main.go | 8 +++++++- examples/v2/simpleClient/main.go | 7 ++++++- v2/header.go | 10 +++++++--- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b961290..bd0a888 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ - [Fetching World of Warcraft Classic Data](#fetching-world-of-warcraft-classic-data) - [Authorization for User Data](#authorization-for-user-data) - [Fetching OAuth Data](#fetching-oauth-data) + - [Header Information](#header-information) - [Documentation](#documentation) - [Special Thanks](#special-thanks) @@ -30,7 +31,12 @@ go get github.com/FuzzyStatic/blizzard/v2 Start using the library by initiating a new Blizzard config structure for your desired region and locale (client_id and client_secret can be acquired through your developer account at [https://develop.battle.net/](https://develop.battle.net/)) and requesting an access token: ```go -blizz := blizzard.NewClient("client_id", "client_secret", blizzard.US, blizzard.EnUS) +blizz := blizzard.NewClient( + "client_id", + "client_secret", + blizzard.US, + blizzard.EnUS, +) err := blizz.AccessTokenRequest(ctx) if err != nil { @@ -233,6 +239,21 @@ if err != nil { fmt.Printf("%+v\n", dat) ``` +## Header Information + +Each API call will return HTTP response header information, if any. Use the second return variable to get a structure containing the response header information. + +```go +dat, header, err := c.WoWAuctions(context.Background(), 1138) +if err != nil { + fmt.Println(err) +} + +fmt.Println(header.BattlenetNamespace) +fmt.Println(header.LastModified) +... +``` + ## Documentation See the [Blizzard API reference](https://develop.battle.net/documentation/guides) and the [Go reference](https://pkg.go.dev/github.com/FuzzyStatic/blizzard/v2) for all the different datasets that can be acquired. diff --git a/examples/v2/authCodeFlow/main.go b/examples/v2/authCodeFlow/main.go index 1a61d4a..d17746d 100644 --- a/examples/v2/authCodeFlow/main.go +++ b/examples/v2/authCodeFlow/main.go @@ -92,7 +92,13 @@ func init() { } func main() { - blizz = blizzard.NewClient(clientID, clientSecret, blizzard.US, blizzard.EnUS) + blizz = blizzard.NewClient( + clientID, + clientSecret, + blizzard.US, + blizzard.EnUS, + ) + cfg = blizz.AuthorizeConfig(fmt.Sprintf("http://%s:9094/oauth2", myDomain), oauth.ProfileD3, oauth.ProfileSC2, oauth.ProfileWoW) http.HandleFunc("/", homepage) diff --git a/examples/v2/simpleClient/main.go b/examples/v2/simpleClient/main.go index 46cf8b9..a0d0bc3 100644 --- a/examples/v2/simpleClient/main.go +++ b/examples/v2/simpleClient/main.go @@ -28,7 +28,12 @@ func init() { } func main() { - blizz = blizzard.NewClient(clientID, clientSecret, blizzard.US, blizzard.EnUS) + blizz = blizzard.NewClient( + clientID, + clientSecret, + blizzard.US, + blizzard.EnUS, + ) err := blizz.AccessTokenRequest(context.Background()) if err != nil { diff --git a/v2/header.go b/v2/header.go index 62b5510..d69d9a8 100644 --- a/v2/header.go +++ b/v2/header.go @@ -1,4 +1,3 @@ -// Package header contains header information for Blizzard API calls package blizzard import ( @@ -6,6 +5,11 @@ import ( "time" ) +const ( + headerTimeFormat = "Mon, _2 Jan 2006 15:04:05 MST" +) + +// Header Keys const ( HeaderKeyBattlenetNamespace = "Battlenet-Namespace" HeaderKeyBattlenetSchema = "Battlenet-Schema" @@ -61,13 +65,13 @@ func getHeader(httpHeader http.Header) (*Header, error) { XTraceTraceID: httpHeader.Get(HeaderKeyXTraceTraceID), } if httpHeader.Get(HeaderKeyDate) != "" { - header.Date, err = time.Parse(time.RFC1123, httpHeader.Get(HeaderKeyDate)) + header.Date, err = time.Parse(headerTimeFormat, httpHeader.Get(HeaderKeyDate)) if err != nil { header.Date = time.Time{} } } if httpHeader.Get(HeaderKeyLastModified) != "" { - header.LastModified, err = time.Parse(time.RFC1123, httpHeader.Get(HeaderKeyLastModified)) + header.LastModified, err = time.Parse(headerTimeFormat, httpHeader.Get(HeaderKeyLastModified)) if err != nil { header.LastModified = time.Time{} }