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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a10bb846e14565885a114bf9d5bfa6f366285e1
4
- data.tar.gz: 0d77b0d53f60662df97b676b85f7ac3bba112137
3
+ metadata.gz: 23fd6d24d216c3453b6dabffd4b3f5bd17a3b68c
4
+ data.tar.gz: cfec79938ce528f75d886ab73aaa8d3eb67ca88e
5
5
  SHA512:
6
- metadata.gz: 5218f828a2c52eaec483c198444e2cb3140ad4da03542656979ce90c3c590650e15c0074ded595b6f9ebc327fdf3bfa3134979050bff46637a8a74c3d77d3c3c
7
- data.tar.gz: 9e8ec72267bfa7a045a165557163d78d5ccd0bb6130ea6787d1508ca6c674f7cc0297c406ca414e3f8fa92c0d137306665a63365b012702dd5feb3464bf3fad0
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/a64ee96b-9362-4c5b-b59a-03cf638eca28/344206/badge.svg)](https://semaphoreci.com/awesomenesstv/big_shift)
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
- private
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
- def post
11
- connection.post url, request_body, headers
12
- end
9
+ def execute
10
+ @access_token = AccessTokenService.retrieve_token
11
+ @response = on_execute
12
+ scrub @response
13
+ @response
14
+ end
13
15
 
14
- def headers
15
- {
16
- 'Authorization' => "Bearer #{access_token}",
17
- 'Content-Type' => 'application/json',
18
- }
19
- end
16
+ private
20
17
 
21
- def params
22
- url_params.merge({
23
- :key => access_token,
24
- })
25
- end
18
+ def connection
19
+ Faraday.new(:url => base_url)
20
+ end
26
21
 
27
- def request_body
28
- body.to_json
29
- end
22
+ def post
23
+ connection.post url, request_body, headers
24
+ end
30
25
 
31
- def base_url
32
- 'https://www.googleapis.com/bigquery/v2/projects/%s/datasets/%s' % [
33
- project_id,
34
- dataset_id,
35
- ]
36
- end
26
+ def url
27
+ connection.build_url endpoint, params
28
+ end
37
29
 
38
- def url
39
- connection.build_url endpoint, params
40
- end
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
- def url_params
43
- {}
44
- end
37
+ def request_body
38
+ body.to_json
39
+ end
45
40
 
46
- def body
47
- {}
48
- end
41
+ def headers
42
+ {
43
+ 'Content-Type' => 'application/json',
44
+ 'Authorization' => "Bearer #{@access_token}",
45
+ }
46
+ end
49
47
 
50
- def project_id
51
- ENV['BIG_SHIFT_PROJECT_ID']
52
- end
48
+ def params
49
+ {
50
+ :key => @access_token,
51
+ }
52
+ end
53
53
 
54
- def dataset_id
55
- ENV['BIG_SHIFT_DATASET_ID']
56
- end
54
+ def project_id
55
+ ENV['BIG_SHIFT_PROJECT_ID']
56
+ end
57
57
 
58
- def access_token
59
- AccessTokenService.retrieve_token
60
- end
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
- class << self
4
- attr_accessor :table_id
3
+ attr_accessor :table_id
5
4
 
6
- private
5
+ private
7
6
 
8
- def base_url
9
- "#{super}/tables/#{table_id}"
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
- class << self
4
- def execute(schema)
5
- @schema = schema
6
- CreateTableResponse.new post
7
- end
3
+ def initialize(schema)
4
+ @schema = schema
5
+ end
6
+
7
+ def on_execute
8
+ CreateTableResponse.new post
9
+ end
8
10
 
9
- def endpoint
10
- 'tables'
11
- end
11
+ def endpoint
12
+ 'tables'
13
+ end
12
14
 
13
- def body
14
- {
15
- 'tableReference' => {
16
- 'projectId' => project_id,
17
- 'datasetId' => dataset_id,
18
- 'tableId' => @schema.table_name,
19
- },
15
+ def body
16
+ {
17
+ 'tableReference' => {
18
+ 'projectId' => project_id,
19
+ 'datasetId' => dataset_id,
20
+ 'tableId' => @schema.table_name,
21
+ },
20
22
 
21
- 'schema' => @schema,
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
- class << self
4
- def execute(table_name, rows)
5
- @rows = rows
6
- self.table_id = table_name
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
- def endpoint
11
- 'insertAll'
12
- end
8
+ def on_execute
9
+ InsertRowsResponse.new post
10
+ end
13
11
 
14
- def body
15
- { :rows => build_rows }
16
- end
12
+ def endpoint
13
+ 'insertAll'
14
+ end
15
+
16
+ def body
17
+ { :rows => build_rows }
18
+ end
17
19
 
18
- private
20
+ private
19
21
 
20
- def build_rows
21
- @rows.map do |row|
22
- {:json => row}
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
- if !defined?(@token) or @token.expired?
7
- response = GetAccessTokenCommand.execute
8
- @token = response.data
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
- @token.access_token
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.2
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-04-29 00:00:00.000000000 Z
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: '0'
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: '0'
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: '1'
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: '1'
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.6
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
@@ -1,7 +0,0 @@
1
- module BigShift
2
- class GetAccessTokenResponse < Reverb::Response
3
- def on_success
4
- self.data = AccessToken.new(body)
5
- end
6
- end
7
- end