Class: BigQuery::Client

Inherits:
Object
  • Object
show all
Includes:
Errors, Jobs, Query, Tables
Defined in:
lib/big_query/client.rb,
lib/big_query/client/jobs.rb,
lib/big_query/client/load.rb,
lib/big_query/client/query.rb,
lib/big_query/client/errors.rb,
lib/big_query/client/tables.rb

Defined Under Namespace

Modules: Errors, Insert, Jobs, Query, Tables

Constant Summary

Constants included from Tables

Tables::ALLOWED_FIELD_MODES, Tables::ALLOWED_FIELD_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Tables

#create_table, #delete_table, #describe_table, #insert, #table_data, #tables, #tables_formatted

Methods included from Jobs

#get_query_results, #job, #jobs

Methods included from Query

#each_row, #query

Methods included from Errors

#handle_error, #is_error?

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/big_query/client.rb', line 15

def initialize(opts = {})
  @client = Google::APIClient.new(
    application_name: 'BigQuery ruby app',
    application_version: BigQuery::VERSION
  )

  key = Google::APIClient::PKCS12.load_key(File.open(
    opts['key'], mode: 'rb'),
    "notasecret"
  )

  @asserter = Google::APIClient::JWTAsserter.new(
    opts['service_email'],
    "https://www.googleapis.com/auth/bigquery",
    key
  )

  refresh_auth

  @bq = @client.discovered_api("bigquery", "v2")

  @project_id = opts['project_id']
  @dataset = opts['dataset']
end

Instance Attribute Details

#datasetObject

Returns the value of attribute dataset.



13
14
15
# File 'lib/big_query/client.rb', line 13

def dataset
  @dataset
end

#project_idObject

Returns the value of attribute project_id.



13
14
15
# File 'lib/big_query/client.rb', line 13

def project_id
  @project_id
end

Instance Method Details

#refresh_authObject



40
41
42
# File 'lib/big_query/client.rb', line 40

def refresh_auth
  @client.authorization = @asserter.authorize
end