ruboty-google_spreadsheet 0.1.1 → 0.1.2

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: 62e903f42f156c78d0558f9e82868505b9e79d6f
4
- data.tar.gz: a2fd5ab101c51ad916fee33c8ef84df9eb645c80
3
+ metadata.gz: f1cdb28aef6a68afc0b98bbcd31af476b57931b8
4
+ data.tar.gz: 7fafefd72204e70a52f27f95afabad440f683fc0
5
5
  SHA512:
6
- metadata.gz: d9ae4cd1a6650c1567e50db2a2c4a76e8e749ed5fae388163b87539716e4afb7f53b5b20f735d8b9a4cb8ca06d4d879dcba579d96d7cff46e9f3e9130e709373
7
- data.tar.gz: b951e91792bedb48faec821d0946e99c196e9ce83b25bf72f5b6d4851b6352870beb29902beb58db4a862f24e20350d737fc50fa293b8bcac1015db74c8e0494
6
+ metadata.gz: 0705122d99ed7f4018af2ca0163b63ed0870a050632a629a03eeb2771b84bfb419c5975c84ea29d79b275baa17b250024a70e402d0cdb6e02761a734dcef8120
7
+ data.tar.gz: 68ee4032215d806d5bc089d5d88ff138d76ec03ea0bdc8322c705a8b3f8e169ac5c301219477d3aba1731727c041b9b8d34a99f73fa72a75db49474e46ed4a12
@@ -10,8 +10,10 @@ module Ruboty
10
10
  def initialize
11
11
  super
12
12
 
13
- @thread = Thread.new { sync }
14
- @thread.abort_on_exception = true
13
+ @threads = []
14
+ @threads << Thread.new { sync }
15
+ @threads << Thread.new { reautorize }
16
+ @threads.each { |thread| thread.abort_on_exception = true }
15
17
 
16
18
  @client = Ruboty::GoogleSpreadsheet::Client.new(
17
19
  client_id: ENV["GOOGLE_CLIENT_ID"],
@@ -19,7 +21,7 @@ module Ruboty
19
21
  redirect_uri: ENV["GOOGLE_REDIRECT_URI"],
20
22
  refresh_token: ENV["GOOGLE_REFRESH_TOKEN"]
21
23
  )
22
- @client.authenticate!
24
+ @client.authorize!
23
25
  end
24
26
 
25
27
  def data
@@ -33,17 +35,18 @@ module Ruboty
33
35
 
34
36
  def sync
35
37
  loop do
36
- wait
38
+ sleep 5
37
39
  data.synchronize
38
40
  end
39
41
  end
40
42
 
41
- def wait
42
- sleep(interval)
43
- end
44
-
45
- def interval
46
- (ENV["GOOGLE_SPREADSHEET_SAVE_INTERVAL"] || 5).to_i
43
+ def reauthorize
44
+ loop do
45
+ # access token will expire in 3600 sec.
46
+ sleep 3599
47
+ @client.authorize!
48
+ @data = nil
49
+ end
47
50
  end
48
51
  end
49
52
  end
@@ -11,11 +11,13 @@ module Ruboty
11
11
  @authorization.client_secret = attrs[:client_secret]
12
12
  @authorization.scope = SCOPE
13
13
  @authorization.redirect_uri = attrs[:redirect_uri]
14
- @authorization.refresh_token = attrs[:refresh_token]
14
+ @refresh_token = attrs[:refresh_token]
15
15
  end
16
16
 
17
- def authenticate!
17
+ def authorize!
18
+ @authorization.refresh_token = @refresh_token
18
19
  @authorization.fetch_access_token!
20
+ @refresh_token = @authorization.refresh_token
19
21
  end
20
22
 
21
23
  def access_token
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module GoogleSpreadsheet
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-google_spreadsheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoto Kaneko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-09 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty