Class: CalendarAssistant
- Inherits:
-
Object
show all
- Defined in:
- lib/calendar_assistant/cli/authorizer.rb,
lib/calendar_assistant.rb,
lib/calendar_assistant/event.rb,
lib/calendar_assistant/config.rb,
lib/calendar_assistant/version.rb,
lib/calendar_assistant/event_set.rb,
lib/calendar_assistant/scheduler.rb,
lib/calendar_assistant/cli/config.rb,
lib/calendar_assistant/cli/helpers.rb,
lib/calendar_assistant/cli/printer.rb,
lib/calendar_assistant/cli/commands.rb,
lib/calendar_assistant/date_helpers.rb,
lib/calendar_assistant/has_duration.rb,
lib/calendar_assistant/local_service.rb,
lib/calendar_assistant/string_helpers.rb,
lib/calendar_assistant/available_block.rb,
lib/calendar_assistant/event_repository.rb,
lib/calendar_assistant/calendar_assistant.rb,
lib/calendar_assistant/config/token_store.rb,
lib/calendar_assistant/cli/command_service.rb,
lib/calendar_assistant/cli/event_presenter.rb,
lib/calendar_assistant/predicate_collection.rb,
lib/calendar_assistant/lint_event_repository.rb,
lib/calendar_assistant/cli/event_set_presenter.rb,
lib/calendar_assistant/event_repository_factory.rb,
lib/calendar_assistant/location_config_validator.rb,
lib/calendar_assistant/location_event_repository.rb,
lib/calendar_assistant/cli/linter_event_presenter.rb,
lib/calendar_assistant/extensions/launchy_extensions.rb,
lib/calendar_assistant/cli/linter_event_set_presenter.rb
Overview
extend Launchy to handle zoom web URLs via the zoom commandline
executable.
note this doesn't handle "personal links" like
"https://robin.zoom.us/my/usernamehere"
which depends on an http 302 redirect from the zoom site
Defined Under Namespace
Modules: CLI, DateHelpers, HasDuration, PredicateCollection, StringHelpers
Classes: AvailableBlock, BaseException, Config, Event, EventRepository, EventRepositoryFactory, EventSet, LintEventRepository, LocalService, LocationConfigValidator, LocationEventRepository, Scheduler, ZoomLaunchy
Constant Summary
collapse
- VERSION =
"0.16.0"
- EMOJI_PLANE =
U+1F6EA NORTHEAST-POINTING AIRPLANE
"🛪"
- EMOJI_1_1 =
MAN AND WOMAN HOLDING HANDS
"👫"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config = Config.new, event_repository_factory: EventRepositoryFactory, service:) ⇒ CalendarAssistant
Returns a new instance of CalendarAssistant.
30
31
32
33
34
35
36
37
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 30
def initialize(config = Config.new,
event_repository_factory: EventRepositoryFactory,
service:) @config = config
@service = service
@calendar = service.get_calendar Config::DEFAULT_CALENDAR_ID
@event_repository_factory = event_repository_factory
@event_repositories = {} @event_predicates = PredicateCollection.build(config.must_be, config.must_not_be) end
|
Instance Attribute Details
#calendar ⇒ Object
Returns the value of attribute calendar.
8
9
10
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 8
def calendar
@calendar
end
|
#config ⇒ Object
Returns the value of attribute config.
8
9
10
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 8
def config
@config
end
|
#service ⇒ Object
Returns the value of attribute service.
8
9
10
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 8
def service
@service
end
|
Class Method Details
.date_range_cast(time_range) ⇒ Object
10
11
12
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 10
def self.date_range_cast(time_range)
time_range.first.to_date..(time_range.last + 1.day).to_date
end
|
.in_tz(time_zone, &block) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 14
def self.in_tz(time_zone, &block)
orig_time_tz = Time.zone
orig_env_tz = ENV["TZ"]
begin
unless time_zone.nil?
Time.zone = time_zone
ENV["TZ"] = time_zone
end
yield
ensure
Time.zone = orig_time_tz
ENV["TZ"] = orig_env_tz
end
end
|
Instance Method Details
#availability(time_range) ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 70
def availability(time_range)
calendar_ids = config.calendar_ids
ers = calendar_ids.map do |calendar_id|
event_repository calendar_id
end
Scheduler.new(self, ers).available_blocks(time_range, predicates: @event_predicates)
end
|
#create_location_events(time_range, location) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 82
def create_location_events(time_range, location)
LocationConfigValidator.valid?(config)
event_set = EventSet::Hash.new(event_repository, {})
unique_calendar_ids.each do |calendar_id|
event_set[calendar_id] = event_repository(calendar_id, type: :location).create(time_range, location, predicates: @event_predicates)
end
event_set
end
|
#event_repository(calendar_id = Config::DEFAULT_CALENDAR_ID, type: :base) ⇒ Object
94
95
96
97
98
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 94
def event_repository(calendar_id = Config::DEFAULT_CALENDAR_ID, type: :base)
@event_repositories[type] ||= {}
@event_repositories[type][calendar_id] ||=
@event_repository_factory.new_event_repository(@service, calendar_id, config: config, type: type)
end
|
#find_events(time_range) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 62
def find_events(time_range)
calendar_ids = config.calendar_ids
if calendar_ids.length > 1
raise BaseException, "CalendarAssistant#find_events only supports one person (for now)"
end
event_repository(calendar_ids.first).find(time_range, predicates: @event_predicates)
end
|
#find_location_events(time_range) ⇒ Object
78
79
80
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 78
def find_location_events(time_range)
event_repository(type: :location).find(time_range, predicates: @event_predicates)
end
|
#in_env(&block) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 39
def in_env(&block)
config.in_env do
in_tz do
yield
end
end
end
|
#in_tz(&block) ⇒ Object
48
49
50
51
52
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 48
def in_tz(&block)
CalendarAssistant.in_tz calendar.time_zone do
yield
end
end
|
#lint_events(time_range) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/calendar_assistant/calendar_assistant.rb', line 54
def lint_events(time_range)
calendar_ids = config.calendar_ids
if calendar_ids.length > 1
raise BaseException, "CalendarAssistant#lint_events only supports one person (for now)"
end
event_repository(calendar_ids.first, type: :lint).find(time_range, predicates: @event_predicates)
end
|