-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.go
More file actions
73 lines (59 loc) · 1.83 KB
/
user.go
File metadata and controls
73 lines (59 loc) · 1.83 KB
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
package goodreads
import (
"encoding/xml"
"errors"
"log"
)
//QueryUser Returns the user id and profile link. Requires OAuth
func (c *Client) QueryUser() (user User_user, err error) {
client, err := c.GetHttpClient()
if err != nil {
return
}
resp, err := client.Get(
"https://www.goodreads.com/api/auth_user")
if err != nil {
return
}
if resp.StatusCode != 200 {
return user, errors.New(resp.Status)
}
defer resp.Body.Close()
var response User_GoodreadsResponse
if err := xml.NewDecoder(resp.Body).Decode(&response); err != nil {
log.Println(err)
}
return response.User_user, nil
}
type User_GoodreadsResponse struct {
User_Request User_Request `xml:" Request,omitempty" json:"Request,omitempty"`
User_user User_user `xml:" user,omitempty" json:"user,omitempty"`
}
type User_Request struct {
User_authentication User_authentication `xml:" authentication,omitempty" json:"authentication,omitempty"`
User_key User_key `xml:" key,omitempty" json:"key,omitempty"`
User_method User_method `xml:" method,omitempty" json:"method,omitempty"`
}
type User_authentication struct {
Text string `xml:",chardata" json:",omitempty"`
}
type User_key struct {
Text string `xml:",chardata" json:",omitempty"`
}
type User_link struct {
Text string `xml:",chardata" json:",omitempty"`
}
type User_method struct {
Text string `xml:",chardata" json:",omitempty"`
}
type User_name struct {
Text string `xml:",chardata" json:",omitempty"`
}
type User_root struct {
User_GoodreadsResponse User_GoodreadsResponse `xml:" GoodreadsResponse,omitempty" json:"GoodreadsResponse,omitempty"`
}
type User_user struct {
Attr_id string `xml:" id,attr" json:",omitempty"`
User_link User_link `xml:" link,omitempty" json:"link,omitempty"`
User_name User_name `xml:" name,omitempty" json:"name,omitempty"`
}