Class: Sendle

Inherits:
Object
  • Object
show all
Defined in:
lib/sendle.rb,
lib/sendle/version.rb

Constant Summary collapse

VERSION =
'0.1.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(password) ⇒ Sendle

Returns a new instance of Sendle.



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

def initialize(password)
  @password = password
  @sha1_checksums_hash = {}
  @last_event = Time.now

  configure_listener
end

Instance Attribute Details

#last_eventObject (readonly)

Returns the value of attribute last_event.



6
7
8
# File 'lib/sendle.rb', line 6

def last_event
  @last_event
end

#listenerObject (readonly)

Returns the value of attribute listener.



6
7
8
# File 'lib/sendle.rb', line 6

def listener
  @listener
end

#sha1_checksums_hashObject (readonly)

Returns the value of attribute sha1_checksums_hash.



6
7
8
# File 'lib/sendle.rb', line 6

def sha1_checksums_hash
  @sha1_checksums_hash
end

Instance Method Details

#file_added(file) ⇒ Object



26
27
28
29
# File 'lib/sendle.rb', line 26

def file_added(file)
  puts "file changed: #{file}, sending now..."
  send_to_kindle(file[0]) unless file.nil? || file.empty?
end

#send_to_kindle(file) ⇒ Object



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

def send_to_kindle(file)
  @config ||= YAML::load(File.open("#{ENV['HOME']}/.sendle"))
  gmail       = Gmail.connect(@config["gmail"]["username"], @password)
  message     = gmail.message
  message.to  = @config["kindle"]["email"]
  message.add_file file
  message.deliver
  puts "an email with #{file} is flying on the interwebz!"
end