Improved channel fetchable function.
This commit is contained in:
parent
a5ecee76c6
commit
40afe824f3
4 changed files with 39 additions and 16 deletions
|
@ -37,7 +37,7 @@ fetch one account
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def fetch
|
def fetch(force = false)
|
||||||
|
|
||||||
adapter = options[:adapter]
|
adapter = options[:adapter]
|
||||||
adapter_options = options
|
adapter_options = options
|
||||||
|
@ -56,6 +56,7 @@ fetch one account
|
||||||
|
|
||||||
driver_class = Object.const_get("Channel::Driver::#{adapter.to_classname}")
|
driver_class = Object.const_get("Channel::Driver::#{adapter.to_classname}")
|
||||||
driver_instance = driver_class.new
|
driver_instance = driver_class.new
|
||||||
|
return if !force && !driver_instance.fetchable?(self)
|
||||||
result = driver_instance.fetch(adapter_options, self)
|
result = driver_instance.fetch(adapter_options, self)
|
||||||
self.status_in = result[:result]
|
self.status_in = result[:result]
|
||||||
self.last_log_in = result[:notice]
|
self.last_log_in = result[:notice]
|
||||||
|
|
|
@ -4,6 +4,10 @@ require 'net/imap'
|
||||||
|
|
||||||
class Channel::Driver::Imap < Channel::EmailParser
|
class Channel::Driver::Imap < Channel::EmailParser
|
||||||
|
|
||||||
|
def fetchable?(_channel)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
fetch emails from IMAP account
|
fetch emails from IMAP account
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Channel::Driver::Pop3 < Channel::EmailParser
|
||||||
|
|
||||||
fetch emails from Pop3 account
|
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)
|
result = instance.fetch(params[:inbound][:options], channel, 'verify', subject_looking_for)
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
@ -21,7 +21,7 @@ returns
|
||||||
|
|
||||||
check if connect to Pop3 account is possible, return count of mails in mailbox
|
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')
|
result = instance.fetch(params[:inbound][:options], channel, 'check')
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
@ -33,7 +33,7 @@ returns
|
||||||
|
|
||||||
verify Pop3 account, check if search email is in there
|
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)
|
result = instance.fetch(params[:inbound][:options], channel, 'verify', subject_looking_for)
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
@ -162,6 +162,17 @@ returns
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
|
instance = Channel::Driver::Pop3.new
|
||||||
|
instance.fetchable?(channel)
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def fetchable?(_channel)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def disconnect
|
def disconnect
|
||||||
return if !@pop
|
return if !@pop
|
||||||
@pop.finish
|
@pop.finish
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
|
||||||
|
|
||||||
|
class Channel::Driver::Twitter
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
fetch tweets from twitter account
|
fetch tweets from twitter account
|
||||||
|
@ -43,22 +45,10 @@ returns
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
class Channel::Driver::Twitter
|
|
||||||
|
|
||||||
def fetch (options, channel)
|
def fetch (options, channel)
|
||||||
|
|
||||||
options = check_external_credential(options)
|
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])
|
@rest_client = TweetRest.new(options[:auth])
|
||||||
@sync = options[:sync]
|
@sync = options[:sync]
|
||||||
@channel = channel
|
@channel = channel
|
||||||
|
@ -79,6 +69,23 @@ class Channel::Driver::Twitter
|
||||||
}
|
}
|
||||||
end
|
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
|
=begin
|
||||||
|
|
||||||
instance = Channel::Driver::Twitter.new
|
instance = Channel::Driver::Twitter.new
|
||||||
|
|
Loading…
Reference in a new issue