2014-02-03 19:23:00 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2012-09-20 12:08:02 +00:00
|
|
|
class Channel < ApplicationModel
|
2012-04-13 13:51:10 +00:00
|
|
|
store :options
|
|
|
|
|
2012-04-10 14:06:46 +00:00
|
|
|
def self.fetch
|
2012-04-13 13:51:10 +00:00
|
|
|
channels = Channel.where( 'active = ? AND area LIKE ?', true, '%::Inbound' )
|
|
|
|
channels.each { |channel|
|
2012-04-10 14:06:46 +00:00
|
|
|
begin
|
2015-07-02 14:54:05 +00:00
|
|
|
# we need to require each channel backend individually otherwise we get a
|
|
|
|
# 'warning: toplevel constant Twitter referenced by Channel::Twitter' error e.g.
|
|
|
|
# so we have to convert the channel name to the filename via Rails String.underscore
|
|
|
|
# http://stem.ps/rails/2015/01/25/ruby-gotcha-toplevel-constant-referenced-by.html
|
|
|
|
require "channel/#{channel[:adapter].underscore}"
|
|
|
|
|
|
|
|
channel_object = Object.const_get("Channel::#{channel[:adapter]}")
|
|
|
|
channel_instance = channel_object.new
|
|
|
|
channel_instance.fetch(channel)
|
2015-05-08 14:09:24 +00:00
|
|
|
rescue => e
|
2015-07-02 14:54:05 +00:00
|
|
|
logger.error "Can't use Channel::#{channel[:adapter]}"
|
2015-05-04 18:58:28 +00:00
|
|
|
logger.error e.inspect
|
|
|
|
logger.error e.backtrace
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|