Improved channel fetchable function.

This commit is contained in:
Martin Edenhofer 2016-01-10 14:24:54 +01:00
parent a5ecee76c6
commit 40afe824f3
4 changed files with 39 additions and 16 deletions

View file

@ -37,7 +37,7 @@ fetch one account
=end
def fetch
def fetch(force = false)
adapter = options[:adapter]
adapter_options = options
@ -56,6 +56,7 @@ fetch one account
driver_class = Object.const_get("Channel::Driver::#{adapter.to_classname}")
driver_instance = driver_class.new
return if !force && !driver_instance.fetchable?(self)
result = driver_instance.fetch(adapter_options, self)
self.status_in = result[:result]
self.last_log_in = result[:notice]

View file

@ -4,6 +4,10 @@ require 'net/imap'
class Channel::Driver::Imap < Channel::EmailParser
def fetchable?(_channel)
true
end
=begin
fetch emails from IMAP account

View file

@ -8,7 +8,7 @@ class Channel::Driver::Pop3 < Channel::EmailParser
fetch emails from Pop3 account
instance = Channel::Driver::Imap.new
instance = Channel::Driver::Pop3.new
result = instance.fetch(params[:inbound][:options], channel, 'verify', subject_looking_for)
returns
@ -21,7 +21,7 @@ returns
check if connect to Pop3 account is possible, return count of mails in mailbox
instance = Channel::Driver::Imap.new
instance = Channel::Driver::Pop3.new
result = instance.fetch(params[:inbound][:options], channel, 'check')
returns
@ -33,7 +33,7 @@ returns
verify Pop3 account, check if search email is in there
instance = Channel::Driver::Imap.new
instance = Channel::Driver::Pop3.new
result = instance.fetch(params[:inbound][:options], channel, 'verify', subject_looking_for)
returns
@ -162,6 +162,17 @@ returns
}
end
=begin
instance = Channel::Driver::Pop3.new
instance.fetchable?(channel)
=end
def fetchable?(_channel)
true
end
def disconnect
return if !@pop
@pop.finish

View file

@ -1,5 +1,7 @@
# Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
class Channel::Driver::Twitter
=begin
fetch tweets from twitter account
@ -43,22 +45,10 @@ returns
=end
class Channel::Driver::Twitter
def fetch (options, channel)
options = check_external_credential(options)
# only fetch once a hour
if Rails.env.production? || Rails.env.development?
if channel.preferences && channel.preferences[:last_fetch] && channel.preferences[:last_fetch] > Time.zone.now - 1.hour
return {
result: 'ok',
notice: '',
}
end
end
@rest_client = TweetRest.new(options[:auth])
@sync = options[:sync]
@channel = channel
@ -79,6 +69,23 @@ class Channel::Driver::Twitter
}
end
=begin
instance = Channel::Driver::Twitter.new
instance.fetchable?(channel)
=end
def fetchable?(channel)
return true if Rails.env.test?
# only fetch once a hour
return true if !channel.preferences
return true if !channel.preferences[:last_fetch]
return false if channel.preferences[:last_fetch] > Time.zone.now - 1.hour
true
end
=begin
instance = Channel::Driver::Twitter.new