bps-google-api 0.4.6 → 0.4.11

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
  SHA256:
3
- metadata.gz: f9ffa3df8c2ddfecc62cfe5a9830ea2c48293aef1952240e9dd5acd12b260ca1
4
- data.tar.gz: 1f3079fcec7a957a890fa217ee44e4ddcf664c31c0bc8129502ca70b92b0503f
3
+ metadata.gz: b9568cf68776abd0aa81f0ceaeecc4b8ca1152f9351f58afb2c6e00936b379bc
4
+ data.tar.gz: e21356e6b6928dd1e678e442e3bb87e524e3a90308ec741d4670def3838b326b
5
5
  SHA512:
6
- metadata.gz: 6412ddc986f1aff995bde999836779c649d9025fd885ab98e7ebb6dd1cc1e35c02f7685648cfa5308069e641e9c1da4bcb435c48a1274ccf7621bfc191849253
7
- data.tar.gz: 7745f51650c013b668e1bdb535db57f5957f9ad5cf5b49b785e8280b91f0aeab2bef2f9964c1e6735b50ec87d45b48a954ee89e516098c4f3b36d7b1c8ee348a
6
+ metadata.gz: 53244017cd5d5b904bd30489f31e6788d05a9bd40ca660870409afb6113f059dc469a6442b5c7627fa56ff00d87a2b7a447e41d3182a6313b529b37989b8c475
7
+ data.tar.gz: def98ec0603bcbd7d13b4c793ed1f3b52b31dbf5023e71a47a78554cb5c6f220d8e76761ee308baefde47978e0b48e842d54336d234e6e536ab7b0b232d162d6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bps-google-api (0.4.6)
4
+ bps-google-api (0.4.11)
5
5
  exp_retry (~> 0.0.13)
6
6
  fileutils (~> 1.2)
7
7
  google-api-client (~> 0.23.4)
@@ -10,15 +10,14 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- addressable (2.7.0)
13
+ addressable (2.8.0)
14
14
  public_suffix (>= 2.0.2, < 5.0)
15
15
  ast (2.4.0)
16
16
  declarative (0.0.20)
17
- declarative-option (0.1.0)
18
17
  diff-lcs (1.3)
19
18
  docile (1.3.2)
20
19
  exp_retry (0.0.13)
21
- faraday (0.17.3)
20
+ faraday (0.17.4)
22
21
  multipart-post (>= 1.2, < 3)
23
22
  fileutils (1.5.0)
24
23
  google-api-client (0.23.9)
@@ -39,11 +38,11 @@ GEM
39
38
  httpclient (2.8.3)
40
39
  jaro_winkler (1.5.3)
41
40
  json (2.3.1)
42
- jwt (2.2.2)
41
+ jwt (2.2.3)
43
42
  memoist (0.16.2)
44
43
  mime-types (3.3.1)
45
44
  mime-types-data (~> 3.2015)
46
- mime-types-data (3.2020.1104)
45
+ mime-types-data (3.2021.0901)
47
46
  multi_json (1.15.0)
48
47
  multipart-post (2.1.1)
49
48
  os (1.1.1)
@@ -52,9 +51,9 @@ GEM
52
51
  ast (~> 2.4.0)
53
52
  public_suffix (4.0.6)
54
53
  rainbow (3.0.0)
55
- representable (3.0.4)
54
+ representable (3.1.1)
56
55
  declarative (< 0.1.0)
57
- declarative-option (< 0.2.0)
56
+ trailblazer-option (>= 0.1.1, < 0.2.0)
58
57
  uber (< 0.2.0)
59
58
  retriable (3.1.2)
60
59
  rspec (3.8.0)
@@ -88,6 +87,7 @@ GEM
88
87
  json (>= 1.8, < 3)
89
88
  simplecov-html (~> 0.10.0)
90
89
  simplecov-html (0.10.2)
90
+ trailblazer-option (0.1.1)
91
91
  uber (0.1.0)
92
92
  unicode-display_width (1.6.0)
93
93
 
data/Readme.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # BPS Google API
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/bps-google-api.svg)](https://rubygems.org/gems/bps-google-api)
4
- [![Build Status](https://travis-ci.org/jfiander/bps-google-api.svg)](https://travis-ci.org/jfiander/bps-google-api)
4
+ [![Build Status](https://travis-ci.com/jfiander/bps-google-api.svg)](https://travis-ci.com/jfiander/bps-google-api)
5
5
 
6
6
  A configured Google API wrapper.
7
7
 
@@ -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.6'
6
- s.date = '2021-01-30'
5
+ s.version = '0.4.11'
6
+ s.date = '2021-09-15'
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'
@@ -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
@@ -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
 
@@ -42,10 +46,8 @@ class GoogleAPI
42
46
 
43
47
  def conference(conf_id, signature)
44
48
  {
45
- conference: {
46
- conference_id: conf_id, conference_solution: meet_solution,
47
- entry_points: meet_entry(conf_id), signature: signature
48
- }
49
+ conference_id: conf_id, conference_solution: meet_solution,
50
+ entry_points: meet_entry(conf_id), signature: signature
49
51
  }
50
52
  end
51
53
 
@@ -74,6 +76,10 @@ class GoogleAPI
74
76
  )
75
77
  ]
76
78
  end
79
+
80
+ def conference_mock
81
+ { id: 'abc-defg-hjk', signature: SecureRandom.hex(32) }
82
+ end
77
83
  end
78
84
  end
79
85
  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
@@ -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
data/lib/google_api.rb CHANGED
@@ -1,47 +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
25
-
26
- def self.configure
27
- yield(configuration) if block_given?
28
- FileUtils.mkdir_p(configuration.root)
29
- configuration
30
- 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'
31
30
 
32
- def self.logging!(level = :FATAL)
33
- raise ArgumentError, 'Unknown logging level' unless %i[INFO WARN ERROR FATAL].include?(level)
34
-
35
- Google::Apis.logger.level = Logger.const_get(level)
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
36
56
  end
37
-
38
- # Internal requires
39
- require 'google_api/base'
40
- require 'google_api/calendar'
41
- require 'google_api/group'
42
- require 'google_api/configured'
43
-
44
- # Extensions
45
- require 'ext/hash' unless defined?(Rails)
46
- require 'ext/silent_progress_bar'
47
57
  end
@@ -83,6 +83,23 @@ RSpec.describe GoogleAPI::Calendar do
83
83
  expect(subject.list_all.map(&:class).uniq).to eql([Google::Apis::CalendarV3::Event])
84
84
  end
85
85
 
86
+ context 'with multiple pages' do
87
+ let(:calendar) { subject.class.api }
88
+
89
+ before do
90
+ allow(calendar).to receive(:call).and_return(
91
+ Google::Apis::CalendarV3::Events.new(items: [Google::Apis::CalendarV3::Event], next_page_token: 'abc'),
92
+ Google::Apis::CalendarV3::Events.new(items: [Google::Apis::CalendarV3::Event], next_page_token: nil)
93
+ )
94
+ end
95
+
96
+ it 'returns the array of all events from list_all when paginated' do
97
+ expect(calendar).to receive(:call).twice
98
+
99
+ subject.list_all
100
+ end
101
+ end
102
+
86
103
  it 'creates an event' do
87
104
  expect(subject.create(test_event)).to be_a(Google::Apis::CalendarV3::Event)
88
105
  end
@@ -94,7 +111,7 @@ RSpec.describe GoogleAPI::Calendar do
94
111
  expect(subject.create(event)).to be_a(Google::Apis::CalendarV3::Event)
95
112
  end
96
113
 
97
- it 'creates an event with conference data' do
114
+ it 'creates an event with conference data', :aggregate_failures do
98
115
  event = subject.create(test_event)
99
116
  event = subject.add_conference(event.id)
100
117
  event_options = test_event.merge(
@@ -104,7 +121,9 @@ RSpec.describe GoogleAPI::Calendar do
104
121
  }
105
122
  )
106
123
 
107
- expect(subject.create(event_options)).to be_a(Google::Apis::CalendarV3::Event)
124
+ event = subject.create(event_options)
125
+ expect(event).to be_a(Google::Apis::CalendarV3::Event)
126
+ expect(event.conference_data).not_to be_nil
108
127
  end
109
128
 
110
129
  it 'returns valid conference information' do
@@ -178,4 +197,22 @@ RSpec.describe GoogleAPI::Calendar do
178
197
  expect(subject.add_conference(event.id)).to be_a(Google::Apis::CalendarV3::Event)
179
198
  end
180
199
  end
200
+
201
+ describe 'mock' do
202
+ subject { described_class.new }
203
+
204
+ before { GoogleAPI.mock! }
205
+
206
+ it 'calls the mock method' do
207
+ expect(subject).to receive(:mock).and_call_original
208
+
209
+ subject.create({})
210
+ end
211
+
212
+ it 'calls the conference_mock method' do
213
+ expect(subject).to receive(:conference_mock).and_call_original
214
+
215
+ subject.conference_info('')
216
+ end
217
+ end
181
218
  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
@@ -32,4 +32,8 @@ RSpec.configure do |config|
32
32
  ENV['GOOGLE_AUTHORIZATION_CODE'] = 'test-auth-code'
33
33
  ENV['HIDE_PROGRESS_BARS'] = 'true'
34
34
  end
35
+
36
+ config.after do
37
+ GoogleAPI.mock!(false) # Reset mock state
38
+ end
35
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.6
4
+ version: 0.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-30 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exp_retry
@@ -159,6 +159,7 @@ 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: