Skip to content

Commit

Permalink
πŸš‘ πŸ“š fix header time format / update README.md (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
FuzzyStatic authored Apr 10, 2021
1 parent af0dfac commit 21f44eb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion examples/v2/authCodeFlow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion examples/v2/simpleClient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions v2/header.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Package header contains header information for Blizzard API calls
package blizzard

import (
"net/http"
"time"
)

const (
headerTimeFormat = "Mon, _2 Jan 2006 15:04:05 MST"
)

// Header Keys
const (
HeaderKeyBattlenetNamespace = "Battlenet-Namespace"
HeaderKeyBattlenetSchema = "Battlenet-Schema"
Expand Down Expand Up @@ -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{}
}
Expand Down

0 comments on commit 21f44eb

Please sign in to comment.