bps-google-api 0.4.3 → 0.4.9

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
- SHA1:
3
- metadata.gz: 723824ab2925aa6bc8778e59f3e6be268e50bf3b
4
- data.tar.gz: a5d1a77bf89d357b1134aa1dbd5a8568128f041a
2
+ SHA256:
3
+ metadata.gz: 8856171f804e9a62eb6efe7d15ca99c8ffe2ba56754aabd6f2db030c1fb0ef9b
4
+ data.tar.gz: 1b20297f206ef497b90ab9b7648dac0bf84c407d82c9f8a891d38903eb39c247
5
5
  SHA512:
6
- metadata.gz: 20cc6578a559490cd3303963b815b9fca1af009a1283d8a375e174c639123b5d4ecb60b07029842d0d58c75653335337a3248cdcaed664f17a79e0116819d7ce
7
- data.tar.gz: b5c762bc067c09a2d0aa723570716e6d26a7c0a21e07e3d9523aa20cbb34ca18dd91135aa72c7ecff8318314a0d5c226f6be9bd0f7d71614b7e4000a8a2189c2
6
+ metadata.gz: 4ae4b2476e6d4efb16593a71d0446217e0d3ab3b3be590918c7e9cbee81817d64bc52d9c164afc904133989666b5bb23d046f2deac6da38da359d0f3a1c82a7c
7
+ data.tar.gz: 822146e8b118409ed47cb4ac204ab5f4190fda432b5baf49a937cd68cf140ee38bf860752f985ed6c60d14d79635381e8ffeca15305c84e5d90688c206e709fd
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bps-google-api (0.4.3)
5
- exp_retry (~> 0.0.11)
4
+ bps-google-api (0.4.9)
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.3'
6
- s.date = '2019-06-27'
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'
@@ -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
+ # 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
36
+
37
+ def configuration
38
+ @configuration ||= GoogleAPI::Config.new
39
+ end
31
40
 
32
- # Internal requires
33
- require 'google_api/base'
34
- require 'google_api/calendar'
35
- require 'google_api/group'
36
- require 'google_api/configured'
41
+ def configure
42
+ yield(configuration) if block_given?
43
+ FileUtils.mkdir_p(configuration.root)
44
+ configuration
45
+ end
37
46
 
38
- # Extensions
39
- require 'ext/hash' unless defined?(Rails)
40
- require 'ext/silent_progress_bar'
47
+ def logging!(level = :FATAL)
48
+ raise ArgumentError, 'Unknown level' unless %i[DEBUG INFO WARN ERROR FATAL].include?(level)
49
+
50
+ Google::Apis.logger.level = Logger.const_get(level)
51
+ end
52
+
53
+ def mock!(value = true)
54
+ @mock = value
55
+ end
56
+ end
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,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,9 +15,13 @@ 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
- return conf if all
24
+ return conf if all || conf.nil?
21
25
 
22
26
  { id: conf.conference_id, signature: conf.signature }
23
27
  end
@@ -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
@@ -0,0 +1,15 @@
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
+ end
data/spec/spec_helper.rb CHANGED
@@ -25,6 +25,8 @@ 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'
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.3
4
+ version: 0.4.9
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: []