bps-google-api 0.2.10 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/Readme.md +15 -0
- data/bps-google-api.gemspec +2 -2
- data/lib/google_api.rb +18 -1
- data/lib/google_api/base.rb +1 -5
- data/lib/google_api/base/authorization.rb +5 -6
- data/lib/google_api/calendar.rb +2 -3
- data/lib/google_api/calendar/clear_test_calendar.rb +1 -1
- data/lib/google_api/config.rb +29 -0
- data/lib/google_api/configured.rb +1 -1
- data/lib/google_api/configured/calendar.rb +12 -10
- data/lib/google_api/configured/group.rb +8 -6
- data/lib/google_api/group.rb +1 -1
- data/spec/lib/google_api/base_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3fdf1dc00cb06bca57e8cec64ac829aa8c2b64d
|
4
|
+
data.tar.gz: f3f93c405057358d4867556026a215f5eba56159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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
|
data/bps-google-api.gemspec
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'bps-google-api'
|
5
|
-
s.version = '0.
|
6
|
-
s.date = '2019-06-
|
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
|
-
|
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
|
data/lib/google_api/base.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
-
|
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(
|
62
|
-
|
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
|
-
|
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|
|
data/lib/google_api/calendar.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
class GoogleAPI
|
4
4
|
class Calendar < GoogleAPI::Base
|
5
5
|
def self.last_token_path
|
6
|
-
|
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'
|
@@ -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,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
class GoogleAPI
|
4
4
|
module Configured
|
5
5
|
class Calendar
|
6
|
-
|
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
|
-
|
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
|
-
|
21
|
+
self.class.api.create(calendar_id, event_options)
|
20
22
|
end
|
21
23
|
|
22
24
|
def get(event_id)
|
23
|
-
|
25
|
+
self.class.api.get(calendar_id, event_id)
|
24
26
|
end
|
25
27
|
|
26
28
|
def update(event_id, event_options = {})
|
27
|
-
|
29
|
+
self.class.api.update(calendar_id, event_id, event_options)
|
28
30
|
end
|
29
31
|
|
30
32
|
def delete(event_id)
|
31
|
-
|
33
|
+
self.class.api.delete(calendar_id, event_id)
|
32
34
|
end
|
33
35
|
|
34
36
|
def permit(user = nil, email: nil)
|
35
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
3
|
+
class GoogleAPI
|
4
4
|
module Configured
|
5
5
|
class Group
|
6
|
-
|
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
|
-
|
17
|
+
self.class.api.get(group_id)
|
16
18
|
end
|
17
19
|
|
18
20
|
def members
|
19
|
-
|
21
|
+
self.class.api.members(group_id)
|
20
22
|
end
|
21
23
|
|
22
24
|
def add(email)
|
23
|
-
|
25
|
+
self.class.api.add(group_id, email)
|
24
26
|
end
|
25
27
|
|
26
28
|
def remove(email)
|
27
|
-
|
29
|
+
self.class.api.remove(group_id, email)
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
data/lib/google_api/group.rb
CHANGED
@@ -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
|
-
|
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(
|
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(
|
24
|
-
FileUtils.rm(Dir.glob(
|
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.
|
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-
|
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
|