Andrew
Andrew

Reputation: 238937

Ruby on Rails 3 and Google Book Search

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?

Upvotes: 7

Views: 2410

Answers (3)

zeantsoi
zeantsoi

Reputation: 26193

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.

Upvotes: 12

Kevin Griffin
Kevin Griffin

Reputation: 14662

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

Upvotes: 6

Jed Schneider
Jed Schneider

Reputation: 14671

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

Upvotes: 0

Related Questions