Class: GmailToDo

Inherits:
Object
  • Object
show all
Defined in:
lib/gmail_todo.rb

Constant Summary collapse

LOCAL_CREDENTIALS =
ENV['HOME'] + '/.gmail_todo/credentials.yml'
DEFAULT_CREDENTIALS =
File.dirname(__FILE__) + '/credentials.yml'

Instance Method Summary collapse

Constructor Details

#initializeGmailToDo

Returns a new instance of GmailToDo.



8
9
10
11
12
13
# File 'lib/gmail_todo.rb', line 8

def initialize
  file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS
  credentials = YAML.load(File.read(file))
  @username = credentials["gmail"]["username"]
  @password = credentials["gmail"]["password"]
end

Instance Method Details

#send_todo(todo) ⇒ Object



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

def send_todo todo
  gmail = Gmail.connect(@username, @password)

  gmail.deliver do
    to "#{@username}@gmail.com"
    subject "[ToDo] #{todo}"
  end

  gmail.logout
end