kura 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +6 -0
- data/README.md +13 -1
- data/lib/kura/client.rb +12 -8
- data/lib/kura/version.rb +1 -1
- data/lib/kura.rb +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5efd73150912195d0d14025754f547070a7330d
|
4
|
+
data.tar.gz: 493c0f054490460710146625b8e8f47b23630579
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 622bd7e0574fd825dda7e0611c4c5f055415f96f813d704f046f3d70c840ac91b927348de9cba7640d386dac7c47ec9063e262bfe532036190bdcc7912e9382e
|
7
|
+
data.tar.gz: fdc9fa61e501ef6247486b9040c8e6a3904ea2c805ed9820e6e5898b0c666de1ce13dd17c33953e00d67e5105e1e2c1e8f03198578e780d3079ea1f02de32f4b
|
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -21,11 +21,23 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
+
### Initialize
|
25
|
+
|
24
26
|
```
|
27
|
+
# a. With Service Account Private Key
|
25
28
|
client = Kura.client(project_id, email, private_key)
|
29
|
+
|
30
|
+
# b. With GCE bigquery scope (Only available on Google Compute Engine instance)
|
31
|
+
client = Kura.client
|
32
|
+
```
|
33
|
+
|
34
|
+
### Job API
|
35
|
+
|
36
|
+
```
|
26
37
|
client.load("dataset", "table", "gs://mybucket/data.csv", wait: 120)
|
27
|
-
client.query("SELECT * FROM [dataset.table];", wait: 120)
|
38
|
+
client.query("SELECT * FROM [dataset.table];", dataset_id: "dest_dataset", table_id: dest_table", wait: 120)
|
28
39
|
client.extract("dataset", "result", "gs://mybucket/extracted.csv", wait: 120)
|
40
|
+
client.copy("src_dataset", "src_table", "dest_dataset", "dest_table", wait: 120)
|
29
41
|
```
|
30
42
|
|
31
43
|
## Contributing
|
data/lib/kura/client.rb
CHANGED
@@ -5,17 +5,21 @@ require "kura/version"
|
|
5
5
|
|
6
6
|
module Kura
|
7
7
|
class Client
|
8
|
-
def initialize(
|
9
|
-
@default_project_id =
|
8
|
+
def initialize(default_project_id: nil, email_address: nil, private_key: nil)
|
9
|
+
@default_project_id = default_project_id
|
10
10
|
@scope = "https://www.googleapis.com/auth/bigquery"
|
11
11
|
@email_address = email_address
|
12
12
|
@private_key = private_key
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
if @email_address and @private_key
|
14
|
+
auth = Signet::OAuth2::Client.new(
|
15
|
+
token_credential_uri: "https://accounts.google.com/o/oauth2/token",
|
16
|
+
audience: "https://accounts.google.com/o/oauth2/token",
|
17
|
+
scope: @scope,
|
18
|
+
issuer: @email_address,
|
19
|
+
signing_key: @private_key)
|
20
|
+
else
|
21
|
+
auth = Google::APIClient::ComputeServiceAccount.new
|
22
|
+
end
|
19
23
|
@api = Google::APIClient.new(application_name: "Kura", application_version: Kura::VERSION, authorization: auth)
|
20
24
|
@api.authorization.fetch_access_token!
|
21
25
|
@bigquery_api = @api.discovered_api("bigquery", "v2")
|
data/lib/kura/version.rb
CHANGED
data/lib/kura.rb
CHANGED
@@ -34,8 +34,10 @@ module Kura
|
|
34
34
|
private_key
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.client(project_id, email_address, private_key)
|
38
|
-
|
39
|
-
|
37
|
+
def self.client(project_id=nil, email_address=nil, private_key=nil)
|
38
|
+
if private_key
|
39
|
+
private_key = get_private_key(private_key)
|
40
|
+
end
|
41
|
+
self::Client.new(default_project_id: project_id, email_address: email_address, private_key: private_key)
|
40
42
|
end
|
41
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kura
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chikanaga Tomoyuki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|