forked from imwally/pinboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
55 lines (45 loc) · 986 Bytes
/
user.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
package pinboard
import (
"encoding/json"
)
type UserResource struct {
token string
}
func NewUserResource(token string) UserResource {
return UserResource{
token: token,
}
}
// userResponse holds the response from /user/secret and
// /user/api_token
type userResponse struct {
Result string `json:"result"`
}
// Secret returns the user's secret RSS key (for viewing private
// feeds).
func (r UserResource) Secret() (string, error) {
resp, err := get(userSecret, r.token, nil)
if err != nil {
return "", err
}
var ur userResponse
err = json.Unmarshal(resp, &ur)
if err != nil {
return "", err
}
return ur.Result, nil
}
// APIToken returns the user's API token (for making API calls
// without a password).
func (r UserResource) APIToken() (string, error) {
resp, err := get(userAPIToken, r.token, nil)
if err != nil {
return "", err
}
var ur userResponse
err = json.Unmarshal(resp, &ur)
if err != nil {
return "", err
}
return ur.Result, nil
}