bps-google-api 0.2.10 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b81ec7c00f00165af4b968536942fc7637ef08a7
4
- data.tar.gz: f560253ee4e8ae7ada9dfaaf3a69b0158070d349
3
+ metadata.gz: d3fdf1dc00cb06bca57e8cec64ac829aa8c2b64d
4
+ data.tar.gz: f3f93c405057358d4867556026a215f5eba56159
5
5
  SHA512:
6
- metadata.gz: e633ccdf18625cdb33f9b7c9eb67393617ebd9644910d4bf66319ea2d824e32c2bf2d3946b7c6900643be59f9f244a50739635a1a6196fafbb70cbe628bc2839
7
- data.tar.gz: fc05951a3d4af73490f1d5b594987dd518260b27727e9ae167b4e391d1c9afb4ead756707fc101dbef5c90656480c5dc1557d092342784298d74078102f3d4fd
6
+ metadata.gz: 2dd2714fa3eb9d611b348e16a9a55fb02855991750ad8dccc58d33fa54506db8ead002e58725e36c5b456d75252689987007db78ed7c479b48a66deee7bb15a0
7
+ data.tar.gz: c2d6b1d4b0356552565d214e741f1027d7256781ad923af1d0b636c61f386153cc2a4eab1277775fad920f1a14a4771c310078e0f56f43a869bd31a2b7dfe71e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bps-google-api (0.2.10)
4
+ bps-google-api (0.3.0)
5
5
  exp_retry (~> 0.0.11)
6
6
  fileutils (~> 1.2)
7
7
  google-api-client (~> 0.23.4)
@@ -50,7 +50,7 @@ GEM
50
50
  parallel (1.17.0)
51
51
  parser (2.6.3.0)
52
52
  ast (~> 2.4.0)
53
- public_suffix (3.1.0)
53
+ public_suffix (3.1.1)
54
54
  rainbow (3.0.0)
55
55
  representable (3.0.4)
56
56
  declarative (< 0.1.0)
data/Readme.md CHANGED
@@ -16,6 +16,21 @@ or install directly:
16
16
  gem install bps-google-api
17
17
  ```
18
18
 
19
+ Create an initializer to configure the root directory for the gem:
20
+
21
+ ```ruby
22
+ GoogleAPI.configure do |config|
23
+ config.root = File.join('tmp', 'google_api')
24
+ end
25
+ ```
26
+
27
+ ```ruby
28
+ GoogleAPI.configure do |config|
29
+ config.root = Rails.root.join('config', 'google_api')
30
+ config.keys = Rails.root.join('config', 'keys')
31
+ end
32
+ ```
33
+
19
34
  Then run the following in `config/application.rb`:
20
35
 
21
36
  ```ruby
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bps-google-api'
5
- s.version = '0.2.10'
6
- s.date = '2019-06-20'
5
+ s.version = '0.3.0'
6
+ s.date = '2019-06-25'
7
7
  s.summary = 'Configured Google API'
8
8
  s.description = 'A configured Google API wrapper.'
9
9
  s.homepage = 'http://rubygems.org/gems/bps-google-api'
data/lib/google_api.rb CHANGED
@@ -1,21 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GoogleAPI
3
+ class GoogleAPI
4
+ # Google Dependencies
4
5
  require 'google/apis/calendar_v3'
5
6
  require 'google/apis/groupssettings_v1'
6
7
  require 'google/apis/admin_directory_v1'
7
8
  require 'googleauth'
8
9
  require 'googleauth/stores/file_token_store'
9
10
 
11
+ # External dependencies
10
12
  require 'exp_retry'
11
13
  require 'fileutils'
12
14
  require 'ruby-progressbar'
13
15
 
16
+ # Configuration
17
+ require 'google_api/config'
18
+
19
+ def self.configuration
20
+ @configuration ||= GoogleAPI::Config.new
21
+ end
22
+
23
+ def self.configure
24
+ yield(configuration) if block_given?
25
+ FileUtils.mkdir_p(configuration.root)
26
+ configuration
27
+ end
28
+
29
+ # Internal requires
14
30
  require 'google_api/base'
15
31
  require 'google_api/calendar'
16
32
  require 'google_api/group'
17
33
  require 'google_api/configured'
18
34
 
35
+ # Extensions
19
36
  require 'ext/hash' unless defined?(Rails)
20
37
  require 'ext/silent_progress_bar'
21
38
  end
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GoogleAPI
3
+ class GoogleAPI
4
4
  class Base
5
5
  RETRIES ||= [
6
6
  Google::Apis::TransmissionError, Google::Apis::ServerError,
7
7
  Google::Apis::RateLimitError, Errno::ECONNRESET
8
8
  ].freeze
9
9
 
10
- def self.root_path
11
- defined?(Rails) ? Rails.root : File.dirname(__dir__)
12
- end
13
-
14
10
  require 'google_api/base/authorization'
15
11
  include GoogleAPI::Base::Authorization
16
12
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GoogleAPI
3
+ class GoogleAPI
4
4
  class Base
5
5
  module Authorization
6
6
  OOB_URI ||= 'urn:ietf:wg:oauth:2.0:oob'
@@ -51,15 +51,15 @@ module GoogleAPI
51
51
  Google::Auth::ClientId.from_hash(
52
52
  JSON.parse(
53
53
  File.read(
54
- File.join(GoogleAPI::Base.root_path, 'config', 'keys', 'google_api_client.json')
54
+ GoogleAPI.configuration.local_path('google_api_client.json', &:keys)
55
55
  )
56
56
  )
57
57
  )
58
58
  end
59
59
 
60
60
  def auth_token_store
61
- Google::Auth::Stores::FileTokenStore.new(file:
62
- File.join(GoogleAPI::Base.root_path, 'config', 'keys', 'google_token.yaml')
61
+ Google::Auth::Stores::FileTokenStore.new(
62
+ file: GoogleAPI.configuration.local_path('google_token.yaml', &:keys)
63
63
  )
64
64
  end
65
65
 
@@ -76,8 +76,7 @@ module GoogleAPI
76
76
  end
77
77
 
78
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)
79
+ path = GoogleAPI.configuration.local_path(filename, &:keys)
81
80
  return if File.exist?(path)
82
81
 
83
82
  File.open(path, 'w+') do |f|
@@ -1,10 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GoogleAPI
3
+ class 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')
6
+ GoogleAPI.configuration.local_path('tmp', 'run', 'last_page_token')
8
7
  end
9
8
 
10
9
  require 'google_api/calendar/clear_test_calendar'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GoogleAPI
3
+ class GoogleAPI
4
4
  class Calendar < GoogleAPI::Base
5
5
  module ClearTestCalendar
6
6
  def clear_test_calendar(page_token: nil, page_limit: 50, verbose: false, error: false)
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GoogleAPI
4
+ class Config
5
+ attr_accessor :root
6
+ attr_writer :keys
7
+
8
+ def initialize
9
+ self.root = __dir__
10
+
11
+ yield self if block_given?
12
+ end
13
+
14
+ def keys
15
+ @keys || root
16
+ end
17
+
18
+ def local_path(*path)
19
+ basepath = block_given? ? yield(self) : root
20
+ fullpath = File.join(basepath, *path)
21
+ paths = fullpath.split('/')
22
+ filename = paths.pop
23
+ path = File.join(*paths)
24
+
25
+ FileUtils.mkdir_p(path)
26
+ File.join(path, filename)
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GoogleAPI
3
+ class GoogleAPI
4
4
  module Configured
5
5
  require 'google_api/configured/calendar'
6
6
  require 'google_api/configured/group'
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GoogleAPI
3
+ class GoogleAPI
4
4
  module Configured
5
5
  class Calendar
6
- CALENDAR_API ||= GoogleAPI::Calendar.new
6
+ def self.api
7
+ @api ||= GoogleAPI::Calendar.new
8
+ end
7
9
 
8
10
  attr_reader :calendar_id
9
11
 
@@ -12,35 +14,35 @@ module GoogleAPI
12
14
  end
13
15
 
14
16
  def list(max_results: 2500, page_token: nil)
15
- CALENDAR_API.list(calendar_id, max_results: max_results, page_token: page_token)
17
+ self.class.api.list(calendar_id, max_results: max_results, page_token: page_token)
16
18
  end
17
19
 
18
20
  def create(event_options = {})
19
- CALENDAR_API.create(calendar_id, event_options)
21
+ self.class.api.create(calendar_id, event_options)
20
22
  end
21
23
 
22
24
  def get(event_id)
23
- CALENDAR_API.get(calendar_id, event_id)
25
+ self.class.api.get(calendar_id, event_id)
24
26
  end
25
27
 
26
28
  def update(event_id, event_options = {})
27
- CALENDAR_API.update(calendar_id, event_id, event_options)
29
+ self.class.api.update(calendar_id, event_id, event_options)
28
30
  end
29
31
 
30
32
  def delete(event_id)
31
- CALENDAR_API.delete(calendar_id, event_id)
33
+ self.class.api.delete(calendar_id, event_id)
32
34
  end
33
35
 
34
36
  def permit(user = nil, email: nil)
35
- CALENDAR_API.permit(calendar_id, user, email: email)
37
+ self.class.api.permit(calendar_id, user, email: email)
36
38
  end
37
39
 
38
40
  def unpermit(user = nil, calendar_rule_id: nil)
39
- CALENDAR_API.unpermit(calendar_id, user, calendar_rule_id: calendar_rule_id)
41
+ self.class.api.unpermit(calendar_id, user, calendar_rule_id: calendar_rule_id)
40
42
  end
41
43
 
42
44
  def clear_test_calendar(page_token: nil, page_limit: 50, verbose: false, error: false)
43
- CALENDAR_API.clear_test_calendar(
45
+ self.class.api.clear_test_calendar(
44
46
  page_token: page_token, page_limit: page_limit, verbose: verbose, error: error
45
47
  )
46
48
  end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GoogleAPI
3
+ class GoogleAPI
4
4
  module Configured
5
5
  class Group
6
- GROUP_API ||= GoogleAPI::Group.new
6
+ def self.api
7
+ @api ||= GoogleAPI::Group.new
8
+ end
7
9
 
8
10
  attr_reader :group_id
9
11
 
@@ -12,19 +14,19 @@ module GoogleAPI
12
14
  end
13
15
 
14
16
  def get
15
- GROUP_API.get(group_id)
17
+ self.class.api.get(group_id)
16
18
  end
17
19
 
18
20
  def members
19
- GROUP_API.members(group_id)
21
+ self.class.api.members(group_id)
20
22
  end
21
23
 
22
24
  def add(email)
23
- GROUP_API.add(group_id, email)
25
+ self.class.api.add(group_id, email)
24
26
  end
25
27
 
26
28
  def remove(email)
27
- GROUP_API.remove(group_id, email)
29
+ self.class.api.remove(group_id, email)
28
30
  end
29
31
  end
30
32
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GoogleAPI
3
+ class GoogleAPI
4
4
  class Group < GoogleAPI::Base
5
5
  SERVICE_CLASS = Google::Apis::AdminDirectoryV1::DirectoryService
6
6
 
@@ -16,7 +16,7 @@ RSpec.describe GoogleAPI::Base do
16
16
 
17
17
  it 'returns the correct last token path' do
18
18
  expect(GoogleAPI::Calendar.last_token_path).to eql(
19
- File.join(GoogleAPI::Base.root_path, 'tmp', 'run', 'last_page_token')
19
+ GoogleAPI.configuration.local_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(GoogleAPI::Base.root_path, 'tmp', 'null'), 'w')
16
+ $stdout = File.new(GoogleAPI.configuration.local_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(GoogleAPI::Base.root_path, 'tmp', 'run'))
24
- FileUtils.rm(Dir.glob(File.join(GoogleAPI::Base.root_path, 'config', 'keys', '*')))
23
+ FileUtils.mkdir_p(GoogleAPI.configuration.local_path('tmp', 'run'))
24
+ FileUtils.rm(Dir.glob(GoogleAPI.configuration.local_path('config', 'keys', '*')))
25
25
 
26
26
  ENV['GOOGLE_AUTHORIZATION_CODE'] = 'test-auth-code'
27
27
  ENV['HIDE_PROGRESS_BARS'] = 'true'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bps-google-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-20 00:00:00.000000000 Z
11
+ date: 2019-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exp_retry
@@ -147,6 +147,7 @@ files:
147
147
  - lib/google_api/base/authorization.rb
148
148
  - lib/google_api/calendar.rb
149
149
  - lib/google_api/calendar/clear_test_calendar.rb
150
+ - lib/google_api/config.rb
150
151
  - lib/google_api/configured.rb
151
152
  - lib/google_api/configured/calendar.rb
152
153
  - lib/google_api/configured/group.rb