class Bq::InstalledApp

Public Instance Methods

authorize(client_secrets_json=nil) click to toggle source
# File lib/bq.rb, line 53
def authorize(client_secrets_json=nil)
  client_secrets_json ||= "client_secrets.json"
  puts "read from #{client_secrets_json}"
  credential = Google::APIClient::ClientSecrets.load(client_secrets_json)

  flow = Google::APIClient::InstalledAppFlow.new(
    :client_id     => credential.client_id,
    :client_secret => credential.client_secret,
    :scope         => ['https://www.googleapis.com/auth/bigquery']
  )
  @client.authorization = flow.authorize(@token_storage)
  # Here, will be opened authorization web page.
  # Click [Authorize] button, and I see "Error: redirect_uri_mismatch".
  # But it may be succeed, authorize arguments is available.

  unless @client.authorization
    puts "failed to authorize. Canceled?"
    return false
  end

  return true
end
datasets() click to toggle source
# File lib/bq.rb, line 76
def datasets
  result = @client.execute(
    :api_method => @bq_client.datasets.list,
    :parameters => {'projectId' => @project_id}
  )
  return result.data
end
query(q,timeout=90) click to toggle source
# File lib/bq.rb, line 84
def query(q,timeout=90)
  result = @client.execute(
    :api_method  => @bq_client.jobs.query,
    :body_object => {
      "query"     => q,
      "timeoutMs" => timeout * 1000
    },
    :parameters => {'projectId' => @project_id}
  )
  return result.data
end