forked from mitchellh/go-bnet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
response.go
46 lines (39 loc) · 1016 Bytes
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package bnet
import (
"net/http"
"strconv"
"time"
)
// Reponse is a Battle.net API response. This wraps the standard http.Response
// and provides convenient access to some of the metadata returned.
type Response struct {
*http.Response
QPSCurrent int
QPSAllotted int
QuotaCurrent int
QuotaAllotted int
QuotaReset time.Time
}
func newResponse(r *http.Response) *Response {
result := &Response{Response: r}
result.parseMeta()
return result
}
func (r *Response) parseMeta() {
// Parse the basic ints
intMaps := map[string]*int{
"X-Plan-Qps-Allotted": &r.QPSAllotted,
"X-Plan-Qps-Current": &r.QPSCurrent,
"X-Plan-Quota-Allotted": &r.QuotaAllotted,
"X-Plan-Quota-Current": &r.QuotaCurrent,
}
for k, ptr := range intMaps {
if v := r.Response.Header.Get(k); v != "" {
*ptr, _ = strconv.Atoi(v)
}
}
// Parse the reset time
if v := r.Response.Header.Get("X-Plan-Quota-Reset"); v != "" {
r.QuotaReset, _ = time.Parse("Monday, January 2, 2006 3:04:05 PM MST", v)
}
}