Goodreads Developers discussion

60 views
Reviews.list?

Comments Showing 1-2 of 2 (2 new)    post a comment »
dateUp arrow    newest »

message 1: by Aaron (last edited Nov 05, 2018 06:25PM) (new)

Aaron (aaronct123) | 4 comments Hey all,

Currently building a Swift iOS app using the api and I’m coming up against something funky. I’m trying to cycle through an array of shelves and pull down data for each shelf using a for loop.

Here’s what it looks like:


func getBooksFromShelf(_ oauthswift: OAuth1Swift, userID: String, shelf: Shelf, name: String) {
let _ = oauthswift.client.get(
"https://www.goodreads.com/review/list...",
parameters: ["key": developerKey, "id": userID, "shelf": name, "sort": "date_added", "v": "2"],
success: { response in
let xml = SWXMLHash.parse(response.data)
for review in xml["GoodreadsResponse"]["reviews"]["review"].all {
let book = review["book"]
let bookID = book["id"].element!.text
let bookTitle = book["title"].element!.text
let bookCoverURL = URL(string: book["image_url"].element!.text)

var bookAuthors = "by "
for author in book["authors"].all {
bookAuthors += author["author"]["name"].element!.text
}

let newBook = Book.init(id: bookID, title: bookTitle, authors: bookAuthors, cover: bookCoverURL)
shelf.books.append(newBook)
}
},


The problem is each run through the loop returns the data for https://www.goodreads.com/review/list... as if no parameters were added to the request at all. But when I replace the name variable with the string of a shelf I know exists —like "currently-reading"—I get the proper result https://www.goodreads.com/review/list....

I’ve tried dropping the parameters array and creating the URL string myself but that’s not working either. Any ideas?


message 2: by Aaron (new)

Aaron (aaronct123) | 4 comments Figured out the problem: I was setting capitalization on the Shelf names, which was messing up the end URL query, which is case-sensitive. Solved it creating two separate variables when the shelf object is created, one for the string the API returns—"want-to-read"— and one for the user friendly string that gets shown in the app which is "Want to Read".


back to top