Class: BigQuery::Client

Inherits:
Object
  • Object
show all
Includes:
Errors, Insert, 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 Insert

#load

Methods included from Tables

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

Methods included from Jobs

#get_query_results, #insert_job, #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.



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

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

  begin
    key = Google::APIClient::KeyUtils.load_from_pkcs12(opts['key'], 'notasecret')
  rescue ArgumentError
    key = Google::APIClient::KeyUtils.load_from_pem(opts['key'], 'notasecret')
  end

  @client.authorization = Signet::OAuth2::Client.new(
    token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
    audience: 'https://accounts.google.com/o/oauth2/token',
    scope: 'https://www.googleapis.com/auth/bigquery',
    issuer: opts['service_email'],
    signing_key: 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.



15
16
17
# File 'lib/big_query/client.rb', line 15

def dataset
  @dataset
end

#project_idObject

Returns the value of attribute project_id.



15
16
17
# File 'lib/big_query/client.rb', line 15

def project_id
  @project_id
end

Instance Method Details

#refresh_authObject



45
46
47
# File 'lib/big_query/client.rb', line 45

def refresh_auth
  @client.authorization.fetch_access_token!
end