Class: Nora::Core

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/nora/core.rb

Constant Summary collapse

PAIRINGS_FILE =
"past_pairings.txt".freeze
PAIRINGS_FILE_SEPARATOR =
" ".freeze
OOB_URI =
"urn:ietf:wg:oauth:2.0:oob".freeze
CLIENT_SECRETS_PATH =
"nora_client_secret.json".freeze
CREDENTIALS_PATH =
"calendar-ruby-quickstart.yaml".freeze
SCOPE =
Google::Apis::CalendarV3::AUTH_CALENDAR
FREE_BUSY_QUERY_BATCH_SIZE =
5
CONFIGURATION =
JSON.parse(File.read("nora_configuration.json"))

Instance Method Summary collapse

Constructor Details

#initialize(weeks_ahead:, test:) ⇒ Core

Returns a new instance of Core.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/nora/core.rb', line 46

def initialize(weeks_ahead:, test:)
  puts

  @weeks_ahead = weeks_ahead
  @test = test

  FileUtils.touch(PAIRINGS_FILE) # Make sure pairings file exists.

  # Set global Chronic parsing time zone.
  Time.zone = "UTC"
  Chronic.time_class = Time.zone

  # Initialize the API
  @service = Google::Apis::CalendarV3::CalendarService.new
  @service.client_options.application_name =
    CONFIGURATION["calendar"]["application_name"]
  @service.authorization = authorize
end

Instance Method Details

#run!Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/nora/core.rb', line 65

def run!
  begin
    load_history!
    puts "Creating groups..."
    create_groups!
  rescue SystemStackError
    remove_oldest_pair!

    retry
  end

  send_emails(
    template_emails_for(
      schedule_meetings!
    )
  )

  puts "Done."
end