abronte / BigQuery

A BigQuery wrapper
86 stars 58 forks source link

Expose client via attr_reader #29

Open hunzinker opened 9 years ago

hunzinker commented 9 years ago

Thanks for the great gem!

I propose exposing the Google::APIClient object client via attr_reader for the following:

Why?

The above enable a BigQuery user to easily download a temporary table from Google Cloud storage.

Example:

bq = BigQuery::Client.new(opts)

# Perform query
# Extract data to Google Storage bucket

client = bq.client
client.authorization.scope=["https://www.googleapis.com/auth/cloud-platform"]
client.authorization.fetch_access_token! 

storage = client.discovered_api('storage', 'v1')
res = client.execute(                                                                                                                                                             
  api_method: storage.objects.get,                                                                                                                                                
  parameters: {                                                                                                                                                                   
    bucket: "bucket",                                                                                                                                                  
    object: "file.csv.gz"                                                                                                                                                      
  }                                                                                                                                                                               
) 

If you find the above scenario valid for this project, one option is expanding the initial authorization scope to cloud-platform instead of bigquery? Another is rolling in a BigQuery::Client::Download module which seems out of scope for this gem? Thoughts?

I'm happy to provide additional PRs if needed.

Thanks!