calendar-assistant 0.9.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.md +44 -22
- data/Rakefile +37 -6
- data/bin/calendar-assistant +3 -1
- data/lib/calendar_assistant.rb +14 -16
- data/lib/calendar_assistant/available_block.rb +1 -1
- data/lib/calendar_assistant/calendar_assistant.rb +21 -25
- data/lib/calendar_assistant/cli.rb +10 -10
- data/lib/calendar_assistant/cli/authorizer.rb +14 -14
- data/lib/calendar_assistant/cli/command_service.rb +2 -2
- data/lib/calendar_assistant/cli/commands.rb +47 -40
- data/lib/calendar_assistant/cli/config.rb +16 -17
- data/lib/calendar_assistant/cli/event_presenter.rb +2 -2
- data/lib/calendar_assistant/cli/event_set_presenter.rb +3 -3
- data/lib/calendar_assistant/cli/helpers.rb +7 -8
- data/lib/calendar_assistant/cli/linter_event_presenter.rb +3 -3
- data/lib/calendar_assistant/cli/linter_event_set_presenter.rb +4 -4
- data/lib/calendar_assistant/cli/printer.rb +15 -15
- data/lib/calendar_assistant/config.rb +11 -11
- data/lib/calendar_assistant/config/token_store.rb +4 -4
- data/lib/calendar_assistant/date_helpers.rb +1 -2
- data/lib/calendar_assistant/event.rb +54 -50
- data/lib/calendar_assistant/event_repository.rb +14 -15
- data/lib/calendar_assistant/event_repository_factory.rb +1 -1
- data/lib/calendar_assistant/event_set.rb +14 -14
- data/lib/calendar_assistant/extensions/google_apis_extensions.rb +1 -1
- data/lib/calendar_assistant/extensions/launchy_extensions.rb +7 -4
- data/lib/calendar_assistant/has_duration.rb +4 -5
- data/lib/calendar_assistant/lint_event_repository.rb +3 -3
- data/lib/calendar_assistant/location_config_validator.rb +3 -3
- data/lib/calendar_assistant/location_event_repository.rb +7 -8
- data/lib/calendar_assistant/predicate_collection.rb +1 -2
- data/lib/calendar_assistant/scheduler.rb +4 -5
- data/lib/calendar_assistant/string_helpers.rb +1 -1
- data/lib/calendar_assistant/version.rb +1 -1
- metadata +38 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0296a4a6bf6caf9b428325373af5819366f39d71349b4a3a365cd77ca2c1831b'
|
4
|
+
data.tar.gz: dad6547f9e014adc254d3530245ea07b29434d51f383d18f038917ef8db3d619
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7444e059b3608e4a8cb9cbd231865240322417f36be12de33b0f09ec9d77d7d07191ef20abb9ca0440d5d4b94b1b48cdceecc6a65a87035df10dccfd968e3bed
|
7
|
+
data.tar.gz: cd9b6e08ddcd646ea9660274423acc99f0db8dbae99f000ae39578872fb10632d62da4bdd19324eb40fbfce888954d3a38bae2d1fd38ba08364c71e1820d97dd
|
data/Gemfile
CHANGED
@@ -6,7 +6,8 @@ group :optional do
|
|
6
6
|
# These gems are not required for a functioning test suite, so not listing them in the gemspec.
|
7
7
|
# I personally find them useful in the developer role, though.
|
8
8
|
gem "autotest"
|
9
|
+
gem "pry"
|
9
10
|
gem "rspec-autotest"
|
11
|
+
gem "rufo"
|
10
12
|
gem "test_notifier"
|
11
|
-
gem "pry"
|
12
13
|
end
|
data/README.md
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
[![Concourse CI](https://ci.nokogiri.org/api/v1/teams/calendar-assistants/pipelines/calendar-assistant/jobs/rake-spec/badge)](https://ci.nokogiri.org/teams/calendar-assistants/pipelines/calendar-assistant)
|
14
14
|
[![Maintainability](https://api.codeclimate.com/v1/badges/3525792e1feeccfd8875/maintainability)](https://codeclimate.com/github/flavorjones/calendar-assistant/maintainability)
|
15
15
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/3525792e1feeccfd8875/test_coverage)](https://codeclimate.com/github/flavorjones/calendar-assistant/test_coverage)
|
16
|
+
[![Join the chat at https://gitter.im/flavorjones/calendar-assistant](https://badges.gitter.im/flavorjones/calendar-assistant.svg)](https://gitter.im/flavorjones/calendar-assistant?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
16
17
|
|
17
18
|
## Contents
|
18
19
|
|
@@ -36,6 +37,7 @@
|
|
36
37
|
* [`show`: View your calendar events](#show-view-your-calendar-events)
|
37
38
|
* [`lint`: Calendar events that require action](#lint-calendar-events-that-require-action)
|
38
39
|
* [`config`: View your configuration parameters](#config-view-your-configuration-parameters)
|
40
|
+
* [`interactive`: Interactive Console](#interactive-interactive-console)
|
39
41
|
- [Development](#development)
|
40
42
|
* [Running Tests Locally](#running-tests-locally)
|
41
43
|
* [Continuous Integration](#continuous-integration)
|
@@ -160,12 +162,11 @@ Options:
|
|
160
162
|
# Default: true
|
161
163
|
|
162
164
|
Description:
|
163
|
-
This command will walk you through setting up a Google Cloud Project, enabling the Google Calendar
|
164
|
-
|
165
|
+
This command will walk you through setting up a Google Cloud Project, enabling the Google Calendar API, and saving
|
166
|
+
the credentials necessary to access the API on behalf of users.
|
165
167
|
|
166
|
-
If you already have downloaded client credentials, you don't need to run this command. Instead,
|
167
|
-
|
168
|
-
`/home/user/.calendar-assistant.client`
|
168
|
+
If you already have downloaded client credentials, you don't need to run this command. Instead, rename the downloaded
|
169
|
+
JSON file to `/home/user/.calendar-assistant.client`
|
169
170
|
</pre>
|
170
171
|
|
171
172
|
|
@@ -182,14 +183,13 @@ Options:
|
|
182
183
|
# Default: true
|
183
184
|
|
184
185
|
Description:
|
185
|
-
Create and authorize a named profile (e.g., "work", "home", "flastname@company.tld") to access your
|
186
|
-
calendar.
|
186
|
+
Create and authorize a named profile (e.g., "work", "home", "flastname@company.tld") to access your calendar.
|
187
187
|
|
188
|
-
When setting up a profile, you'll be asked to visit a URL to authenticate, grant authorization, and
|
189
|
-
|
188
|
+
When setting up a profile, you'll be asked to visit a URL to authenticate, grant authorization, and generate and
|
189
|
+
persist an access token.
|
190
190
|
|
191
|
-
In order for this to work, you'll need to have set up your API client credentials. Run
|
192
|
-
|
191
|
+
In order for this to work, you'll need to have set up your API client credentials. Run `calendar-assistant help
|
192
|
+
setup` for instructions.
|
193
193
|
</pre>
|
194
194
|
|
195
195
|
|
@@ -197,17 +197,18 @@ Description:
|
|
197
197
|
|
198
198
|
<pre>
|
199
199
|
Commands:
|
200
|
-
calendar-assistant authorize PROFILE_NAME # create (or validate) a
|
201
|
-
calendar-assistant availability [DATE | DATERANGE | TIMERANGE] # Show your availability for a ...
|
202
|
-
calendar-assistant config # Dump your configuration
|
203
|
-
calendar-assistant help [COMMAND] # Describe available commands
|
204
|
-
calendar-assistant
|
205
|
-
calendar-assistant
|
206
|
-
calendar-assistant
|
207
|
-
calendar-assistant location
|
208
|
-
calendar-assistant
|
209
|
-
calendar-assistant
|
210
|
-
calendar-assistant
|
200
|
+
calendar-assistant authorize PROFILE_NAME # create (or validate) a profile named NAME with ca...
|
201
|
+
calendar-assistant availability [DATE | DATERANGE | TIMERANGE] # Show your availability for a date or range of dat...
|
202
|
+
calendar-assistant config # Dump your configuration parameters (merge of defa...
|
203
|
+
calendar-assistant help [COMMAND] # Describe available commands or one specific command
|
204
|
+
calendar-assistant interactive # interactive console for calendar assistant
|
205
|
+
calendar-assistant join [TIME] # Open the URL for a video call attached to your me...
|
206
|
+
calendar-assistant lint [DATE | DATERANGE | TIMERANGE] # Lint your events for a date or range of dates (de...
|
207
|
+
calendar-assistant location [DATE | DATERANGE] # Show your location for a date or range of dates (...
|
208
|
+
calendar-assistant location-set LOCATION [DATE | DATERANGE] # Set your location to LOCATION for a date or range...
|
209
|
+
calendar-assistant setup # Link your local calendar-assistant installation t...
|
210
|
+
calendar-assistant show [DATE | DATERANGE | TIMERANGE] # Show your events for a date or range of dates (de...
|
211
|
+
calendar-assistant version # Display the version of calendar-assistant
|
211
212
|
|
212
213
|
Options:
|
213
214
|
-h, -?, [--help], [--no-help]
|
@@ -579,6 +580,27 @@ meeting-length = "30m"
|
|
579
580
|
start-of-day = "9am"
|
580
581
|
</pre>
|
581
582
|
|
583
|
+
### `interactive`: Interactive Console
|
584
|
+
|
585
|
+
<pre>
|
586
|
+
Usage:
|
587
|
+
calendar-assistant interactive
|
588
|
+
|
589
|
+
Options:
|
590
|
+
-h, -?, [--help], [--no-help]
|
591
|
+
[--debug], [--no-debug] # how dare you suggest there are bugs
|
592
|
+
-f, [--formatting], [--no-formatting] # Enable Text Formatting
|
593
|
+
# Default: true
|
594
|
+
|
595
|
+
interactive console for calendar assistant
|
596
|
+
</pre>
|
597
|
+
|
598
|
+
For example, check the version of calendar assistant
|
599
|
+
|
600
|
+
```
|
601
|
+
calendar-assistant> version
|
602
|
+
0.0.0
|
603
|
+
```
|
582
604
|
|
583
605
|
## Development
|
584
606
|
|
data/Rakefile
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
require "concourse"
|
4
4
|
require "license_finder"
|
5
|
+
require "tempfile"
|
6
|
+
require "rainbow"
|
5
7
|
|
6
8
|
#
|
7
9
|
# concourse
|
8
10
|
#
|
9
11
|
Concourse.new("calendar-assistant", fly_target: "calendar-assistants").create_tasks!
|
10
12
|
|
11
|
-
|
12
13
|
#
|
13
14
|
# spec tasks
|
14
15
|
#
|
@@ -17,26 +18,38 @@ RSpec::Core::RakeTask.new("spec")
|
|
17
18
|
task "test" => "spec" # undocumented alias for 'spec'
|
18
19
|
|
19
20
|
desc "Run unit specs"
|
20
|
-
RSpec::Core::RakeTask.new("spec:unit")
|
21
|
+
RSpec::Core::RakeTask.new("spec:unit") do |t|
|
21
22
|
t.rspec_opts ||= []
|
22
23
|
t.rspec_opts << " --tag=~type:aruba"
|
23
24
|
end
|
24
25
|
|
25
26
|
desc "Run feature specs"
|
26
|
-
RSpec::Core::RakeTask.new("spec:feature")
|
27
|
+
RSpec::Core::RakeTask.new("spec:feature") do |t|
|
27
28
|
t.rspec_opts ||= []
|
28
29
|
t.rspec_opts << " --tag=type:aruba"
|
29
30
|
end
|
30
31
|
|
31
|
-
desc "Ensure all dependencies meet license requirements
|
32
|
+
desc "Ensure all dependencies meet license requirements"
|
32
33
|
task "license_finder" do
|
33
34
|
LicenseFinder::CLI::Main.start(["report"])
|
34
35
|
LicenseFinder::CLI::Main.start([])
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
#
|
39
|
+
# readme tasks
|
40
|
+
#
|
41
|
+
desc "Generate the README.md from its erb template"
|
42
|
+
task "readme" do
|
43
|
+
sh "./generate-readme"
|
44
|
+
end
|
39
45
|
|
46
|
+
desc "Generate the README.md from its erb template"
|
47
|
+
task "readme:check" do
|
48
|
+
file = Tempfile.new("readme").path
|
49
|
+
sh "./generate-readme #{file}"
|
50
|
+
sh "diff -C3 #{file} README.md"
|
51
|
+
puts Rainbow("README.md looks good").green
|
52
|
+
end
|
40
53
|
|
41
54
|
#
|
42
55
|
# docker docker docker
|
@@ -53,3 +66,21 @@ end
|
|
53
66
|
|
54
67
|
desc "Build and push a docker image for testing"
|
55
68
|
task "docker" => ["docker:build", "docker:push"]
|
69
|
+
|
70
|
+
#
|
71
|
+
# formatting
|
72
|
+
#
|
73
|
+
desc "Format ruby code"
|
74
|
+
task "format" do
|
75
|
+
sh "rufo lib spec", verbose: true
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# default
|
80
|
+
#
|
81
|
+
desc "Run unit specs, feature specs, license finder, and check the README"
|
82
|
+
task "default" => [
|
83
|
+
"spec",
|
84
|
+
"readme:check",
|
85
|
+
"license_finder", # last because it modifies bundle env
|
86
|
+
]
|
data/bin/calendar-assistant
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
|
-
libdir = File.join(
|
2
|
+
libdir = File.join(File.dirname(__FILE__), "..", "lib")
|
3
3
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
4
4
|
|
5
5
|
require "calendar_assistant"
|
6
6
|
|
7
|
+
Encoding.default_internal = Encoding::UTF_8
|
7
8
|
Rainbow.enabled = true
|
8
9
|
|
9
10
|
begin
|
11
|
+
require "calendar_assistant/cli"
|
10
12
|
CalendarAssistant::CLI::Commands.start ARGV
|
11
13
|
rescue Google::Apis::AuthorizationError, CalendarAssistant::BaseException => e
|
12
14
|
printf "ERROR: %s\n", e
|
data/lib/calendar_assistant.rb
CHANGED
@@ -25,22 +25,20 @@ require "active_support/time" # Time doesn't trigger autoload
|
|
25
25
|
require "calendar_assistant/calendar_assistant"
|
26
26
|
|
27
27
|
class CalendarAssistant
|
28
|
-
autoload :VERSION,
|
29
|
-
autoload :Config,
|
30
|
-
autoload :StringHelpers,
|
31
|
-
autoload :DateHelpers,
|
32
|
-
autoload :HasDuration,
|
33
|
-
autoload :AvailableBlock,
|
34
|
-
autoload :Event,
|
35
|
-
autoload :EventRepository,
|
36
|
-
autoload :EventRepositoryFactory,
|
37
|
-
autoload :EventSet,
|
38
|
-
autoload :Scheduler,
|
39
|
-
autoload :LocalService,
|
28
|
+
autoload :VERSION, "calendar_assistant/version"
|
29
|
+
autoload :Config, "calendar_assistant/config"
|
30
|
+
autoload :StringHelpers, "calendar_assistant/string_helpers"
|
31
|
+
autoload :DateHelpers, "calendar_assistant/date_helpers"
|
32
|
+
autoload :HasDuration, "calendar_assistant/has_duration"
|
33
|
+
autoload :AvailableBlock, "calendar_assistant/available_block"
|
34
|
+
autoload :Event, "calendar_assistant/event"
|
35
|
+
autoload :EventRepository, "calendar_assistant/event_repository"
|
36
|
+
autoload :EventRepositoryFactory, "calendar_assistant/event_repository_factory"
|
37
|
+
autoload :EventSet, "calendar_assistant/event_set"
|
38
|
+
autoload :Scheduler, "calendar_assistant/scheduler"
|
39
|
+
autoload :LocalService, "calendar_assistant/local_service"
|
40
40
|
autoload :LocationEventRepository, "calendar_assistant/location_event_repository"
|
41
|
-
autoload :LintEventRepository,
|
42
|
-
autoload :PredicateCollection,
|
41
|
+
autoload :LintEventRepository, "calendar_assistant/lint_event_repository"
|
42
|
+
autoload :PredicateCollection, "calendar_assistant/predicate_collection"
|
43
43
|
autoload :LocationConfigValidator, "calendar_assistant/location_config_validator"
|
44
44
|
end
|
45
|
-
|
46
|
-
require "calendar_assistant/cli"
|
@@ -1,46 +1,42 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
class CalendarAssistant
|
3
|
-
class BaseException < RuntimeError
|
3
|
+
class BaseException < RuntimeError; end
|
4
4
|
|
5
|
-
EMOJI_PLANE
|
6
|
-
EMOJI_1_1
|
5
|
+
EMOJI_PLANE = "🛪" # U+1F6EA NORTHEAST-POINTING AIRPLANE
|
6
|
+
EMOJI_1_1 = "👫" # MAN AND WOMAN HOLDING HANDS
|
7
7
|
|
8
8
|
attr_reader :service, :calendar, :config
|
9
9
|
|
10
|
-
def self.date_range_cast
|
10
|
+
def self.date_range_cast(time_range)
|
11
11
|
time_range.first.to_date..(time_range.last + 1.day).to_date
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.in_tz
|
14
|
+
def self.in_tz(time_zone, &block)
|
15
15
|
# this is totally not thread-safe
|
16
16
|
orig_time_tz = Time.zone
|
17
|
-
orig_env_tz = ENV[
|
17
|
+
orig_env_tz = ENV["TZ"]
|
18
18
|
begin
|
19
19
|
unless time_zone.nil?
|
20
20
|
Time.zone = time_zone
|
21
|
-
ENV[
|
21
|
+
ENV["TZ"] = time_zone
|
22
22
|
end
|
23
23
|
yield
|
24
24
|
ensure
|
25
25
|
Time.zone = orig_time_tz
|
26
|
-
ENV[
|
26
|
+
ENV["TZ"] = orig_env_tz
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
def initialize config=Config.new,
|
30
|
+
def initialize(config = Config.new,
|
32
31
|
event_repository_factory: EventRepositoryFactory,
|
33
|
-
service:
|
34
|
-
@config = config
|
32
|
+
service:) @config = config
|
35
33
|
@service = service
|
36
|
-
|
37
34
|
@calendar = service.get_calendar Config::DEFAULT_CALENDAR_ID
|
38
35
|
@event_repository_factory = event_repository_factory
|
39
36
|
@event_repositories = {} # type, calendar_id → event_repository
|
40
|
-
@event_predicates = PredicateCollection.build(config.must_be, config.must_not_be)
|
41
|
-
end
|
37
|
+
@event_predicates = PredicateCollection.build(config.must_be, config.must_not_be) end
|
42
38
|
|
43
|
-
def in_env
|
39
|
+
def in_env(&block)
|
44
40
|
# this is totally not thread-safe
|
45
41
|
config.in_env do
|
46
42
|
in_tz do
|
@@ -49,21 +45,21 @@ class CalendarAssistant
|
|
49
45
|
end
|
50
46
|
end
|
51
47
|
|
52
|
-
def in_tz
|
48
|
+
def in_tz(&block)
|
53
49
|
CalendarAssistant.in_tz calendar.time_zone do
|
54
50
|
yield
|
55
51
|
end
|
56
52
|
end
|
57
53
|
|
58
|
-
def lint_events
|
54
|
+
def lint_events(time_range)
|
59
55
|
calendar_ids = config.calendar_ids
|
60
56
|
if calendar_ids.length > 1
|
61
57
|
raise BaseException, "CalendarAssistant#lint_events only supports one person (for now)"
|
62
58
|
end
|
63
|
-
event_repository(calendar_ids.first, type: :lint).find(time_range,
|
59
|
+
event_repository(calendar_ids.first, type: :lint).find(time_range, predicates: @event_predicates)
|
64
60
|
end
|
65
61
|
|
66
|
-
def find_events
|
62
|
+
def find_events(time_range)
|
67
63
|
calendar_ids = config.calendar_ids
|
68
64
|
if calendar_ids.length > 1
|
69
65
|
raise BaseException, "CalendarAssistant#find_events only supports one person (for now)"
|
@@ -71,7 +67,7 @@ class CalendarAssistant
|
|
71
67
|
event_repository(calendar_ids.first).find(time_range, predicates: @event_predicates)
|
72
68
|
end
|
73
69
|
|
74
|
-
def availability
|
70
|
+
def availability(time_range)
|
75
71
|
calendar_ids = config.calendar_ids
|
76
72
|
ers = calendar_ids.map do |calendar_id|
|
77
73
|
event_repository calendar_id
|
@@ -79,14 +75,14 @@ class CalendarAssistant
|
|
79
75
|
Scheduler.new(self, ers).available_blocks(time_range, predicates: @event_predicates)
|
80
76
|
end
|
81
77
|
|
82
|
-
def find_location_events
|
78
|
+
def find_location_events(time_range)
|
83
79
|
event_repository(type: :location).find(time_range, predicates: @event_predicates)
|
84
80
|
end
|
85
81
|
|
86
|
-
def create_location_events
|
82
|
+
def create_location_events(time_range, location)
|
87
83
|
LocationConfigValidator.valid?(config)
|
88
84
|
|
89
|
-
event_set = EventSet::Hash.new(event_repository,{})
|
85
|
+
event_set = EventSet::Hash.new(event_repository, {})
|
90
86
|
|
91
87
|
unique_calendar_ids.each do |calendar_id|
|
92
88
|
event_set[calendar_id] = event_repository(calendar_id, type: :location).create(time_range, location, predicates: @event_predicates)
|
@@ -95,7 +91,7 @@ class CalendarAssistant
|
|
95
91
|
event_set
|
96
92
|
end
|
97
93
|
|
98
|
-
def event_repository
|
94
|
+
def event_repository(calendar_id = Config::DEFAULT_CALENDAR_ID, type: :base)
|
99
95
|
@event_repositories[type] ||= {}
|
100
96
|
@event_repositories[type][calendar_id] ||=
|
101
97
|
@event_repository_factory.new_event_repository(@service, calendar_id, config: config, type: type)
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
1
|
+
require_relative "cli/config"
|
2
|
+
require_relative "cli/helpers"
|
3
|
+
require_relative "cli/command_service"
|
4
|
+
require_relative "cli/printer"
|
5
|
+
require_relative "cli/event_presenter"
|
6
|
+
require_relative "cli/event_set_presenter"
|
7
|
+
require_relative "cli/linter_event_presenter"
|
8
|
+
require_relative "cli/linter_event_set_presenter"
|
9
|
+
require_relative "cli/authorizer"
|
10
|
+
require_relative "cli/commands"
|
@@ -20,17 +20,17 @@
|
|
20
20
|
class CalendarAssistant
|
21
21
|
module CLI
|
22
22
|
class Authorizer
|
23
|
-
class NoCredentials < CalendarAssistant::BaseException
|
24
|
-
class UnauthorizedError < CalendarAssistant::BaseException
|
23
|
+
class NoCredentials < CalendarAssistant::BaseException; end
|
24
|
+
class UnauthorizedError < CalendarAssistant::BaseException; end
|
25
25
|
|
26
|
-
OOB_URI =
|
26
|
+
OOB_URI = "urn:ietf:wg:oauth:2.0:oob".freeze
|
27
27
|
APPLICATION_NAME = "Flavorjones Calendar Assistant".freeze
|
28
|
-
CREDENTIALS_PATH = File.join (ENV[
|
28
|
+
CREDENTIALS_PATH = File.join (ENV["CA_HOME"] || ENV["HOME"]), ".calendar-assistant.client"
|
29
29
|
SCOPE = Google::Apis::CalendarV3::AUTH_CALENDAR
|
30
30
|
|
31
31
|
attr_reader :profile_name, :config_token_store
|
32
32
|
|
33
|
-
def initialize
|
33
|
+
def initialize(profile_name, config_token_store)
|
34
34
|
@profile_name = profile_name
|
35
35
|
@config_token_store = config_token_store
|
36
36
|
end
|
@@ -50,7 +50,7 @@ class CalendarAssistant
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
private
|
54
54
|
|
55
55
|
def credentials
|
56
56
|
@credentials ||= authorizer.get_credentials profile_name
|
@@ -74,15 +74,15 @@ class CalendarAssistant
|
|
74
74
|
|
75
75
|
def authorizer
|
76
76
|
@authorizer ||= begin
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
if !File.exists?(CREDENTIALS_PATH)
|
78
|
+
raise NoCredentials, "No credentials found. Please run `calendar-assistant help setup` for instructions"
|
79
|
+
end
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
FileUtils.chmod 0600, CREDENTIALS_PATH
|
82
|
+
client_id = Google::Auth::ClientId.from_file(CREDENTIALS_PATH)
|
83
|
+
Google::Auth::UserAuthorizer.new(client_id, SCOPE, config_token_store)
|
84
|
+
end
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
88
|
-
end
|
88
|
+
end
|