Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 238
Andrew Avatar asked Sep 09 '10 02:09

Andrew


2 Answers

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.

like image 168
zeantsoi Avatar answered Nov 04 '22 18:11

zeantsoi


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
like image 6
Kevin Griffin Avatar answered Nov 04 '22 17:11

Kevin Griffin