-
Notifications
You must be signed in to change notification settings - Fork 1
/
shelves.go
57 lines (48 loc) · 1.69 KB
/
shelves.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
package books
// ShelvesService defines the behavior required by types that want to implement a new Shelf type.
type ShelvesService interface {
List(*ShelvesListOptions) ([]Shelf, *Response, error)
}
// GoogleShelvesService implements the VolumesService interface.
type GoogleShelvesService struct {
client *Client
}
// Shelf represents a Google Book Volume resource.
// https://developers.google.com/books/docs/v1/reference/bookshelves#resource
type Shelf struct {
ID *int `json:"id,omitempty"`
Title *string `json:"title,omitempty"`
VolumeCount *int `json:"volumeCount,omitempty"`
Description *string `json:"description,omitempty"`
Updated *string `json:"updated,omitempty"`
}
// shelvesRoot represents a response from Google Books API.
// https://developers.google.com/books/docs/v1/reference/mylibrary/bookshelves/list#response
type shelvesRoot struct {
Shelves []Shelf `json:"items"`
}
// ShelvesListOptions specifies the optional parameters needed to make API request.
// books.mylibrary.bookshelves.list
type ShelvesListOptions struct {
Source string `url:"source,omitempty"`
Fields string `url:"fields, omitempty,omitempty"`
}
// List will call the books.mylibrary.bookshelves.list API.
// https://www.googleapis.com/books/v1/mylibrary/bookshelves
func (v *GoogleShelvesService) List(opt *ShelvesListOptions) ([]Shelf, *Response, error) {
url := "mylibrary/bookshelves"
url, err := addOptions(url, opt)
if err != nil {
return nil, nil, err
}
req, err := v.client.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}
root := new(shelvesRoot)
resp, err := v.client.Do(req, root)
if err != nil {
return nil, resp, err
}
return root.Shelves, resp, err
}