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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62dc0559dea2c506661457f032e9e60df284d2f9
4
- data.tar.gz: 25d483983fe5607af8d87fbfaad9120674575d2f
3
+ metadata.gz: b81ec7c00f00165af4b968536942fc7637ef08a7
4
+ data.tar.gz: f560253ee4e8ae7ada9dfaaf3a69b0158070d349
5
5
  SHA512:
6
- metadata.gz: af86ddc607a96df38f7bf1b2dc321898def9f3be7fffd01273423d6bf9d8ecf373e422c6fa039e5db686edc1ef7bf22438a28be2bfe477aa68df833c59b75c3e
7
- data.tar.gz: ffcad31969723afadaf920de95f4ae06caa3c109786293d74f39476b09090c08f7871a92dd8fdecda0ffa48af1542d3515568121de9941732f28d98cb3350afa
6
+ metadata.gz: e633ccdf18625cdb33f9b7c9eb67393617ebd9644910d4bf66319ea2d824e32c2bf2d3946b7c6900643be59f9f244a50739635a1a6196fafbb70cbe628bc2839
7
+ data.tar.gz: fc05951a3d4af73490f1d5b594987dd518260b27727e9ae167b4e391d1c9afb4ead756707fc101dbef5c90656480c5dc1557d092342784298d74078102f3d4fd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bps-google-api (0.2.4)
4
+ bps-google-api (0.2.10)
5
5
  exp_retry (~> 0.0.11)
6
6
  fileutils (~> 1.2)
7
7
  google-api-client (~> 0.23.4)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bps-google-api'
5
- s.version = '0.2.4'
5
+ s.version = '0.2.10'
6
6
  s.date = '2019-06-20'
7
7
  s.summary = 'Configured Google API'
8
8
  s.description = 'A configured Google API wrapper.'
@@ -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(File.read('config/keys/google_api_client.json'))
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: 'config/keys/google_token.yaml')
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(path, 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
- File.join(ROOT_PATH, 'config/keys/google_api_client.json'),
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
- File.join(ROOT_PATH, 'config/keys/google_token.yaml'),
103
+ 'google_token.yaml',
97
104
  <<~KEY
98
105
  ---
99
106
  default: '{"client_id":"#{ENV['GOOGLE_CLIENT_ID']}","access_token":"#{ENV['GOOGLE_ACCESS_TOKEN']}",
@@ -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
- @page_token ||= File.read(Calendar::LAST_TOKEN_PATH) if File.exist?(Calendar::LAST_TOKEN_PATH)
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::LAST_TOKEN_PATH, 'w+') { |f| f.write(@page_token) }
58
- puts "\n*** Token stored in #{Calendar::LAST_TOKEN_PATH}" if @verbose
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)
@@ -2,7 +2,10 @@
2
2
 
3
3
  module GoogleAPI
4
4
  class Calendar < GoogleAPI::Base
5
- LAST_TOKEN_PATH ||= File.join(ROOT_PATH, 'tmp', 'run', 'last_page_token')
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
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoogleAPI
4
- ROOT_PATH ||= File.dirname(__dir__)
5
-
6
4
  require 'google/apis/calendar_v3'
7
5
  require 'google/apis/groupssettings_v1'
8
6
  require 'google/apis/admin_directory_v1'
@@ -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::LAST_TOKEN_PATH).to eql(
19
- File.join(GoogleAPI::ROOT_PATH, 'tmp', 'run', 'last_page_token')
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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bps-google-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander