tokumine/fusion_tables — pull request #21 by derekeder (2013-01-13 07:26:20+00:00)
Title: Fusion Tables v1 API implementation

Configured this gem to work with the [Fusion Tables v1 API](https://developers.google.com/fusiontables/docs/v1/reference/query/sql), which involved pointing to a new endpoint (https://www.googleapis.com/fusiontables/v1/query), adding support for an api_key, and handling responses in JSON format.

Google will be shutting off the old SQL API on [Monday Jan 14th, 2013](https://developers.google.com/fusiontables/docs/developers_guide), so these updates are required if this gem is to continue working. I would really like it to!

#### New requirements
__api_key__
An API key is required for all v1 API Fusion Tables queries. You can get one at the [Google API Console](https://code.google.com/apis/console/). The key can be set for this gem by calling the set_api_key method like so:

@ft = GData::Client::FusionTables.new
@ft.clientlogin(username, password)
@ft.set_api_key(api_key)

#### Testing
Currently all tests are passing, except for this one:

should "be able to select the rows" do
data = 2.times.inject([]) { |a,i|
a << {:firstname => "Person-#{i}",
:phone => 12,
:dob => Time.utc(2010,"aug",10,20,15,1),
:house => "1,1,0"}
}

@table.insert data
assert_equal [{:firstname=>"Person-0", :phone=>"12", :dob=>"08-10-2010 20:15:01", :house=>"1,1,0"}, {:firstname=>"Person-1", :phone=>"12", :dob=>"08-10-2010 20:15:01", :house=>"1,1,0"}], @table.select
end

The Ruby JSON parser is mistakenly parsing the house KML as additional JSON. I'm not sure the best way to have it handle this.

#### Other nuances: type sensitivity

In testing this with my other projects, I've noticed that because the responses are coming back in JSON format, it is much more type sensitive, especially for numbers. If a column is set to :type => 'number' and is blank or contains any non-numeric characters, the JSON parser will throw a NaN error. I'm open to suggestions on how to handle this elegantly.

Relates to issue #18.

Cheers,
Derek