bps-google-api 0.2.4 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bps-google-api.gemspec +1 -1
- data/lib/google_api/base/authorization.rb +13 -6
- data/lib/google_api/base.rb +5 -2
- data/lib/google_api/calendar/clear_test_calendar.rb +4 -3
- data/lib/google_api/calendar.rb +4 -1
- data/lib/google_api.rb +0 -2
- data/spec/lib/google_api/base_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b81ec7c00f00165af4b968536942fc7637ef08a7
|
4
|
+
data.tar.gz: f560253ee4e8ae7ada9dfaaf3a69b0158070d349
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e633ccdf18625cdb33f9b7c9eb67393617ebd9644910d4bf66319ea2d824e32c2bf2d3946b7c6900643be59f9f244a50739635a1a6196fafbb70cbe628bc2839
|
7
|
+
data.tar.gz: fc05951a3d4af73490f1d5b594987dd518260b27727e9ae167b4e391d1c9afb4ead756707fc101dbef5c90656480c5dc1557d092342784298d74078102f3d4fd
|
data/Gemfile.lock
CHANGED
data/bps-google-api.gemspec
CHANGED
@@ -49,12 +49,18 @@ module GoogleAPI
|
|
49
49
|
def auth_client_id
|
50
50
|
client_id_file
|
51
51
|
Google::Auth::ClientId.from_hash(
|
52
|
-
JSON.parse(
|
52
|
+
JSON.parse(
|
53
|
+
File.read(
|
54
|
+
File.join(GoogleAPI::Base.root_path, 'config', 'keys', 'google_api_client.json')
|
55
|
+
)
|
56
|
+
)
|
53
57
|
)
|
54
58
|
end
|
55
59
|
|
56
60
|
def auth_token_store
|
57
|
-
Google::Auth::Stores::FileTokenStore.new(file:
|
61
|
+
Google::Auth::Stores::FileTokenStore.new(file:
|
62
|
+
File.join(GoogleAPI::Base.root_path, 'config', 'keys', 'google_token.yaml')
|
63
|
+
)
|
58
64
|
end
|
59
65
|
|
60
66
|
def auth_keys(auth)
|
@@ -69,10 +75,11 @@ module GoogleAPI
|
|
69
75
|
Time.strptime(time, '%Y-%m-%d %H:%M:%S %:z').to_i * 1000
|
70
76
|
end
|
71
77
|
|
72
|
-
def store_key(
|
78
|
+
def store_key(filename, key)
|
79
|
+
FileUtils.mkdir_p(File.join(GoogleAPI::Base.root_path, 'config', 'keys'))
|
80
|
+
path = File.join(GoogleAPI::Base.root_path, 'config', 'keys', filename)
|
73
81
|
return if File.exist?(path)
|
74
82
|
|
75
|
-
FileUtils.mkdir_p(File.join(ROOT_PATH, 'config', 'keys'))
|
76
83
|
File.open(path, 'w+') do |f|
|
77
84
|
File.chmod(0o600, f)
|
78
85
|
block_given? ? yield(f) : f.write(key)
|
@@ -81,7 +88,7 @@ module GoogleAPI
|
|
81
88
|
|
82
89
|
def client_id_file
|
83
90
|
store_key(
|
84
|
-
|
91
|
+
'google_api_client.json',
|
85
92
|
<<~KEY
|
86
93
|
{"installed":{"client_id":"#{ENV['GOOGLE_CLIENT_ID']}","project_id":"charming-scarab-208718",
|
87
94
|
"auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token",
|
@@ -93,7 +100,7 @@ module GoogleAPI
|
|
93
100
|
|
94
101
|
def token_file
|
95
102
|
store_key(
|
96
|
-
|
103
|
+
'google_token.yaml',
|
97
104
|
<<~KEY
|
98
105
|
---
|
99
106
|
default: '{"client_id":"#{ENV['GOOGLE_CLIENT_ID']}","access_token":"#{ENV['GOOGLE_ACCESS_TOKEN']}",
|
data/lib/google_api/base.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module GoogleAPI
|
4
|
-
require 'google_api/base/authorization'
|
5
|
-
|
6
4
|
class Base
|
7
5
|
RETRIES ||= [
|
8
6
|
Google::Apis::TransmissionError, Google::Apis::ServerError,
|
9
7
|
Google::Apis::RateLimitError, Errno::ECONNRESET
|
10
8
|
].freeze
|
11
9
|
|
10
|
+
def self.root_path
|
11
|
+
defined?(Rails) ? Rails.root : File.dirname(__dir__)
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'google_api/base/authorization'
|
12
15
|
include GoogleAPI::Base::Authorization
|
13
16
|
|
14
17
|
def initialize(auth: true)
|
@@ -20,7 +20,8 @@ module GoogleAPI
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def choose_page_token(page_token)
|
23
|
-
|
23
|
+
last_token = Calendar.last_token_path
|
24
|
+
@page_token ||= File.read(last_token) if File.exist?(last_token)
|
24
25
|
@page_token = page_token if token?(page_token)
|
25
26
|
end
|
26
27
|
|
@@ -54,8 +55,8 @@ module GoogleAPI
|
|
54
55
|
|
55
56
|
def log_last_page_token
|
56
57
|
puts "\n\n*** Last page token cleared: #{@page_token}" if @verbose
|
57
|
-
File.open(Calendar
|
58
|
-
puts "\n*** Token stored in #{Calendar
|
58
|
+
File.open(Calendar.last_token_path, 'w+') { |f| f.write(@page_token) }
|
59
|
+
puts "\n*** Token stored in #{Calendar.last_token_path}" if @verbose
|
59
60
|
end
|
60
61
|
|
61
62
|
def progress_bar(total)
|
data/lib/google_api/calendar.rb
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
module GoogleAPI
|
4
4
|
class Calendar < GoogleAPI::Base
|
5
|
-
|
5
|
+
def self.last_token_path
|
6
|
+
FileUtils.mkdir_p(File.join(GoogleAPI::Base.root_path, 'tmp', 'run'))
|
7
|
+
File.join(GoogleAPI::Base.root_path, 'tmp', 'run', 'last_page_token')
|
8
|
+
end
|
6
9
|
|
7
10
|
require 'google_api/calendar/clear_test_calendar'
|
8
11
|
include GoogleAPI::Calendar::ClearTestCalendar
|
data/lib/google_api.rb
CHANGED
@@ -15,8 +15,8 @@ RSpec.describe GoogleAPI::Base do
|
|
15
15
|
subject { GoogleAPI::Calendar }
|
16
16
|
|
17
17
|
it 'returns the correct last token path' do
|
18
|
-
expect(GoogleAPI::Calendar
|
19
|
-
File.join(GoogleAPI::
|
18
|
+
expect(GoogleAPI::Calendar.last_token_path).to eql(
|
19
|
+
File.join(GoogleAPI::Base.root_path, 'tmp', 'run', 'last_page_token')
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
data/spec/spec_helper.rb
CHANGED
@@ -13,15 +13,15 @@ require 'google_api'
|
|
13
13
|
|
14
14
|
def silently
|
15
15
|
original_stdout = $stdout
|
16
|
-
$stdout = File.new(File.join('tmp', 'null'), 'w')
|
16
|
+
$stdout = File.new(File.join(GoogleAPI::Base.root_path, 'tmp', 'null'), 'w')
|
17
17
|
yield
|
18
18
|
$stdout = original_stdout
|
19
19
|
end
|
20
20
|
|
21
21
|
RSpec.configure do |config|
|
22
22
|
config.before(:suite) do
|
23
|
-
FileUtils.mkdir_p(File.join('tmp', 'run'))
|
24
|
-
FileUtils.rm(Dir.glob(File.join('config', 'keys', '*')))
|
23
|
+
FileUtils.mkdir_p(File.join(GoogleAPI::Base.root_path, 'tmp', 'run'))
|
24
|
+
FileUtils.rm(Dir.glob(File.join(GoogleAPI::Base.root_path, 'config', 'keys', '*')))
|
25
25
|
|
26
26
|
ENV['GOOGLE_AUTHORIZATION_CODE'] = 'test-auth-code'
|
27
27
|
ENV['HIDE_PROGRESS_BARS'] = 'true'
|