big_shift 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/big_shift/commands/base_command.rb +50 -45
- data/lib/big_shift/commands/base_table_command.rb +4 -6
- data/lib/big_shift/commands/create_table_command.rb +19 -18
- data/lib/big_shift/commands/insert_rows_command.rb +18 -17
- data/lib/big_shift/services/access_token_service.rb +18 -4
- data/lib/big_shift.rb +1 -2
- metadata +23 -11
- data/lib/big_shift/commands/get_access_token_command.rb +0 -46
- data/lib/big_shift/responses/get_access_token_response.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23fd6d24d216c3453b6dabffd4b3f5bd17a3b68c
|
4
|
+
data.tar.gz: cfec79938ce528f75d886ab73aaa8d3eb67ca88e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c91709f44f4c26633c9d90b1caf732ab6631dffaccf21a33db50087a7344640273e900ea8af4c95b3131e540f3eb2a10fe86a660f9de9e4ba3dc221809413b0c
|
7
|
+
data.tar.gz: 0c25524a9db25f478091cde261052a7d3388e841b5aafc9dc82dcddd24b71d8e09b2d98d3c9212f6f8f6881842696ef837680ccc5ad5478e5488305b50abbb6b
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
BigShift
|
2
2
|
========
|
3
3
|
|
4
|
-
[![Build Status](https://semaphoreci.com/api/v1/projects/
|
4
|
+
[![Build Status](https://semaphoreci.com/api/v1/projects/be4677b9-459a-4edb-b8a6-091746be4af3/460270/badge.svg)](https://semaphoreci.com/awesomenesstv/big_shift)
|
5
5
|
|
6
6
|
BigShift uploads your data to BigQuery.
|
7
7
|
|
@@ -1,63 +1,68 @@
|
|
1
1
|
module BigShift
|
2
2
|
class BaseCommand
|
3
3
|
class << self
|
4
|
-
|
5
|
-
|
6
|
-
def connection
|
7
|
-
Faraday.new(:url => base_url)
|
4
|
+
def execute(*args)
|
5
|
+
self.new(*args).execute
|
8
6
|
end
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def execute
|
10
|
+
@access_token = AccessTokenService.retrieve_token
|
11
|
+
@response = on_execute
|
12
|
+
scrub @response
|
13
|
+
@response
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
{
|
16
|
-
'Authorization' => "Bearer #{access_token}",
|
17
|
-
'Content-Type' => 'application/json',
|
18
|
-
}
|
19
|
-
end
|
16
|
+
private
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
})
|
25
|
-
end
|
18
|
+
def connection
|
19
|
+
Faraday.new(:url => base_url)
|
20
|
+
end
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
def post
|
23
|
+
connection.post url, request_body, headers
|
24
|
+
end
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
dataset_id,
|
35
|
-
]
|
36
|
-
end
|
26
|
+
def url
|
27
|
+
connection.build_url endpoint, params
|
28
|
+
end
|
37
29
|
|
38
|
-
|
39
|
-
|
40
|
-
|
30
|
+
def base_url
|
31
|
+
'https://www.googleapis.com/bigquery/v2/projects/%s/datasets/%s' % [
|
32
|
+
project_id,
|
33
|
+
dataset_id,
|
34
|
+
]
|
35
|
+
end
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
def request_body
|
38
|
+
body.to_json
|
39
|
+
end
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
def headers
|
42
|
+
{
|
43
|
+
'Content-Type' => 'application/json',
|
44
|
+
'Authorization' => "Bearer #{@access_token}",
|
45
|
+
}
|
46
|
+
end
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
def params
|
49
|
+
{
|
50
|
+
:key => @access_token,
|
51
|
+
}
|
52
|
+
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
def project_id
|
55
|
+
ENV['BIG_SHIFT_PROJECT_ID']
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
def dataset_id
|
59
|
+
ENV['BIG_SHIFT_DATASET_ID']
|
60
|
+
end
|
61
|
+
|
62
|
+
def scrub(response)
|
63
|
+
response.scrub @access_token, 'ACCESS_TOKEN'
|
64
|
+
response.scrub project_id, 'PROJECT_ID'
|
65
|
+
response.scrub dataset_id, 'DATASET_ID'
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module BigShift
|
2
2
|
class BaseTableCommand < BaseCommand
|
3
|
-
|
4
|
-
attr_accessor :table_id
|
3
|
+
attr_accessor :table_id
|
5
4
|
|
6
|
-
|
5
|
+
private
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
7
|
+
def base_url
|
8
|
+
"#{super}/tables/#{table_id}"
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
@@ -1,26 +1,27 @@
|
|
1
1
|
module BigShift
|
2
2
|
class CreateTableCommand < BaseCommand
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
def initialize(schema)
|
4
|
+
@schema = schema
|
5
|
+
end
|
6
|
+
|
7
|
+
def on_execute
|
8
|
+
CreateTableResponse.new post
|
9
|
+
end
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
def endpoint
|
12
|
+
'tables'
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def body
|
16
|
+
{
|
17
|
+
'tableReference' => {
|
18
|
+
'projectId' => project_id,
|
19
|
+
'datasetId' => dataset_id,
|
20
|
+
'tableId' => @schema.table_name,
|
21
|
+
},
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
23
|
+
'schema' => @schema,
|
24
|
+
}
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -1,26 +1,27 @@
|
|
1
1
|
module BigShift
|
2
2
|
class InsertRowsCommand < BaseTableCommand
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
InsertRowsResponse.new post
|
8
|
-
end
|
3
|
+
def initialize(table_name, rows)
|
4
|
+
self.table_id = table_name
|
5
|
+
@rows = rows
|
6
|
+
end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def on_execute
|
9
|
+
InsertRowsResponse.new post
|
10
|
+
end
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
def endpoint
|
13
|
+
'insertAll'
|
14
|
+
end
|
15
|
+
|
16
|
+
def body
|
17
|
+
{ :rows => build_rows }
|
18
|
+
end
|
17
19
|
|
18
|
-
|
20
|
+
private
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
22
|
+
def build_rows
|
23
|
+
@rows.map do |row|
|
24
|
+
{:json => row}
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -2,13 +2,27 @@ module BigShift
|
|
2
2
|
module AccessTokenService
|
3
3
|
extend self
|
4
4
|
|
5
|
+
@@mutex = Mutex.new
|
6
|
+
|
5
7
|
def retrieve_token
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
@@mutex.synchronize do
|
9
|
+
if !defined?(@token) or @token.expired?
|
10
|
+
response = Toke.retrieve_token(params)
|
11
|
+
@token = response.data if response.success?
|
12
|
+
end
|
13
|
+
|
14
|
+
@token.token if defined?(@token)
|
9
15
|
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
10
19
|
|
11
|
-
|
20
|
+
def params
|
21
|
+
{
|
22
|
+
:refresh_token => ENV['BIG_SHIFT_REFRESH_TOKEN'],
|
23
|
+
:client_id => ENV['BIG_SHIFT_GOOGLE_CLIENT_ID'],
|
24
|
+
:client_secret => ENV['BIG_SHIFT_GOOGLE_CLIENT_SECRET'],
|
25
|
+
}
|
12
26
|
end
|
13
27
|
end
|
14
28
|
end
|
data/lib/big_shift.rb
CHANGED
@@ -2,6 +2,7 @@ require 'json'
|
|
2
2
|
|
3
3
|
require 'faraday'
|
4
4
|
require 'reverb'
|
5
|
+
require 'toke'
|
5
6
|
|
6
7
|
module BigShift
|
7
8
|
end
|
@@ -11,14 +12,12 @@ require_relative 'big_shift/models/access_token'
|
|
11
12
|
require_relative 'big_shift/models/table_field'
|
12
13
|
require_relative 'big_shift/models/schema'
|
13
14
|
|
14
|
-
require_relative 'big_shift/responses/get_access_token_response'
|
15
15
|
require_relative 'big_shift/responses/create_table_response'
|
16
16
|
require_relative 'big_shift/responses/insert_rows_response'
|
17
17
|
|
18
18
|
require_relative 'big_shift/commands/base_command'
|
19
19
|
require_relative 'big_shift/commands/base_table_command'
|
20
20
|
require_relative 'big_shift/commands/create_table_command'
|
21
|
-
require_relative 'big_shift/commands/get_access_token_command'
|
22
21
|
require_relative 'big_shift/commands/insert_rows_command'
|
23
22
|
|
24
23
|
require_relative 'big_shift/services/access_token_service'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: big_shift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Herrick
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -31,28 +31,42 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 0.0.4
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 0.0.4
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: toke
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.0.3
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.0.3
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: rake_tasks
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
45
59
|
requirements:
|
46
60
|
- - "~>"
|
47
61
|
- !ruby/object:Gem::Version
|
48
|
-
version: '4'
|
62
|
+
version: '4.1'
|
49
63
|
type: :development
|
50
64
|
prerelease: false
|
51
65
|
version_requirements: !ruby/object:Gem::Requirement
|
52
66
|
requirements:
|
53
67
|
- - "~>"
|
54
68
|
- !ruby/object:Gem::Version
|
55
|
-
version: '4'
|
69
|
+
version: '4.1'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: gems
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,14 +143,14 @@ dependencies:
|
|
129
143
|
requirements:
|
130
144
|
- - "~>"
|
131
145
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
146
|
+
version: '2'
|
133
147
|
type: :development
|
134
148
|
prerelease: false
|
135
149
|
version_requirements: !ruby/object:Gem::Requirement
|
136
150
|
requirements:
|
137
151
|
- - "~>"
|
138
152
|
- !ruby/object:Gem::Version
|
139
|
-
version: '
|
153
|
+
version: '2'
|
140
154
|
- !ruby/object:Gem::Dependency
|
141
155
|
name: factory_girl
|
142
156
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,7 +180,6 @@ files:
|
|
166
180
|
- lib/big_shift/commands/base_command.rb
|
167
181
|
- lib/big_shift/commands/base_table_command.rb
|
168
182
|
- lib/big_shift/commands/create_table_command.rb
|
169
|
-
- lib/big_shift/commands/get_access_token_command.rb
|
170
183
|
- lib/big_shift/commands/insert_rows_command.rb
|
171
184
|
- lib/big_shift/core.rb
|
172
185
|
- lib/big_shift/models/access_token.rb
|
@@ -174,7 +187,6 @@ files:
|
|
174
187
|
- lib/big_shift/models/schema.rb
|
175
188
|
- lib/big_shift/models/table_field.rb
|
176
189
|
- lib/big_shift/responses/create_table_response.rb
|
177
|
-
- lib/big_shift/responses/get_access_token_response.rb
|
178
190
|
- lib/big_shift/responses/insert_rows_response.rb
|
179
191
|
- lib/big_shift/services/access_token_service.rb
|
180
192
|
- license/gplv3.md
|
@@ -200,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
212
|
version: '0'
|
201
213
|
requirements: []
|
202
214
|
rubyforge_project:
|
203
|
-
rubygems_version: 2.4.
|
215
|
+
rubygems_version: 2.4.8
|
204
216
|
signing_key:
|
205
217
|
specification_version: 4
|
206
218
|
summary: BigShift API interface
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module BigShift
|
2
|
-
class GetAccessTokenCommand < BaseCommand
|
3
|
-
class << self
|
4
|
-
def execute
|
5
|
-
GetAccessTokenResponse.new post
|
6
|
-
end
|
7
|
-
|
8
|
-
def headers
|
9
|
-
{
|
10
|
-
'Content-Type' => 'application/json',
|
11
|
-
}
|
12
|
-
end
|
13
|
-
|
14
|
-
def params
|
15
|
-
{
|
16
|
-
:client_id => client_id,
|
17
|
-
:client_secret => client_secret,
|
18
|
-
:refresh_token => refresh_token,
|
19
|
-
:grant_type => 'refresh_token',
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
def endpoint
|
24
|
-
'token'
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def client_id
|
30
|
-
ENV['BIG_SHIFT_GOOGLE_CLIENT_ID']
|
31
|
-
end
|
32
|
-
|
33
|
-
def client_secret
|
34
|
-
ENV['BIG_SHIFT_GOOGLE_CLIENT_SECRET']
|
35
|
-
end
|
36
|
-
|
37
|
-
def refresh_token
|
38
|
-
ENV['BIG_SHIFT_REFRESH_TOKEN']
|
39
|
-
end
|
40
|
-
|
41
|
-
def base_url
|
42
|
-
'https://www.googleapis.com/oauth2/v3'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|