bps-google-api 0.1.1 → 0.1.2

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
- SHA256:
3
- metadata.gz: 2590ec53270ef1d9a249357917da8b47bfeef3109372168254125d1e819c2c8b
4
- data.tar.gz: a1a2b2a00089057ffb6fff6de8051d1a51ce0465eee9716a6474320781a36037
2
+ SHA1:
3
+ metadata.gz: 4c9bdd0dbd8450f6fc8ccca6dfc573c0162a675b
4
+ data.tar.gz: ea97614006f842d3cbd6a1781110f83514bd7110
5
5
  SHA512:
6
- metadata.gz: 5f6cccaccbffb1bd7b26102d9c24c6e84095992386ec227086d3fa85247fc9e6d5a7dd186ae628c92083803f4e66082581697909b306708b382d88ed3625a9ab
7
- data.tar.gz: 425e48ad269cef55ff5043bfc087a75578139c9f5bcc240bd9099ca7df6e903bea68fe5ef976dd4d95260bf7e2a324a529e7cb84a63bd635bbd8f9d686a7e5b7
6
+ metadata.gz: 52d33984ef3ef387e3a35120325e2227d16aed10593537c5d6ef50640157d12f10b95d689f451279138fb7c7ef728f0fdc8e9651dcfac4cb9ad700a309094b0e
7
+ data.tar.gz: 408fbf62a6f872d2471e70fb5de9f2a772fe2e92ea9d05be2aa496e3eda0974f1b50c19e3e7b11faacb53ae95d19180b9ec643a4651bbb2d4f00ae38dedfbcac
data/.rubocop.yml CHANGED
@@ -57,9 +57,6 @@ Naming/MemoizedInstanceVariableName:
57
57
  Naming/UncommunicativeMethodParamName:
58
58
  Enabled: false
59
59
 
60
- Rails/InverseOf:
61
- Enabled: true
62
-
63
60
  Style/Documentation:
64
61
  Enabled: false
65
62
  Style/FrozenStringLiteralComment:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bps-google-api (0.0.6)
4
+ bps-google-api (0.1.2)
5
5
  exp_retry (~> 0.0.8)
6
6
  fileutils (~> 1.2)
7
7
  google-api-client (~> 0.23.4)
@@ -34,21 +34,21 @@ GEM
34
34
  os (>= 0.9, < 2.0)
35
35
  signet (~> 0.7)
36
36
  httpclient (2.8.3)
37
- jwt (2.1.0)
37
+ jwt (2.2.1)
38
38
  memoist (0.16.0)
39
39
  mime-types (3.2.2)
40
40
  mime-types-data (~> 3.2015)
41
41
  mime-types-data (3.2019.0331)
42
42
  multi_json (1.13.1)
43
- multipart-post (2.0.0)
44
- os (1.0.0)
45
- public_suffix (3.0.3)
43
+ multipart-post (2.1.1)
44
+ os (1.0.1)
45
+ public_suffix (3.1.0)
46
46
  representable (3.0.4)
47
47
  declarative (< 0.1.0)
48
48
  declarative-option (< 0.2.0)
49
49
  uber (< 0.2.0)
50
50
  retriable (3.1.2)
51
- ruby-progressbar (1.10.0)
51
+ ruby-progressbar (1.10.1)
52
52
  signet (0.11.0)
53
53
  addressable (~> 2.3)
54
54
  faraday (~> 0.9)
@@ -63,4 +63,4 @@ DEPENDENCIES
63
63
  bps-google-api!
64
64
 
65
65
  BUNDLED WITH
66
- 2.0.0
66
+ 1.17.3
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bps-google-api'
5
- s.version = '0.1.1'
5
+ s.version = '0.1.2'
6
6
  s.date = '2019-06-15'
7
7
  s.summary = 'Configured Google API'
8
8
  s.description = 'A configured Google API wrapper.'
data/lib/google_api.rb CHANGED
@@ -7,9 +7,9 @@ module GoogleAPI
7
7
  require 'googleauth'
8
8
  require 'googleauth/stores/file_token_store'
9
9
 
10
- require 'google_api/base'
11
10
  require 'google_api/base/authorization'
12
- require 'google_api/calendar'
11
+ require 'google_api/base'
13
12
  require 'google_api/calendar/clear_test_calendar'
13
+ require 'google_api/calendar'
14
14
  require 'google_api/group'
15
15
  end
@@ -28,5 +28,14 @@ module GoogleAPI
28
28
  def call(method, *args)
29
29
  ExpRetry.for(exception: RETRIES) { service.send(method, *args) }
30
30
  end
31
+
32
+ def root_path
33
+ defined?(Rails) ? Rails.root : '.'
34
+ end
35
+
36
+ def last_token_path
37
+ path = %w[tmp run last_page_token]
38
+ File.join(root_path, *path)
39
+ end
31
40
  end
32
41
  end
@@ -72,6 +72,7 @@ module GoogleAPI
72
72
  def store_key(path, key)
73
73
  return if File.exist?(path)
74
74
 
75
+ FileUtils::mkdir_p('config/keys')
75
76
  File.open(path, 'w+') do |f|
76
77
  File.chmod(0o600, f)
77
78
  block_given? ? yield(f) : f.write(key)
@@ -80,7 +81,7 @@ module GoogleAPI
80
81
 
81
82
  def client_id_file
82
83
  store_key(
83
- File.join(Rails.root, 'config/keys/google_api_client.json'),
84
+ File.join(root_path, 'config/keys/google_api_client.json'),
84
85
  <<~KEY
85
86
  {"installed":{"client_id":"#{ENV['GOOGLE_CLIENT_ID']}","project_id":"charming-scarab-208718",
86
87
  "auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token",
@@ -92,7 +93,7 @@ module GoogleAPI
92
93
 
93
94
  def token_file
94
95
  store_key(
95
- File.join(Rails.root, 'config/keys/google_token.yaml'),
96
+ File.join(root_path, 'config/keys/google_token.yaml'),
96
97
  <<~KEY
97
98
  ---
98
99
  default: '{"client_id":"#{ENV['GOOGLE_CLIENT_ID']}","access_token":"#{ENV['GOOGLE_ACCESS_TOKEN']}",
@@ -5,7 +5,6 @@ module GoogleAPI
5
5
  include GoogleAPI::Calendar::ClearTestCalendar
6
6
 
7
7
  SERVICE_CLASS = Google::Apis::CalendarV3::CalendarService
8
- LAST_TOKEN_PATH ||= Rails.root.join('tmp', 'run', 'last_page_token')
9
8
  VALID_EVENT_KEYS ||= %i[
10
9
  summary start end description location recurrence conference_data conference_data_version
11
10
  ].freeze
@@ -63,5 +62,10 @@ module GoogleAPI
63
62
  key = date&.is_a?(String) ? :date : :date_time
64
63
  Google::Apis::CalendarV3::EventDateTime.new(key => date, time_zone: ENV['TZ'])
65
64
  end
65
+
66
+ def last_token_path
67
+ path = %w[tmp run last_page_token]
68
+ defined?(Rails) ? Rails.root.join(*path) : File.join(*path)
69
+ end
66
70
  end
67
71
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoogleAPI
4
- class Calendar
4
+ class Calendar < GoogleAPI::Base
5
5
  module ClearTestCalendar
6
6
  def clear_test_calendar(page_token: nil, page_limit: 50)
7
7
  Google::Apis.logger.level = Logger::WARN
@@ -17,7 +17,7 @@ module GoogleAPI
17
17
  private
18
18
 
19
19
  def choose_page_token(page_token)
20
- last_token = GoogleAPI::Calendar::LAST_TOKEN_PATH
20
+ last_token = last_token_path
21
21
  @page_token ||= File.read(last_token) if File.exist?(last_token)
22
22
  @page_token = page_token if page_token.present?
23
23
  end
@@ -47,10 +47,8 @@ module GoogleAPI
47
47
 
48
48
  def log_last_page_token
49
49
  puts "\n\n*** Last page token cleared: #{@page_token}"
50
- File.open(GoogleAPI::Calendar::LAST_TOKEN_PATH, 'w+') do |f|
51
- f.write(@page_token)
52
- end
53
- puts "\n*** Token stored in #{GoogleAPI::Calendar::LAST_TOKEN_PATH}"
50
+ File.open(last_token_path, 'w+') { |f| f.write(@page_token) }
51
+ puts "\n*** Token stored in #{last_token_path}"
54
52
  end
55
53
 
56
54
  def progress_bar(total)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bps-google-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.7.6
107
+ rubygems_version: 2.6.14.1
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Configured Google API