-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.go
executable file
·128 lines (118 loc) · 3.21 KB
/
account.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package golink
import (
"fmt"
"net/url"
"strconv"
"time"
)
type aStatus struct {
Paid time.Time
Created time.Time
Logins int64
MinutesPlayed int64
}
var key_types = map[string]string{"Account": "account", "Character": "char", "Corporation": "corp"}
func (a *CredentialedAPI) AccountStatus() (aStatus, error) {
result, err := a.Get("account/AccountStatus", url.Values{})
r := aStatus{}
if err != nil {
return r, err
}
if r.Paid, err = getTimeValue(result, "paidUntil"); err != nil {
return r, err
}
if r.Created, err = getTimeValue(result, "createDate"); err != nil {
return r, err
}
if r.Logins, err = getIntValue(result, "logonCount"); err != nil {
return r, err
}
if r.MinutesPlayed, err = getIntValue(result, "logonMinutes"); err != nil {
return r, err
}
return r, nil
}
type aCharacter struct {
Id int64
Name string
CorpId int64
CorpName string
}
type aKInfo struct {
AccessMask int64
Type string
Expires *time.Time
Characters map[int64]aCharacter
}
func (a *CredentialedAPI) AccountKeyInfo() (aKInfo, error) {
result, err := a.Get("account/APIKeyInfo", url.Values{})
var ok bool
r := aKInfo{}
if err != nil {
return r, err
}
result = result.Find("key")
if r.AccessMask, err = strconv.ParseInt(first(result.Get("accessMask")), 0, 64); err != nil {
return r, err
}
if r.Type, ok = key_types[first(result.Get("type"))]; ok == false {
return r, fmt.Errorf("No key type returned from API server.")
}
if temp, ok := result.Get("expires"); ok == false {
r.Expires = nil
} else {
temp, err := parseEveTs(temp)
if err != nil {
return r, err
}
r.Expires = &temp
}
r.Characters = make(map[int64]aCharacter)
rowset := result.Find("rowset")
for _, row := range rowset.FindAll("row") {
c := aCharacter{}
if c.Id, err = strconv.ParseInt(first(row.Get("characterID")), 0, 64); err != nil {
return r, err
}
if c.Name, ok = row.Get("characterName"); ok == false {
return r, fmt.Errorf("Unable to extract a character name.")
}
if c.CorpId, err = strconv.ParseInt(first(row.Get("corporationID")), 0, 64); err != nil {
return r, err
}
if c.CorpName, ok = row.Get("corporationName"); ok == false {
return r, fmt.Errorf("Unable to extract a corp name for %v.", c.Name)
}
r.Characters[c.Id] = c
}
return r, nil
}
func (a *CredentialedAPI) AccountCharacters() (map[int64]aCharacter, error) {
result, err := a.Get("account/Characters", url.Values{})
r := make(map[int64]aCharacter)
var ok bool
if err != nil {
return nil, err
}
rowset := result.Find("rowset")
if rowset == nil {
return nil, fmt.Errorf("Unable to extract rowset from API response.")
}
for _, row := range rowset.FindAll("row") {
c := aCharacter{}
if c.Id, err = strconv.ParseInt(first(row.Get("characterID")), 0, 64); err != nil {
return nil, err
}
if c.Name, ok = row.Get("name"); ok == false {
return nil, fmt.Errorf("Unable to extract a character name.")
}
if c.CorpId, err = strconv.ParseInt(first(row.Get("corporationID")), 0, 64); err != nil {
return nil, err
}
if c.CorpName, ok = row.Get("corporationName"); ok == false {
return nil, fmt.Errorf("Unable to extract a corp name for %v.", c.Name)
}
r[c.Id] = c
}
return r, nil
}