Class: FatFreeCRM::Dropbox
- Inherits:
-
Object
- Object
- FatFreeCRM::Dropbox
- Defined in:
- lib/fat_free_crm/dropbox.rb
Constant Summary collapse
- KEYWORDS =
%w(account campaign contact lead opportunity).freeze
Instance Method Summary collapse
-
#initialize ⇒ Dropbox
constructor
————————————————————————————–.
-
#run ⇒ Object
————————————————————————————–.
-
#setup ⇒ Object
Setup imap folders in settings.
Constructor Details
#initialize ⇒ Dropbox
26 27 28 29 30 31 32 33 34 |
# File 'lib/fat_free_crm/dropbox.rb', line 26 def initialize # Models are autoloaded, so the following @@assets class variable should only be set # when Dropbox is initialized. This needs to be done so that Rake tasks such as # 'assets:precompile' can run on Heroku without depending on a database. # See: http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting @@assets = [ Account, Contact, Lead ].freeze @settings = Setting.email_dropbox.dup @archived, @discarded = 0, 0 end |
Instance Method Details
#run ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fat_free_crm/dropbox.rb', line 37 def run log "connecting to #{@settings[:server]}..." connect! or return nil log "logged in to #{@settings[:server]}..." with_new_emails do |uid, email| process(uid, email) archive(uid) end ensure log "messages processed: #{@archived + @discarded}, archived: #{@archived}, discarded: #{@discarded}." disconnect! end |
#setup ⇒ Object
Setup imap folders in settings.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fat_free_crm/dropbox.rb', line 52 def setup log "connecting to #{@settings[:server]}..." connect!(:setup => true) or return nil log "logged in to #{@settings[:server]}, checking folders..." folders = [ @settings[:scan_folder] ] folders << @settings[:move_to_folder] unless @settings[:move_to_folder].blank? folders << @settings[:move_invalid_to_folder] unless @settings[:move_invalid_to_folder].blank? # Open (or create) destination folder in read-write mode. folders.each do |folder| if @imap.list("", folder) log "folder #{folder} OK" else log "folder #{folder} missing, creating..." @imap.create(folder) end end rescue => e $stderr.puts "setup error #{e.inspect}" ensure disconnect! end |