New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fusion Tables v1 API implementation #21

Closed
wants to merge 8 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@derekeder
Contributor

derekeder commented Jan 13, 2013

Configured this gem to work with the Fusion Tables v1 API, 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, 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. 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

@derekeder

This comment has been minimized.

Show comment
Hide comment
@derekeder

derekeder Jan 13, 2013

Contributor

Also, forgot to mention: the json gem is required.

Add to your Gemfile:

gem 'json'

Or in the command line:

bundle install json
Contributor

derekeder commented Jan 13, 2013

Also, forgot to mention: the json gem is required.

Add to your Gemfile:

gem 'json'

Or in the command line:

bundle install json
@derekeder

This comment has been minimized.

Show comment
Hide comment
@derekeder

derekeder Jan 14, 2013

Contributor

Discovered another nuance. Blank fields are now returned as an empty string ('') instead of nil. Important difference when checking for missing values.

Contributor

derekeder commented Jan 14, 2013

Discovered another nuance. Blank fields are now returned as an empty string ('') instead of nil. Important difference when checking for missing values.

@tokumine

This comment has been minimized.

Show comment
Hide comment
@tokumine

tokumine Jan 14, 2013

Owner

hmm - is it the case that google is outputing "" instead of Null in the JSON?

Owner

tokumine commented Jan 14, 2013

hmm - is it the case that google is outputing "" instead of Null in the JSON?

@derekeder

This comment has been minimized.

Show comment
Hide comment
@derekeder

derekeder Jan 14, 2013

Contributor

Yes that looks to be the case. Take a look at this example output:

https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20*%20FROM%201xy_wp4-NhtKPecuDlhsS8MLO0z-g5ayY1OfBhAg&key=AIzaSyDEr3t9l3rUbE69ZB72Lj7hMVx_R_IXKaE

Nulls exist in that table, but they are being returned as an empty string.

Contributor

derekeder commented Jan 14, 2013

Yes that looks to be the case. Take a look at this example output:

https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20*%20FROM%201xy_wp4-NhtKPecuDlhsS8MLO0z-g5ayY1OfBhAg&key=AIzaSyDEr3t9l3rUbE69ZB72Lj7hMVx_R_IXKaE

Nulls exist in that table, but they are being returned as an empty string.

@tokumine

This comment has been minimized.

Show comment
Hide comment
@tokumine

tokumine Jan 14, 2013

Owner

dang. ok, not much we can do there.

By the way, I'm running the tests and am getting a lot of

GData::Client::AuthorizationError: request error 403: {
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured"
   }
  ],
  "code": 403,
  "message": "Access Not Configured"
 }
}

errors. I have my api key all setup as far as I can tell - did you run into this?

tks

Owner

tokumine commented Jan 14, 2013

dang. ok, not much we can do there.

By the way, I'm running the tests and am getting a lot of

GData::Client::AuthorizationError: request error 403: {
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured"
   }
  ],
  "code": 403,
  "message": "Access Not Configured"
 }
}

errors. I have my api key all setup as far as I can tell - did you run into this?

tks

@tokumine

This comment has been minimized.

Show comment
Hide comment
@tokumine

tokumine Jan 14, 2013

Owner

ok, looks good now. Google's API console just needed to sync.

Owner

tokumine commented Jan 14, 2013

ok, looks good now. Google's API console just needed to sync.

@derekeder

This comment has been minimized.

Show comment
Hide comment
@derekeder

derekeder Jan 14, 2013

Contributor

That error happens when the api key is not set. Perhaps try issuing another one? Also, is your api_key set in test_config.yml?

Contributor

derekeder commented Jan 14, 2013

That error happens when the api key is not set. Perhaps try issuing another one? Also, is your api_key set in test_config.yml?

@tokumine

This comment has been minimized.

Show comment
Hide comment
@tokumine

tokumine Jan 14, 2013

heh - just done this myself :D

tokumine commented on 0a6986f Jan 14, 2013

heh - just done this myself :D

@tokumine

This comment has been minimized.

Show comment
Hide comment
@tokumine

tokumine Jan 14, 2013

Owner

Looks like the API is outputing the location data as geojson. Which is a bit bizzare as it's being populated by KML, but what the hey !

Owner

tokumine commented Jan 14, 2013

Looks like the API is outputing the location data as geojson. Which is a bit bizzare as it's being populated by KML, but what the hey !

@tokumine

This comment has been minimized.

Show comment
Hide comment
@tokumine

tokumine Jan 14, 2013

Owner

Merged. Thanks Derek! I'll release a new gem shortly

Owner

tokumine commented Jan 14, 2013

Merged. Thanks Derek! I'll release a new gem shortly

@tokumine tokumine closed this Jan 14, 2013

@tokumine

This comment has been minimized.

Show comment
Hide comment
@tokumine

tokumine Jan 14, 2013

Owner

released as v0.4 (http://rubygems.org/gems/fusion_tables). Thanks again Derek for your work on this. Awesome!

Owner

tokumine commented Jan 14, 2013

released as v0.4 (http://rubygems.org/gems/fusion_tables). Thanks again Derek for your work on this. Awesome!

@derekeder

This comment has been minimized.

Show comment
Hide comment
@derekeder

derekeder Jan 14, 2013

Contributor

Awesome! Thanks Simon! Glad to help out.

Contributor

derekeder commented Jan 14, 2013

Awesome! Thanks Simon! Glad to help out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment