7

I'm trying to get started using the Google Data API for Google Book Search in my Ruby on Rails 3 application, and I don't even understand how to get started. What gems do I need? What do I need to do in order to do something simple like searching for books with a title of Foobar?

Andrew
  • 196,883
  • 184
  • 487
  • 673

3 Answers3

12

Following up on the deprecation issue: I've just published GoogleBooks, a Ruby wrapper that enables users to query for books precisely in the manner described.

It's updated to hook into the present-day Google API, so it's not affected by the recent deprecation of the Google Book Search API.

zeantsoi
  • 23,793
  • 7
  • 62
  • 61
6

If you're looking to use Google Books to retrieve information about books, you can use their data API: http://code.google.com/apis/books/docs/gdata/developers_guide_protocol.html

Making requests to a URL like http://books.google.com/books/feeds/volumes?q=isbn:9780974514055 will return XML with the book's information. You could use the Nokogiri gem to parse the result ( http://nokogiri.org/ ).

One thing to be aware of is that, to get the full descriptions for books, you need to get the entry instead of just the feed results.

Here's a short example of how you could get a book's information from Google:

require 'open-uri'
require 'nokogiri'

class Book
  attr_accessor :title, :description
  def self.from_google(title)
    book  = self.new
    entry = Nokogiri::XML(open "http://books.google.com/books/feeds/volumes?q=#{title}").css("entry id").first
    xml   = Nokogiri::XML(open entry.text) if entry
    return book unless xml

    book.title       = xml.css("entry dc|title").first.text       unless xml.css("entry dc|title").empty?
    book.description = xml.css("entry dc|description").first.text unless xml.css("entry dc|description").empty?
    book
  end
end

b = Book.from_google("Ruby")
p b
Kevin Griffin
  • 11,989
  • 7
  • 26
  • 22
0

if you want to use the api, i think you will have to use jruby and their java api. no ruby api exists for the book search, according to this: http://code.google.com/apis/books/docs/gdata/code.html

for connecting with google, try using the gdata gem. http://code.google.com/apis/gdata/articles/gdata_on_rails.html#SetupRails

Jed Schneider
  • 12,615
  • 3
  • 33
  • 46
  • Sorry, I can't use Java. I need a Ruby solution. – Andrew Sep 10 '10 at 03:53
  • Also, I think I could use the gdata gem, but I can't figure out how to get it to work. Also, a more generic solution would be fine too. I just need a code sample to get me started. – Andrew Sep 11 '10 at 17:12
  • according to Kevin's solution the exclusive need for jruby is not there. I will avoid a downvote given your rep. – Michael Durrant Oct 09 '11 at 20:34
  • appears both suggestions at this time are deprecated: http://googlecode.blogspot.com/2011/05/spring-cleaning-for-some-of-our-apis.html the books api has moved here http://googlecode.blogspot.com/2011/05/new-books-api-for-developers.html and appears to be consumable in any language – Jed Schneider Oct 12 '11 at 00:12