-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreview_list.go
More file actions
376 lines (307 loc) · 13.3 KB
/
review_list.go
File metadata and controls
376 lines (307 loc) · 13.3 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
package goodreads
import (
"encoding/xml"
"errors"
"fmt"
"log"
"net/http"
"net/url"
"strconv"
)
const ()
type ReviewListParameters struct {
Shelf string
Sort string
Search string
Order string
Page int
PerPage int
}
//GetShelf is an alternate name for ReviewList because it's listed as both in the Goodreads API documentation
func (c Client) GetShelf(userID string, params ReviewListParameters) (response Reviews_reviews, err error) {
return c.ReviewList(userID, params)
}
//ReviewList returns the boks on shelves and reviews for the user. Requires OAuth
func (c Client) ReviewList(userID string, params ReviewListParameters) (response Reviews_reviews, err error) {
form := url.Values{}
form.Add("v", "2")
form.Add("id", userID)
form.Add("key", c.consumerKey)
if params.Shelf != "" {
form.Add("shelf", params.Shelf)
}
if params.Sort != "" {
form.Add("sort", params.Sort)
}
if params.Search != "" {
form.Add("search", params.Search)
}
if params.Order != "" {
form.Add("order", params.Order)
}
if params.Page > 0 {
form.Add("page", strconv.Itoa(params.Page))
}
if params.PerPage > 0 {
form.Add("per_page", strconv.Itoa(params.PerPage))
}
apiURL := fmt.Sprintf("%sreview/list.xml?%s", apiRoot, form.Encode())
// Build the request
req, err := http.NewRequest("GET", apiURL, nil)
if err != nil {
log.Println("NewRequest: ", err)
return
}
client, err := c.GetHttpClient()
if err != nil {
return
}
resp, err := client.Do(req)
if err != nil {
log.Println("Do: ", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return response, errors.New(resp.Status)
}
var goodreadsResponse Reviews_GoodreadsResponse
if err := xml.NewDecoder(resp.Body).Decode(&goodreadsResponse); err != nil {
log.Println(err)
}
return goodreadsResponse.Reviews_reviews, nil
}
type Reviews_GoodreadsResponse struct {
Reviews_Request Reviews_Request `xml:" Request,omitempty" json:"Request,omitempty"`
Reviews_reviews Reviews_reviews `xml:" reviews,omitempty" json:"reviews,omitempty"`
}
type Reviews_Request struct {
Reviews_authentication Reviews_authentication `xml:" authentication,omitempty" json:"authentication,omitempty"`
Reviews_key Reviews_key `xml:" key,omitempty" json:"key,omitempty"`
Reviews_method Reviews_method `xml:" method,omitempty" json:"method,omitempty"`
}
type Reviews_a struct {
Attr_href string `xml:" href,attr" json:",omitempty"`
Attr_rel string `xml:" rel,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_authentication struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_author struct {
Reviews_average_rating Reviews_average_rating `xml:" average_rating,omitempty" json:"average_rating,omitempty"`
Reviews_id Reviews_id `xml:" id,omitempty" json:"id,omitempty"`
Reviews_image_url Reviews_image_url `xml:" image_url,omitempty" json:"image_url,omitempty"`
Reviews_link Reviews_link `xml:" link,omitempty" json:"link,omitempty"`
Reviews_name Reviews_name `xml:" name,omitempty" json:"name,omitempty"`
Reviews_ratings_count Reviews_ratings_count `xml:" ratings_count,omitempty" json:"ratings_count,omitempty"`
Reviews_role Reviews_role `xml:" role,omitempty" json:"role,omitempty"`
Reviews_small_image_url Reviews_small_image_url `xml:" small_image_url,omitempty" json:"small_image_url,omitempty"`
Reviews_text_reviews_count Reviews_text_reviews_count `xml:" text_reviews_count,omitempty" json:"text_reviews_count,omitempty"`
}
type Reviews_authors struct {
Reviews_author Reviews_author `xml:" author,omitempty" json:"author,omitempty"`
}
type Reviews_average_rating struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_b struct {
Reviews_br []Reviews_br `xml:" br,omitempty" json:"br,omitempty"`
Reviews_i []Reviews_i `xml:" i,omitempty" json:"i,omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_body struct {
}
type Reviews_book struct {
Reviews_authors Reviews_authors `xml:" authors,omitempty" json:"authors,omitempty"`
Reviews_average_rating Reviews_average_rating `xml:" average_rating,omitempty" json:"average_rating,omitempty"`
Reviews_description Reviews_description `xml:" description,omitempty" json:"description,omitempty"`
Reviews_edition_information Reviews_edition_information `xml:" edition_information,omitempty" json:"edition_information,omitempty"`
Reviews_format Reviews_format `xml:" format,omitempty" json:"format,omitempty"`
Reviews_id Reviews_id `xml:" id,omitempty" json:"id,omitempty"`
Reviews_image_url Reviews_image_url `xml:" image_url,omitempty" json:"image_url,omitempty"`
Reviews_isbn Reviews_isbn `xml:" isbn,omitempty" json:"isbn,omitempty"`
Reviews_isbn13 Reviews_isbn13 `xml:" isbn13,omitempty" json:"isbn13,omitempty"`
Reviews_large_image_url Reviews_large_image_url `xml:" large_image_url,omitempty" json:"large_image_url,omitempty"`
Reviews_link Reviews_link `xml:" link,omitempty" json:"link,omitempty"`
Reviews_num_pages Reviews_num_pages `xml:" num_pages,omitempty" json:"num_pages,omitempty"`
Reviews_publication_day Reviews_publication_day `xml:" publication_day,omitempty" json:"publication_day,omitempty"`
Reviews_publication_month Reviews_publication_month `xml:" publication_month,omitempty" json:"publication_month,omitempty"`
Reviews_publication_year Reviews_publication_year `xml:" publication_year,omitempty" json:"publication_year,omitempty"`
Reviews_published Reviews_published `xml:" published,omitempty" json:"published,omitempty"`
Reviews_publisher Reviews_publisher `xml:" publisher,omitempty" json:"publisher,omitempty"`
Reviews_ratings_count Reviews_ratings_count `xml:" ratings_count,omitempty" json:"ratings_count,omitempty"`
Reviews_small_image_url Reviews_small_image_url `xml:" small_image_url,omitempty" json:"small_image_url,omitempty"`
Reviews_text_reviews_count Reviews_text_reviews_count `xml:" text_reviews_count,omitempty" json:"text_reviews_count,omitempty"`
Reviews_title Reviews_title `xml:" title,omitempty" json:"title,omitempty"`
Reviews_title_without_series Reviews_title_without_series `xml:" title_without_series,omitempty" json:"title_without_series,omitempty"`
}
type Reviews_br struct {
}
type Reviews_comments_count struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_date_added struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_date_updated struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_description struct {
Reviews_a Reviews_a `xml:" a,omitempty" json:"a,omitempty"`
Reviews_b []Reviews_b `xml:" b,omitempty" json:"b,omitempty"`
Reviews_br []Reviews_br `xml:" br,omitempty" json:"br,omitempty"`
Reviews_i []Reviews_i `xml:" i,omitempty" json:"i,omitempty"`
Reviews_p []Reviews_p `xml:" p,omitempty" json:"p,omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_edition_information struct {
}
type Reviews_em struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_format struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_i struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_id struct {
Attr_type string `xml:" type,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_image_url struct {
Attr_nophoto string `xml:" nophoto,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_isbn struct {
Attr_nil string `xml:" nil,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_isbn13 struct {
Attr_nil string `xml:" nil,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_key struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_large_image_url struct {
}
type Reviews_link struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_method struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_name struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_num_pages struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_owned struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_p struct {
Reviews_em Reviews_em `xml:" em,omitempty" json:"em,omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_publication_day struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_publication_month struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_publication_year struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_published struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_publisher struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_rating struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_ratings_count struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_read_at struct {
}
type Reviews_read_count struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_recommended_by struct {
}
type Reviews_recommended_for struct {
}
type Reviews_review struct {
Reviews_body Reviews_body `xml:" body,omitempty" json:"body,omitempty"`
Reviews_book Reviews_book `xml:" book,omitempty" json:"book,omitempty"`
Reviews_comments_count Reviews_comments_count `xml:" comments_count,omitempty" json:"comments_count,omitempty"`
Reviews_date_added Reviews_date_added `xml:" date_added,omitempty" json:"date_added,omitempty"`
Reviews_date_updated Reviews_date_updated `xml:" date_updated,omitempty" json:"date_updated,omitempty"`
Reviews_id Reviews_id `xml:" id,omitempty" json:"id,omitempty"`
Reviews_link Reviews_link `xml:" link,omitempty" json:"link,omitempty"`
Reviews_owned Reviews_owned `xml:" owned,omitempty" json:"owned,omitempty"`
Reviews_rating Reviews_rating `xml:" rating,omitempty" json:"rating,omitempty"`
Reviews_read_at Reviews_read_at `xml:" read_at,omitempty" json:"read_at,omitempty"`
Reviews_read_count Reviews_read_count `xml:" read_count,omitempty" json:"read_count,omitempty"`
Reviews_recommended_by Reviews_recommended_by `xml:" recommended_by,omitempty" json:"recommended_by,omitempty"`
Reviews_recommended_for Reviews_recommended_for `xml:" recommended_for,omitempty" json:"recommended_for,omitempty"`
Reviews_shelves Reviews_shelves `xml:" shelves,omitempty" json:"shelves,omitempty"`
Reviews_spoiler_flag Reviews_spoiler_flag `xml:" spoiler_flag,omitempty" json:"spoiler_flag,omitempty"`
Reviews_spoilers_state Reviews_spoilers_state `xml:" spoilers_state,omitempty" json:"spoilers_state,omitempty"`
Reviews_started_at Reviews_started_at `xml:" started_at,omitempty" json:"started_at,omitempty"`
Reviews_url Reviews_url `xml:" url,omitempty" json:"url,omitempty"`
Reviews_votes Reviews_votes `xml:" votes,omitempty" json:"votes,omitempty"`
}
type Reviews_reviews 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"`
Reviews_review []Reviews_review `xml:" review,omitempty" json:"review,omitempty"`
}
type Reviews_role struct {
}
type Reviews_root struct {
Reviews_GoodreadsResponse Reviews_GoodreadsResponse `xml:" GoodreadsResponse,omitempty" json:"GoodreadsResponse,omitempty"`
}
type Reviews_shelf struct {
Attr_exclusive string `xml:" exclusive,attr" json:",omitempty"`
Attr_name string `xml:" name,attr" json:",omitempty"`
Attr_review_shelf_id string `xml:" review_shelf_id,attr" json:",omitempty"`
Attr_sortable string `xml:" sortable,attr" json:",omitempty"`
}
type Reviews_shelves struct {
Reviews_shelf []Reviews_shelf `xml:" shelf,omitempty" json:"shelf,omitempty"`
}
type Reviews_small_image_url struct {
Attr_nophoto string `xml:" nophoto,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_spoiler_flag struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_spoilers_state struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_started_at struct {
}
type Reviews_text_reviews_count struct {
Attr_type string `xml:" type,attr" json:",omitempty"`
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_title struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_title_without_series struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_url struct {
Text string `xml:",chardata" json:",omitempty"`
}
type Reviews_votes struct {
Text string `xml:",chardata" json:",omitempty"`
}