Skip to content

Instantly share code, notes, and snippets.

@sprite2005
Created July 9, 2009 11:17
Show Gist options
  • Save sprite2005/143580 to your computer and use it in GitHub Desktop.
Save sprite2005/143580 to your computer and use it in GitHub Desktop.
def get_matching_books query
matching_books = []
bs = GData::Client::BookSearch.new
feed = bs.get("http://books.google.com/books/feeds/volumes?q=#{URI::encode query}").to_xml
feed.elements.each('entry') do |entry|
feed_book = Book.new
feed_book.title = entry.elements['title'].text
feed_book.image_url = entry.elements["link[@rel='http://schemas.google.com/books/2008/thumbnail']"].attribute('href').value
# image_element = entry.elements["link[@rel='http://schemas.google.com/books/2008/thumbnail']"]
# feed_book.image_url = image_element ? image_element.attribute('href').value : 'images/logo.png'
matching_books.push feed_book
end
matching_books
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment