diff --git a/VERSION.txt b/VERSION.txt index 9ff151c..a1c2c6a 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -v0.1.0 \ No newline at end of file +v0.1.1 \ No newline at end of file diff --git a/goodreads/shelves.go b/goodreads/shelves.go index 86588ab..8e8cc52 100644 --- a/goodreads/shelves.go +++ b/goodreads/shelves.go @@ -3,6 +3,7 @@ package goodreads import ( "fmt" "net/http" + "strconv" ) // ListShelves for current user. @@ -19,16 +20,26 @@ func (c *Client) ListShelves(userID string) ([]UserShelf, error) { // ListShelfBooks returns books by from a shelf. func (c *Client) ListShelfBooks(shelf string, userID string) ([]Book, error) { + var books []Book args := make(map[string]string) args["shelf"] = shelf args["v"] = "2" - listShelfEndpoint := fmt.Sprintf("%s/%s.xml", ListShelfEndpoint, userID) - data, err := c.doRequest(http.MethodGet, listShelfEndpoint, args) - if err != nil { - return nil, err + args["per_page"] = "200" + + for page := 1; ; page++ { + args["page"] = strconv.Itoa(page) + listShelfEndpoint := fmt.Sprintf("%s/%s.xml", ListShelfEndpoint, userID) + data, err := c.doRequest(http.MethodGet, listShelfEndpoint, args) + if err != nil { + return nil, err + } + books = append(books, data.Reviews.Books...) + if data.Reviews.AttrEnd == data.Reviews.AttrTotal { + break + } } - return data.Reviews.Books, nil + return books, nil } // AddToShelf adds a book to shelf. diff --git a/goodreads/types.go b/goodreads/types.go index 39f5c19..5c33905 100644 --- a/goodreads/types.go +++ b/goodreads/types.go @@ -41,13 +41,18 @@ type User struct { // Reviews defines the struct for the reviews object type Reviews struct { - Books []Book `xml:"review>book,omitempty"` + AttrEnd string `xml:"end,attr"` + AttrStart string `xml:"start,attr"` + AttrTotal string `xml:"total,attr"` + Books []Book `xml:"review,omitempty"` } // Book defines the struct for the book object type Book struct { - ID string `xml:"id,omitempty"` - Title string `xml:"title,omitempty"` - AvgRating string `xml:"average_rating,omitempty"` - Link string `xml:"link,omitempty"` + ID string `xml:"book>id,omitempty"` + Title string `xml:"book>title,omitempty"` + AvgRating string `xml:"book>average_rating,omitempty"` + Link string `xml:"book>link,omitempty"` + Pages string `xml:"book>num_pages,omitempty"` + ReadAt string `xml:"read_at,omitempty"` }