bps-google-api 0.1.5 → 0.2.0

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
  SHA1:
3
- metadata.gz: 36e2a1cd1f252cfeef6ffd6d9876aa57edf0bdbc
4
- data.tar.gz: ac11872b200429439ca3be64872cbab00fbae4e5
3
+ metadata.gz: 4bb3f5af2dbe6a57df4945c7d082aab5e6f68edb
4
+ data.tar.gz: 225fd27b21ae836d6d051bf32a81b96e17ed71f7
5
5
  SHA512:
6
- metadata.gz: 2f6852acfb76d9b69d6ed8d70b93c4b84c7247cb0115cc507da4300a3504bba1e2f6a1794cf91eb5d205261a45bd08c98f5873cb666c9ba63c38c74e43126115
7
- data.tar.gz: fee256d45c8795cd36e49c157bd233d697a1ffaccf684edb85274c09979541b0799847e1a94530d67c15089b7bfd97242f7fa7b99c738cc7f88a465a2d053bb5
6
+ metadata.gz: 031d62aac72e1de816ac5d309fed95d8886c7b205633f25c9accf6ca8e43fa389c62334943a57f9ed4a0f85c47583149daab492eff8be4db403b7018c90b09a7
7
+ data.tar.gz: 3e5e6374f3731ba02d763d515bf3877d35e635a0c5f1f87a465ac8fb891581aa288a42c83eed1fbf93a963dba681115269a497efe864d71c31116f0580940e45
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
- config/
1
+ config/
2
+ coverage/
3
+ tmp/
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.5
2
+ TargetRubyVersion: 2.4
3
3
  Exclude:
4
4
  - bin/**/*
5
5
  - config/**/*
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.4
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.4
4
+ branches:
5
+ except:
6
+ - "/^v[0-9]+\\.[0-9]+\\.[0-9]+(?:-.*)?/"
7
+ notifications:
8
+ email:
9
+ on_success: change
10
+ on_failure: always
11
+ before_install:
12
+ - gem install bundler -v '< 2'
13
+ before_script:
14
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
15
+ - chmod +x ./cc-test-reporter
16
+ - ./cc-test-reporter before-build
17
+ script:
18
+ - bundle exec rspec
19
+ after_script:
20
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bps-google-api (0.1.5)
4
+ bps-google-api (0.2.0)
5
5
  exp_retry (~> 0.0.11)
6
6
  fileutils (~> 1.2)
7
7
  google-api-client (~> 0.23.4)
@@ -14,7 +14,9 @@ GEM
14
14
  public_suffix (>= 2.0.2, < 4.0)
15
15
  declarative (0.0.10)
16
16
  declarative-option (0.1.0)
17
- exp_retry (0.0.11)
17
+ diff-lcs (1.3)
18
+ docile (1.3.2)
19
+ exp_retry (0.0.12)
18
20
  faraday (0.15.4)
19
21
  multipart-post (>= 1.2, < 3)
20
22
  fileutils (1.2.0)
@@ -34,6 +36,7 @@ GEM
34
36
  os (>= 0.9, < 2.0)
35
37
  signet (~> 0.7)
36
38
  httpclient (2.8.3)
39
+ json (2.2.0)
37
40
  jwt (2.2.1)
38
41
  memoist (0.16.0)
39
42
  mime-types (3.2.2)
@@ -48,12 +51,30 @@ GEM
48
51
  declarative-option (< 0.2.0)
49
52
  uber (< 0.2.0)
50
53
  retriable (3.1.2)
54
+ rspec (3.8.0)
55
+ rspec-core (~> 3.8.0)
56
+ rspec-expectations (~> 3.8.0)
57
+ rspec-mocks (~> 3.8.0)
58
+ rspec-core (3.8.1)
59
+ rspec-support (~> 3.8.0)
60
+ rspec-expectations (3.8.4)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.8.0)
63
+ rspec-mocks (3.8.1)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.8.0)
66
+ rspec-support (3.8.2)
51
67
  ruby-progressbar (1.10.1)
52
68
  signet (0.11.0)
53
69
  addressable (~> 2.3)
54
70
  faraday (~> 0.9)
55
71
  jwt (>= 1.5, < 3.0)
56
72
  multi_json (~> 1.10)
73
+ simplecov (0.16.1)
74
+ docile (~> 1.1)
75
+ json (>= 1.8, < 3)
76
+ simplecov-html (~> 0.10.0)
77
+ simplecov-html (0.10.2)
57
78
  uber (0.1.0)
58
79
 
59
80
  PLATFORMS
@@ -61,6 +82,8 @@ PLATFORMS
61
82
 
62
83
  DEPENDENCIES
63
84
  bps-google-api!
85
+ rspec (~> 3.8, >= 3.8.0)
86
+ simplecov (~> 0.16, >= 0.16.1)
64
87
 
65
88
  BUNDLED WITH
66
89
  1.17.3
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bps-google-api'
5
- s.version = '0.1.5'
6
- s.date = '2019-06-15'
5
+ s.version = '0.2.0'
6
+ s.date = '2019-06-20'
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'
@@ -13,8 +13,13 @@ Gem::Specification.new do |s|
13
13
  s.require_paths = %w[lib]
14
14
  s.files = `git ls-files`.split("\n")
15
15
 
16
+ s.required_ruby_version = '~> 2.4'
17
+
16
18
  s.add_runtime_dependency 'exp_retry', '~> 0.0.11'
17
19
  s.add_runtime_dependency 'fileutils', '~> 1.2'
18
20
  s.add_runtime_dependency 'google-api-client', '~> 0.23.4'
19
21
  s.add_runtime_dependency 'ruby-progressbar', '~> 1.10'
22
+
23
+ s.add_development_dependency 'rspec', '~> 3.8', '>= 3.8.0'
24
+ s.add_development_dependency 'simplecov', '~> 0.16', '>= 0.16.1'
20
25
  end
data/lib/google_api.rb CHANGED
@@ -7,6 +7,10 @@ module GoogleAPI
7
7
  require 'googleauth'
8
8
  require 'googleauth/stores/file_token_store'
9
9
 
10
+ require 'exp_retry'
11
+ require 'fileutils'
12
+ require 'ruby-progressbar'
13
+
10
14
  require 'google_api/base'
11
15
  require 'google_api/calendar'
12
16
  require 'google_api/group'
@@ -33,27 +33,30 @@ module GoogleAPI
33
33
  :event_not_found
34
34
  end
35
35
 
36
- def permit(calendar, user)
36
+ def permit(calendar, user = nil, email: nil)
37
+ email ||= user&.email
38
+
37
39
  rule = Google::Apis::CalendarV3::AclRule.new(
38
- scope: { type: 'user', value: user.email }, role: 'writer'
40
+ scope: { type: 'user', value: email }, role: 'writer'
39
41
  )
40
42
 
41
- result = call(:insert_acl, calendar, rule)
42
- user.update(calendar_rule_id: result.id)
43
+ user&.update(calendar_rule_id: call(:insert_acl, calendar, rule).id)
43
44
  end
44
45
 
45
- def unpermit(calendar, user)
46
- call(:delete_acl, calendar, user&.calendar_rule_id)
46
+ def unpermit(calendar, user = nil, calendar_rule_id: nil)
47
+ calendar_rule_id ||= user&.calendar_rule_id
48
+
49
+ call(:delete_acl, calendar, calendar_rule_id)
47
50
  rescue Google::Apis::ClientError
48
51
  :permission_not_found
49
52
  ensure
50
- user.update(calendar_rule_id: nil)
53
+ user&.update(calendar_rule_id: nil)
51
54
  end
52
55
 
53
56
  private
54
57
 
55
58
  def event(event_options)
56
- event_options.assert_valid_keys(VALID_EVENT_KEYS)
59
+ validate_event_options(event_options)
57
60
  event_options[:start] = date(event_options[:start])
58
61
  event_options[:end] = date(event_options[:end])
59
62
 
@@ -69,5 +72,11 @@ module GoogleAPI
69
72
  path = %w[tmp run last_page_token]
70
73
  defined?(Rails) ? Rails.root.join(*path) : File.join(*path)
71
74
  end
75
+
76
+ def validate_event_options(event_options)
77
+ return unless event_options.respond_to?(:assert_valid_keys)
78
+
79
+ event_options.assert_valid_keys(VALID_EVENT_KEYS)
80
+ end
72
81
  end
73
82
  end
@@ -12,7 +12,7 @@ module GoogleAPI
12
12
  rescue Google::Apis::RateLimitError
13
13
  puts "\n\n*** Google::Apis::RateLimitError (Rate Limit Exceeded)"
14
14
  ensure
15
- log_last_page_token unless @page_token.blank?
15
+ log_last_page_token if token?
16
16
  end
17
17
 
18
18
  private
@@ -20,18 +20,23 @@ module GoogleAPI
20
20
  def choose_page_token(page_token)
21
21
  last_token = last_token_path
22
22
  @page_token ||= File.read(last_token) if File.exist?(last_token)
23
- @page_token = page_token if page_token.present?
23
+ @page_token = page_token if token?(page_token)
24
+ end
25
+
26
+ def token?(token = nil)
27
+ token ||= @token
28
+ token != ''
24
29
  end
25
30
 
26
31
  def loop_over_pages(cal_id, page_limit: 50)
27
- puts "*** Starting with page token: #{@page_token}" if @verbose && @page_token.present?
32
+ puts "*** Starting with page token: #{@page_token}" if @verbose && token?
28
33
 
29
34
  page_limit -= 1 while (@page_token = clear_page(cal_id)) && page_limit.positive?
30
35
  end
31
36
 
32
37
  def clear_page(cal_id)
33
38
  response = list(cal_id, page_token: @page_token)
34
- clear_events_from_page(cal_id, response.items) unless response.items.blank?
39
+ clear_events_from_page(cal_id, response.items) unless response.items.empty?
35
40
  response.next_page_token
36
41
  end
37
42
 
data/spec/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ Metrics/LineLength:
2
+ Max: 100
3
+ Metrics/BlockLength:
4
+ Enabled: false
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe GoogleAPI::Base do
6
+ subject { described_class.new }
7
+
8
+ it 'does not have a service class' do
9
+ expect { subject }.to raise_error(
10
+ NameError, 'uninitialized constant GoogleAPI::Base::SERVICE_CLASS'
11
+ )
12
+ end
13
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe GoogleAPI::Calendar do
6
+ subject { described_class.new }
7
+
8
+ it 'has a service class' do
9
+ expect { subject.send(:service_class) }.not_to raise_error
10
+ end
11
+
12
+ it 'has the correct service class' do
13
+ expect(subject.send(:service_class)).to eql(Google::Apis::CalendarV3::CalendarService)
14
+ end
15
+
16
+ describe 'list' do
17
+ it 'returns not found for a nonexistent calendar' do
18
+ expect { subject.list('not-a-calendar') }.to raise_error(
19
+ Google::Apis::ClientError, 'notFound: Not Found'
20
+ )
21
+ end
22
+ end
23
+
24
+ describe 'create' do
25
+ it 'returns not found for a nonexistent calendar' do
26
+ expect { subject.create('not-a-calendar') }.to raise_error(
27
+ Google::Apis::ClientError, 'notFound: Not Found'
28
+ )
29
+ end
30
+ end
31
+
32
+ describe 'get' do
33
+ it 'returns not found for a nonexistent calendar' do
34
+ expect { subject.get('not-a-calendar', 'not-an-event') }.to raise_error(
35
+ Google::Apis::ClientError, 'notFound: Not Found'
36
+ )
37
+ end
38
+ end
39
+
40
+ describe 'update' do
41
+ it 'returns not found for a nonexistent calendar' do
42
+ expect { subject.update('not-a-calendar', 'not-an-event') }.to raise_error(
43
+ Google::Apis::ClientError, 'notFound: Not Found'
44
+ )
45
+ end
46
+ end
47
+
48
+ describe 'delete' do
49
+ it 'returns event not found for a nonexistent calendar' do
50
+ expect(subject.delete('not-a-calendar', 'not-an-event')).to eql(
51
+ :event_not_found
52
+ )
53
+ end
54
+ end
55
+
56
+ describe 'permit' do
57
+ it 'returns nil for a nonexistent calendar' do
58
+ expect(subject.permit('not-a-calendar', email: 'not-a-user')).to be_nil
59
+ end
60
+ end
61
+
62
+ describe 'unpermit' do
63
+ it 'returns permission not found for a nonexistent calendar' do
64
+ expect(subject.unpermit('not-a-calendar', calendar_rule_id: 'not-a-user')).to eql(
65
+ :permission_not_found
66
+ )
67
+ end
68
+ end
69
+
70
+ describe 'clear test calendar' do
71
+ it 'does not raise any errors' do
72
+ expect { subject.clear_test_calendar }.not_to raise_error
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe GoogleAPI::Group do
6
+ subject { described_class.new('test-group@example.com') }
7
+
8
+ it 'has a service class' do
9
+ expect { subject.send(:service_class) }.not_to raise_error
10
+ end
11
+
12
+ it 'has the correct service class' do
13
+ expect(subject.send(:service_class)).to eql(Google::Apis::AdminDirectoryV1::DirectoryService)
14
+ end
15
+
16
+ describe 'get' do
17
+ it 'returns not found for a nonexistent group' do
18
+ expect { subject.get }.to raise_error(
19
+ Google::Apis::ClientError, 'forbidden: Not Authorized to access this resource/api'
20
+ )
21
+ end
22
+ end
23
+
24
+ describe 'members' do
25
+ it 'returns forbidden for a nonexistent group' do
26
+ expect { subject.members }.to raise_error(
27
+ Google::Apis::ClientError, 'forbidden: Not Authorized to access this resource/api'
28
+ )
29
+ end
30
+ end
31
+
32
+ describe 'add' do
33
+ it 'returns not found for a nonexistent group' do
34
+ expect(subject.add('test-member@example.com')).to eql(:already_exists)
35
+ end
36
+ end
37
+
38
+ describe 'remove' do
39
+ it 'returns not found for a nonexistent group' do
40
+ expect(subject.remove('test-member@example.com')).to eql(:not_found)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ Bundler.setup
5
+ require 'simplecov'
6
+ SimpleCov.start do
7
+ add_filter '/spec'
8
+ end
9
+
10
+ require 'google_api'
11
+
12
+ RSpec.configure do |config|
13
+ config.before(:suite) do
14
+ FileUtils.mkdir_p('tmp/run')
15
+ end
16
+ 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.1.5
4
+ version: 0.2.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-15 00:00:00.000000000 Z
11
+ date: 2019-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: exp_retry
@@ -66,6 +66,46 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 3.8.0
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '3.8'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 3.8.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.16'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 0.16.1
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '0.16'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 0.16.1
69
109
  description: A configured Google API wrapper.
70
110
  email: julian@fiander.one
71
111
  executables: []
@@ -74,6 +114,8 @@ extra_rdoc_files: []
74
114
  files:
75
115
  - ".gitignore"
76
116
  - ".rubocop.yml"
117
+ - ".ruby-version"
118
+ - ".travis.yml"
77
119
  - Gemfile
78
120
  - Gemfile.lock
79
121
  - Readme.md
@@ -84,6 +126,11 @@ files:
84
126
  - lib/google_api/calendar.rb
85
127
  - lib/google_api/calendar/clear_test_calendar.rb
86
128
  - lib/google_api/group.rb
129
+ - spec/.rubocop.yml
130
+ - spec/lib/google_api/base_spec.rb
131
+ - spec/lib/google_api/calendar_spec.rb
132
+ - spec/lib/google_api/group_spec.rb
133
+ - spec/spec_helper.rb
87
134
  homepage: http://rubygems.org/gems/bps-google-api
88
135
  licenses:
89
136
  - GPL-3.0
@@ -94,9 +141,9 @@ require_paths:
94
141
  - lib
95
142
  required_ruby_version: !ruby/object:Gem::Requirement
96
143
  requirements:
97
- - - ">="
144
+ - - "~>"
98
145
  - !ruby/object:Gem::Version
99
- version: '0'
146
+ version: '2.4'
100
147
  required_rubygems_version: !ruby/object:Gem::Requirement
101
148
  requirements:
102
149
  - - ">="