bps-google-api 0.4.4 → 0.4.10

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
- SHA1:
3
- metadata.gz: 788064cba2b4804e1160d25ce3821b0272fe639f
4
- data.tar.gz: 033f65955b8ab308501341e7b6fc5b2516724492
2
+ SHA256:
3
+ metadata.gz: de16bf3d1c0b8b9f1971b1bb77077ded52379e3502d667fb3ca168e74bf202aa
4
+ data.tar.gz: 9ef1b294632a591e4808a6d0456e346b2a29922bf0fb756905813586517d83af
5
5
  SHA512:
6
- metadata.gz: 00cf09c82eaa74317ad14726400c0024fdf69782c578ad2f79402386e6e630ecbf3c11762d5bde80002047d9f7ec6f86bf6869aa30fc54ca39acd0badb746437
7
- data.tar.gz: 5afe4b08a137a5838f356b66ecce7361ff2620be574c10c205daf003c6c036e969ad6a65f875102c433e44cf07291445c3e6cab6be30579688efbaaf79503837
6
+ metadata.gz: 4a5a51dc5e75da452e7d548ad643997b9935ff8f535da11cb289e595deb2025c8bbbf15e77296f2053fd2b75a487af8a9d493ad45f28610e37d7f1b3263dffc3
7
+ data.tar.gz: 140eac17905e9b5396c79e39e7523192c3ce8616090328f893e0afe057e769dae71759a1fdcaac0a731939f485ab80868a662b2db9f48ef72d09658a2f6d2a1e
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bps-google-api (0.4.4)
5
- exp_retry (~> 0.0.11)
4
+ bps-google-api (0.4.10)
5
+ exp_retry (~> 0.0.13)
6
6
  fileutils (~> 1.2)
7
7
  google-api-client (~> 0.23.4)
8
8
  ruby-progressbar (~> 1.10)
@@ -10,17 +10,17 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- addressable (2.6.0)
14
- public_suffix (>= 2.0.2, < 4.0)
13
+ addressable (2.7.0)
14
+ public_suffix (>= 2.0.2, < 5.0)
15
15
  ast (2.4.0)
16
- declarative (0.0.10)
16
+ declarative (0.0.20)
17
17
  declarative-option (0.1.0)
18
18
  diff-lcs (1.3)
19
19
  docile (1.3.2)
20
- exp_retry (0.0.12)
21
- faraday (0.15.4)
20
+ exp_retry (0.0.13)
21
+ faraday (0.17.4)
22
22
  multipart-post (>= 1.2, < 3)
23
- fileutils (1.2.0)
23
+ fileutils (1.5.0)
24
24
  google-api-client (0.23.9)
25
25
  addressable (~> 2.5, >= 2.5.1)
26
26
  googleauth (>= 0.5, < 0.7.0)
@@ -38,19 +38,19 @@ GEM
38
38
  signet (~> 0.7)
39
39
  httpclient (2.8.3)
40
40
  jaro_winkler (1.5.3)
41
- json (2.2.0)
42
- jwt (2.2.1)
43
- memoist (0.16.0)
44
- mime-types (3.2.2)
41
+ json (2.3.1)
42
+ jwt (2.2.2)
43
+ memoist (0.16.2)
44
+ mime-types (3.3.1)
45
45
  mime-types-data (~> 3.2015)
46
- mime-types-data (3.2019.0331)
47
- multi_json (1.13.1)
46
+ mime-types-data (3.2021.0225)
47
+ multi_json (1.15.0)
48
48
  multipart-post (2.1.1)
49
- os (1.0.1)
49
+ os (1.1.1)
50
50
  parallel (1.17.0)
51
51
  parser (2.6.3.0)
52
52
  ast (~> 2.4.0)
53
- public_suffix (3.1.1)
53
+ public_suffix (4.0.6)
54
54
  rainbow (3.0.0)
55
55
  representable (3.0.4)
56
56
  declarative (< 0.1.0)
@@ -78,9 +78,9 @@ GEM
78
78
  ruby-progressbar (~> 1.7)
79
79
  unicode-display_width (>= 1.4.0, < 1.7)
80
80
  ruby-progressbar (1.10.1)
81
- signet (0.11.0)
81
+ signet (0.14.1)
82
82
  addressable (~> 2.3)
83
- faraday (~> 0.9)
83
+ faraday (>= 0.17.3, < 2.0)
84
84
  jwt (>= 1.5, < 3.0)
85
85
  multi_json (~> 1.10)
86
86
  simplecov (0.16.1)
data/Readme.md CHANGED
@@ -36,6 +36,12 @@ GoogleAPI.configure do |config|
36
36
  end
37
37
  ```
38
38
 
39
+ You can also alter the logging level using:
40
+
41
+ ```ruby
42
+ GoogleAPI.logging!(:FATAL) # %i[INFO WARN ERROR FATAL]
43
+ ```
44
+
39
45
  Then add the following in `config/application.rb`:
40
46
 
41
47
  ```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.4.4'
6
- s.date = '2019-06-27'
5
+ s.version = '0.4.10'
6
+ s.date = '2021-02-27'
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'
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.required_ruby_version = '~> 2.4'
17
17
 
18
- s.add_runtime_dependency 'exp_retry', '~> 0.0.11'
18
+ s.add_runtime_dependency 'exp_retry', '~> 0.0.13'
19
19
  s.add_runtime_dependency 'fileutils', '~> 1.2'
20
20
  s.add_runtime_dependency 'google-api-client', '~> 0.23.4'
21
21
  s.add_runtime_dependency 'ruby-progressbar', '~> 1.10'
data/lib/google_api.rb CHANGED
@@ -1,41 +1,57 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class GoogleAPI
4
- # Core Dependencies
5
- require 'date'
6
-
7
- # Google Dependencies
8
- require 'google/apis/calendar_v3'
9
- require 'google/apis/groupssettings_v1'
10
- require 'google/apis/admin_directory_v1'
11
- require 'googleauth'
12
- require 'googleauth/stores/file_token_store'
13
-
14
- # External dependencies
15
- require 'exp_retry'
16
- require 'fileutils'
17
- require 'ruby-progressbar'
18
-
19
- # Configuration
20
- require 'google_api/config'
21
-
22
- def self.configuration
23
- @configuration ||= GoogleAPI::Config.new
24
- end
3
+ # Core Dependencies
4
+ require 'date'
5
+
6
+ # Google Dependencies
7
+ require 'google/apis/calendar_v3'
8
+ require 'google/apis/groupssettings_v1'
9
+ require 'google/apis/admin_directory_v1'
10
+ require 'googleauth'
11
+ require 'googleauth/stores/file_token_store'
12
+
13
+ # External dependencies
14
+ require 'exp_retry'
15
+ require 'fileutils'
16
+ require 'ruby-progressbar'
17
+
18
+ # Configuration
19
+ require 'google_api/config'
20
+
21
+ # Internal requires
22
+ require 'google_api/base'
23
+ require 'google_api/calendar'
24
+ require 'google_api/group'
25
+ require 'google_api/configured'
26
+
27
+ # Extensions
28
+ require 'ext/hash' unless defined?(Rails)
29
+ require 'ext/silent_progress_bar'
25
30
 
26
- def self.configure
27
- yield(configuration) if block_given?
28
- FileUtils.mkdir_p(configuration.root)
29
- configuration
31
+ class GoogleAPI
32
+ class << self
33
+ def configuration
34
+ @configuration ||= GoogleAPI::Config.new
35
+ end
36
+
37
+ def configure
38
+ yield(configuration) if block_given?
39
+ FileUtils.mkdir_p(configuration.root)
40
+ configuration
41
+ end
42
+
43
+ def logging!(level = :FATAL)
44
+ raise ArgumentError, 'Unknown level' unless %i[DEBUG INFO WARN ERROR FATAL].include?(level)
45
+
46
+ Google::Apis.logger.level = Logger.const_get(level)
47
+ end
48
+
49
+ def mock!(value = true)
50
+ @mock = value
51
+ end
52
+
53
+ def mock
54
+ @mock || false
55
+ end
30
56
  end
31
-
32
- # Internal requires
33
- require 'google_api/base'
34
- require 'google_api/calendar'
35
- require 'google_api/group'
36
- require 'google_api/configured'
37
-
38
- # Extensions
39
- require 'ext/hash' unless defined?(Rails)
40
- require 'ext/silent_progress_bar'
41
57
  end
@@ -1,15 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'google_api/base/authorization'
4
+
3
5
  class GoogleAPI
4
6
  class Base
7
+ include GoogleAPI::Base::Authorization
8
+
5
9
  RETRIES ||= [
6
10
  Google::Apis::TransmissionError, Google::Apis::ServerError,
7
11
  Google::Apis::RateLimitError, Errno::ECONNRESET
8
12
  ].freeze
9
13
 
10
- require 'google_api/base/authorization'
11
- include GoogleAPI::Base::Authorization
12
-
13
14
  def initialize(auth: true)
14
15
  authorize! if auth
15
16
  end
@@ -27,7 +28,17 @@ class GoogleAPI
27
28
  end
28
29
 
29
30
  def call(method, *args)
30
- ExpRetry.for(exception: RETRIES) { service.send(method, *args) }
31
+ if GoogleAPI.mock
32
+ send(:mock, method, *args)
33
+ else
34
+ ExpRetry.for(exception: RETRIES) { service.send(method, *args) }
35
+ end
36
+ end
37
+
38
+ # :nocov:
39
+ def mock(*)
40
+ raise 'This method must be overwritten by the inheriting class.'
31
41
  end
42
+ # :nocov:
32
43
  end
33
44
  end
@@ -1,15 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'google_api/calendar/conference'
4
+ require 'google_api/calendar/clear_test_calendar'
5
+
3
6
  class GoogleAPI
4
7
  class Calendar < GoogleAPI::Base
5
- def self.last_token_path
6
- GoogleAPI.configuration.local_path('tmp', 'run', 'last_page_token')
7
- end
8
-
9
- require 'google_api/calendar/conference'
10
8
  include GoogleAPI::Calendar::Conference
11
-
12
- require 'google_api/calendar/clear_test_calendar'
13
9
  include GoogleAPI::Calendar::ClearTestCalendar
14
10
 
15
11
  SERVICE_CLASS = Google::Apis::CalendarV3::CalendarService
@@ -21,6 +17,10 @@ class GoogleAPI
21
17
  etag html_link i_cal_uid id kind organizer reminders sequence status updated
22
18
  ].freeze
23
19
 
20
+ def self.last_token_path
21
+ GoogleAPI.configuration.local_path('tmp', 'run', 'last_page_token')
22
+ end
23
+
24
24
  def create(calendar_id, event_options = {})
25
25
  call(:insert_event, calendar_id, event(event_options), conference_data_version: 1)
26
26
  end
@@ -111,5 +111,13 @@ class GoogleAPI
111
111
  key = date&.is_a?(String) ? :date : :date_time
112
112
  Google::Apis::CalendarV3::EventDateTime.new(key => date, time_zone: ENV['TZ'])
113
113
  end
114
+
115
+ def mock(*)
116
+ Google::Apis::CalendarV3::Event.new(
117
+ id: SecureRandom.hex(8),
118
+ html_link: 'http://calendar.google.com',
119
+ conference_id: 'abc-defg-hjk'
120
+ )
121
+ end
114
122
  end
115
123
  end
@@ -15,7 +15,11 @@ class GoogleAPI
15
15
  call(:patch_event, calendar_id, event_id, patch_options, conference_data_version: 1)
16
16
  end
17
17
 
18
- def conference_info(calendar_id, event_id, all: false)
18
+ def conference_info(calendar_id, event_id = nil, all: false)
19
+ return conference_mock if GoogleAPI.mock
20
+
21
+ raise ArgumentError, 'event_id is required' if event_id.nil?
22
+
19
23
  conf = call(:get_event, calendar_id, event_id).conference_data
20
24
  return conf if all || conf.nil?
21
25
 
@@ -74,6 +78,10 @@ class GoogleAPI
74
78
  )
75
79
  ]
76
80
  end
81
+
82
+ def conference_mock
83
+ { id: 'abc-defg-hjk', signature: SecureRandom.hex(32) }
84
+ end
77
85
  end
78
86
  end
79
87
  end
@@ -60,6 +60,8 @@ class GoogleAPI
60
60
  end
61
61
 
62
62
  def conference_info(event_id, all: false)
63
+ return self.class.api.send(:conference_mock) if GoogleAPI.mock
64
+
63
65
  self.class.api.conference_info(calendar_id, event_id, all: all)
64
66
  end
65
67
  end
@@ -33,5 +33,13 @@ class GoogleAPI
33
33
  def member(email)
34
34
  Google::Apis::AdminDirectoryV1::Member.new(email: email)
35
35
  end
36
+
37
+ def mock(*)
38
+ Google::Apis::AdminDirectoryV1::Members.new(
39
+ members: [
40
+ Google::Apis::AdminDirectoryV1::Member.new(email: 'nobody@example.com')
41
+ ]
42
+ )
43
+ end
36
44
  end
37
45
  end
@@ -178,4 +178,22 @@ RSpec.describe GoogleAPI::Calendar do
178
178
  expect(subject.add_conference(event.id)).to be_a(Google::Apis::CalendarV3::Event)
179
179
  end
180
180
  end
181
+
182
+ describe 'mock' do
183
+ subject { described_class.new }
184
+
185
+ before { GoogleAPI.mock! }
186
+
187
+ it 'calls the mock method' do
188
+ expect(subject).to receive(:mock).and_call_original
189
+
190
+ subject.create({})
191
+ end
192
+
193
+ it 'calls the conference_mock method' do
194
+ expect(subject).to receive(:conference_mock).and_call_original
195
+
196
+ subject.conference_info('')
197
+ end
198
+ end
181
199
  end
@@ -46,4 +46,16 @@ RSpec.describe GoogleAPI::Group do
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ describe 'mock' do
51
+ subject { described_class.new }
52
+
53
+ before { GoogleAPI.mock! }
54
+
55
+ it 'calls the mock method' do
56
+ expect(subject).to receive(:mock).and_call_original
57
+
58
+ subject.members({})
59
+ end
60
+ end
49
61
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe GoogleAPI do
6
+ it 'sets the log level correctly' do
7
+ expect { GoogleAPI.logging!(:FATAL) }.to(
8
+ change(Google::Apis.logger, :level).from(Logger::WARN).to(Logger::FATAL)
9
+ )
10
+ end
11
+
12
+ it 'raises for invalid levels' do
13
+ expect { GoogleAPI.logging!(:WRONG) }.to raise_error(ArgumentError, 'Unknown level')
14
+ end
15
+
16
+ it 'sets the mock flag' do
17
+ expect { GoogleAPI.mock! }.to change { GoogleAPI.mock }.from(false).to(true)
18
+ end
19
+ end
data/spec/spec_helper.rb CHANGED
@@ -25,9 +25,15 @@ RSpec.configure do |config|
25
25
  c.keys = 'tmp/spec/keys'
26
26
  end
27
27
 
28
+ GoogleAPI.logging!(:INFO)
29
+
28
30
  FileUtils.rm(Dir.glob(GoogleAPI.configuration.local_path('*', &:keys)))
29
31
 
30
32
  ENV['GOOGLE_AUTHORIZATION_CODE'] = 'test-auth-code'
31
33
  ENV['HIDE_PROGRESS_BARS'] = 'true'
32
34
  end
35
+
36
+ config.after do
37
+ GoogleAPI.mock!(false) # Reset mock state
38
+ end
33
39
  end
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.4
4
+ version: 0.4.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-27 00:00:00.000000000 Z
11
+ date: 2021-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exp_retry
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.11
19
+ version: 0.0.13
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.11
26
+ version: 0.0.13
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fileutils
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -159,12 +159,13 @@ files:
159
159
  - spec/lib/google_api/calendar_spec.rb
160
160
  - spec/lib/google_api/event_spec.rb
161
161
  - spec/lib/google_api/group_spec.rb
162
+ - spec/lib/google_api_spec.rb
162
163
  - spec/spec_helper.rb
163
164
  homepage: http://rubygems.org/gems/bps-google-api
164
165
  licenses:
165
166
  - GPL-3.0
166
167
  metadata: {}
167
- post_install_message:
168
+ post_install_message:
168
169
  rdoc_options: []
169
170
  require_paths:
170
171
  - lib
@@ -179,9 +180,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  - !ruby/object:Gem::Version
180
181
  version: '0'
181
182
  requirements: []
182
- rubyforge_project:
183
- rubygems_version: 2.6.14.1
184
- signing_key:
183
+ rubygems_version: 3.2.7
184
+ signing_key:
185
185
  specification_version: 4
186
186
  summary: Configured Google API
187
187
  test_files: []