bps-google-api 0.4.8 → 0.4.9

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
  SHA256:
3
- metadata.gz: ac23f313f3e6a5bd469d43b3097bd94f2b7d8e6e4a2cefbbd416b7d783224f82
4
- data.tar.gz: ebe61c322c7e1fbb37cee4b925cb4f40707b0b16e3a2d4f4b18973aec24a08d2
3
+ metadata.gz: 8856171f804e9a62eb6efe7d15ca99c8ffe2ba56754aabd6f2db030c1fb0ef9b
4
+ data.tar.gz: 1b20297f206ef497b90ab9b7648dac0bf84c407d82c9f8a891d38903eb39c247
5
5
  SHA512:
6
- metadata.gz: 8d514d9e36cd7b017a33ccccbc71acb2b8353b2c9c69320189186853e772d0adcbbfed8cee132e31593f51a624fa40f59c08d94e72d4101151447536ab494cfa
7
- data.tar.gz: 3f14a711aa4a0668f62aeb91abf381d346010973de1074b0f8b8ff6d94338c326eb8b68f3a9ebbffd53c09a6472362f94fe12ae5e54d102e8ecdb678718a8126
6
+ metadata.gz: 4ae4b2476e6d4efb16593a71d0446217e0d3ab3b3be590918c7e9cbee81817d64bc52d9c164afc904133989666b5bb23d046f2deac6da38da359d0f3a1c82a7c
7
+ data.tar.gz: 822146e8b118409ed47cb4ac204ab5f4190fda432b5baf49a937cd68cf140ee38bf860752f985ed6c60d14d79635381e8ffeca15305c84e5d90688c206e709fd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bps-google-api (0.4.8)
4
+ bps-google-api (0.4.9)
5
5
  exp_retry (~> 0.0.13)
6
6
  fileutils (~> 1.2)
7
7
  google-api-client (~> 0.23.4)
@@ -18,7 +18,7 @@ GEM
18
18
  diff-lcs (1.3)
19
19
  docile (1.3.2)
20
20
  exp_retry (0.0.13)
21
- faraday (0.17.3)
21
+ faraday (0.17.4)
22
22
  multipart-post (>= 1.2, < 3)
23
23
  fileutils (1.5.0)
24
24
  google-api-client (0.23.9)
@@ -43,7 +43,7 @@ GEM
43
43
  memoist (0.16.2)
44
44
  mime-types (3.3.1)
45
45
  mime-types-data (~> 3.2015)
46
- mime-types-data (3.2020.1104)
46
+ mime-types-data (3.2021.0225)
47
47
  multi_json (1.15.0)
48
48
  multipart-post (2.1.1)
49
49
  os (1.1.1)
@@ -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.8'
6
- s.date = '2021-01-30'
5
+ s.version = '0.4.9'
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'
data/lib/google_api.rb CHANGED
@@ -1,47 +1,57 @@
1
1
  # frozen_string_literal: true
2
2
 
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'
30
+
3
31
  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
32
+ @@mock = false # Default to normal behavior
25
33
 
26
- def self.configure
27
- yield(configuration) if block_given?
28
- FileUtils.mkdir_p(configuration.root)
29
- configuration
30
- end
34
+ class << self
35
+ attr_reader :mock
31
36
 
32
- def self.logging!(level = :FATAL)
33
- raise ArgumentError, 'Unknown level' unless %i[DEBUG INFO WARN ERROR FATAL].include?(level)
37
+ def configuration
38
+ @configuration ||= GoogleAPI::Config.new
39
+ end
34
40
 
35
- Google::Apis.logger.level = Logger.const_get(level)
36
- end
41
+ def configure
42
+ yield(configuration) if block_given?
43
+ FileUtils.mkdir_p(configuration.root)
44
+ configuration
45
+ end
46
+
47
+ def logging!(level = :FATAL)
48
+ raise ArgumentError, 'Unknown level' unless %i[DEBUG INFO WARN ERROR FATAL].include?(level)
37
49
 
38
- # Internal requires
39
- require 'google_api/base'
40
- require 'google_api/calendar'
41
- require 'google_api/group'
42
- require 'google_api/configured'
50
+ Google::Apis.logger.level = Logger.const_get(level)
51
+ end
43
52
 
44
- # Extensions
45
- require 'ext/hash' unless defined?(Rails)
46
- require 'ext/silent_progress_bar'
53
+ def mock!(value = true)
54
+ @mock = value
55
+ end
56
+ end
47
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,11 @@ 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
+ self.send(:mock, method, *args)
33
+ else
34
+ ExpRetry.for(exception: RETRIES) { service.send(method, *args) }
35
+ end
31
36
  end
32
37
  end
33
38
  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(_method, *_args)
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
@@ -69,6 +69,11 @@ class GoogleAPI
69
69
 
70
70
  ProgressBar.create(bar_config)
71
71
  end
72
+
73
+ # Is this one necessary?
74
+ def mock(_method, *_args)
75
+ nil
76
+ end
72
77
  end
73
78
  end
74
79
  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(_method, *_args)
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
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.8
4
+ version: 0.4.9
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-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exp_retry