-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_user_shelves.go
More file actions
153 lines (123 loc) · 4.7 KB
/
get_user_shelves.go
File metadata and controls
153 lines (123 loc) · 4.7 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package goodreads
import (
"encoding/xml"
"errors"
"fmt"
"log"
"net/http"
)
//GetUserShelves returns a summary of the shelves in the user's account. Requires OAuth
func (c Client) GetUserShelves(id string) (shelves Shelf_shelves, err error) {
var response Shelf_GoodreadsResponse
url := apiRoot + fmt.Sprintf("shelf/list.xml?key=%s&user_id=%s", c.consumerKey, id)
// Build the request
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Println("NewRequest: ", err)
return
}
client, err := c.GetHttpClient()
if err != nil {
log.Println("Do: ", err)
return
}
resp, err := client.Do(req)
if err != nil {
log.Println("Do: ", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err = errors.New(resp.Status)
return
}
if err = xml.NewDecoder(resp.Body).Decode(&response); err != nil {
log.Println(err)
return
}
return response.Shelf_shelves, nil
}
type Shelf_GoodreadsResponse struct {
Shelf_Request Shelf_Request `xml:" Request,omitempty" json:"Request,omitempty"`
Shelf_shelves Shelf_shelves `xml:" shelves,omitempty" json:"shelves,omitempty"`
}
type Shelf_Request struct {
Shelf_authentication Shelf_authentication `xml:" authentication,omitempty" json:"authentication,omitempty"`
Shelf_key Shelf_key `xml:" key,omitempty" json:"key,omitempty"`
Shelf_method Shelf_method `xml:" method,omitempty" json:"method,omitempty"`
}
type Shelf_authentication struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_book_count struct {
Attr_type string `xml:" type,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_description struct {
Attr_nil string `xml:" nil,attr" json:",omitempty"`
}
type Shelf_display_fields struct {
}
type Shelf_exclusive_flag struct {
Attr_type string `xml:" type,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_featured struct {
Attr_type string `xml:" type,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_id struct {
Attr_type string `xml:" type,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_key struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_method struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_name struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_order struct {
Attr_nil string `xml:" nil,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_per_page struct {
Attr_nil string `xml:" nil,attr" json:",omitempty"`
Attr_type string `xml:" type,attr" json:",omitempty"`
}
type Shelf_recommend_for struct {
Attr_type string `xml:" type,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Shelf_root struct {
Shelf_GoodreadsResponse Shelf_GoodreadsResponse `xml:" GoodreadsResponse,omitempty" json:"GoodreadsResponse,omitempty"`
}
type Shelf_shelves struct {
Attr_end string `xml:" end,attr" json:",omitempty"`
Attr_start string `xml:" start,attr" json:",omitempty"`
Attr_total string `xml:" total,attr" json:",omitempty"`
Shelf_user_shelf []Shelf_user_shelf `xml:" user_shelf,omitempty" json:"user_shelf,omitempty"`
}
type Shelf_sort struct {
Attr_nil string `xml:" nil,attr" json:",omitempty"`
}
type Shelf_sticky struct {
Attr_nil string `xml:" nil,attr" json:",omitempty"`
Attr_type string `xml:" type,attr" json:",omitempty"`
}
type Shelf_user_shelf struct {
Shelf_book_count Shelf_book_count `xml:" book_count,omitempty" json:"book_count,omitempty"`
Shelf_description Shelf_description `xml:" description,omitempty" json:"description,omitempty"`
Shelf_display_fields Shelf_display_fields `xml:" display_fields,omitempty" json:"display_fields,omitempty"`
Shelf_exclusive_flag Shelf_exclusive_flag `xml:" exclusive_flag,omitempty" json:"exclusive_flag,omitempty"`
Shelf_featured Shelf_featured `xml:" featured,omitempty" json:"featured,omitempty"`
Shelf_id Shelf_id `xml:" id,omitempty" json:"id,omitempty"`
Shelf_name Shelf_name `xml:" name,omitempty" json:"name,omitempty"`
Shelf_order Shelf_order `xml:" order,omitempty" json:"order,omitempty"`
Shelf_per_page Shelf_per_page `xml:" per_page,omitempty" json:"per_page,omitempty"`
Shelf_recommend_for Shelf_recommend_for `xml:" recommend_for,omitempty" json:"recommend_for,omitempty"`
Shelf_sort Shelf_sort `xml:" sort,omitempty" json:"sort,omitempty"`
Shelf_sticky Shelf_sticky `xml:" sticky,omitempty" json:"sticky,omitempty"`
}