Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ A Ruby interface to the BigQuery API.
```

## Getting Started
### Use private_key

```ruby
require "bigquery-client"
Expand All @@ -27,6 +28,22 @@ client = BigQuery::Client.new(
client.sql "SELECT * FROM publicdata:samples.wikipedia LIMIT 10"
```

### Use client_secrets

```ruby
require "bigquery-client"

client = BigQuery::Client.new(
project: "your-project-42",
dataset: "your_dataset",
client_secrets_path: "/path/to/client_secrets.json",
credential_store_file: "/path/to/credential_store_file.json",
auth_method: "client_secrets"
)

client.sql "SELECT * FROM publicdata:samples.wikipedia LIMIT 10"
```

## Available API methods

https://cloud.google.com/bigquery/docs/reference/v2/
Expand Down
15 changes: 15 additions & 0 deletions lib/bigquery-client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ def authorize_client
auth = Google::APIClient::ComputeServiceAccount.new
auth.fetch_access_token!
@client.authorization = auth
when 'client_secrets'
file_storage = Google::APIClient::Storage.new(Google::APIClient::FileStore.new(@credential_store_file))
auth = file_storage.authorize

if file_storage.authorization.nil?
client_secrets = Google::APIClient::ClientSecrets.load(@client_secrets_path)
flow = Google::APIClient::InstalledAppFlow.new(
client_id: client_secrets.client_id,
client_secret: client_secrets.client_secret,
scope: 'https://www.googleapis.com/auth/bigquery'
)

auth = flow.authorize(file_storage)
end
@client.authorization = auth
end
end
end
Expand Down