Module: RememberTheMeeting

Extended by:
Platform
Defined in:
lib/remember_the_meeting.rb,
lib/remember_the_meeting/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Methods included from Platform

linux?

Class Method Details

.configObject



43
44
45
# File 'lib/remember_the_meeting.rb', line 43

def config
  YAML.load(File.read(config_filepath))
end

.config_filepathObject



47
48
49
# File 'lib/remember_the_meeting.rb', line 47

def config_filepath
  File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'exchange.yml'))
end

.configureObject



34
35
36
# File 'lib/remember_the_meeting.rb', line 34

def configure
  system "#{editor} #{config_filepath}"
end

.editorObject



38
39
40
41
# File 'lib/remember_the_meeting.rb', line 38

def editor
  editor = `echo $EDITOR`.chomp
  editor.blank? ? 'vim' : editor
end

.enable!Object



73
74
75
76
# File 'lib/remember_the_meeting.rb', line 73

def enable!
  setup
  start
end

.notify(subject, start_time, end_time, location) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/remember_the_meeting.rb', line 17

def notify(subject, start_time, end_time, location)
  message = "#{start_time}-#{end_time}\n#{location}"
  if linux?
    system "notify-send \"#{subject}\" \"#{message}\""
  else
    Growl.notify(message, {:title => subject, :sticky => true})
  end
end

.setupObject



26
27
28
29
30
31
32
# File 'lib/remember_the_meeting.rb', line 26

def setup
  password = ask("Enter password: ") { |q| q.echo = false }
  Viewpoint::EWS::EWS.endpoint = config['server']
  Viewpoint::EWS::EWS.set_auth(config['user'], password)
  @cal = Viewpoint::EWS::CalendarFolder.get_folder :calendar
  @cal.subscribe
end

.startObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/remember_the_meeting.rb', line 51

def start
  loop do
    items = @cal.todays_items
    
    # d1 = DateTime.parse('2011-09-24')
    # d2 = DateTime.parse('2011-09-30')
    # items = @cal.items_between(d1, d2)
    
    now = Time.now
    in_15_minutes = Time.now + 60 * 15
    upcoming = items.select {|item| item.start_time > now && item.start_time < in_15_minutes }
    upcoming.each do |appointment|
      start_time = appointment.start_time_formatted
      end_time   = appointment.end_time_formatted
      subject    = appointment.subject
      location   = appointment.location
      notify(subject, start_time, end_time, location)
    end
    sleep(300)
  end
end