2015-07-09 14:56:01 +00:00
|
|
|
# Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
|
2013-06-12 15:59:58 +00:00
|
|
|
|
2015-07-09 14:56:01 +00:00
|
|
|
require 'facebook'
|
2012-04-10 14:06:46 +00:00
|
|
|
|
2015-08-28 00:53:14 +00:00
|
|
|
class Channel::Driver::Facebook
|
2012-04-10 14:06:46 +00:00
|
|
|
|
2015-08-28 01:02:21 +00:00
|
|
|
def fetch (_adapter_options, channel)
|
2015-07-09 14:56:01 +00:00
|
|
|
|
|
|
|
@channel = channel
|
2015-07-17 14:57:10 +00:00
|
|
|
@facebook = Facebook.new( @channel[:options] )
|
2015-07-09 14:56:01 +00:00
|
|
|
@sync = @channel[:options][:sync]
|
|
|
|
|
|
|
|
Rails.logger.debug 'facebook fetch started'
|
|
|
|
|
|
|
|
fetch_feed
|
|
|
|
|
|
|
|
disconnect
|
|
|
|
|
|
|
|
Rails.logger.debug 'facebook fetch completed'
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
2014-06-22 07:00:09 +00:00
|
|
|
|
2015-07-09 14:56:01 +00:00
|
|
|
def send(article, _notification = false)
|
|
|
|
|
|
|
|
@channel = Channel.find_by( area: 'Facebook::Inbound', active: true )
|
2015-07-17 14:57:10 +00:00
|
|
|
@facebook = Facebook.new( @channel[:options] )
|
2015-07-09 14:56:01 +00:00
|
|
|
|
2015-12-18 10:47:05 +00:00
|
|
|
post = @facebook.from_article(article)
|
2015-07-09 14:56:01 +00:00
|
|
|
disconnect
|
|
|
|
|
2015-12-18 10:47:05 +00:00
|
|
|
post
|
2015-07-09 14:56:01 +00:00
|
|
|
end
|
2014-06-22 07:00:09 +00:00
|
|
|
|
2015-07-09 14:56:01 +00:00
|
|
|
def disconnect
|
|
|
|
@facebook.disconnect
|
2014-06-22 07:00:09 +00:00
|
|
|
end
|
|
|
|
|
2015-07-09 14:56:01 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def fetch_feed
|
|
|
|
|
|
|
|
return if !@sync[:group_id]
|
|
|
|
|
|
|
|
counter = 0
|
|
|
|
feed = @facebook.client.get_connections('me', 'feed')
|
2015-12-18 10:47:05 +00:00
|
|
|
feed.each { |feed_item|
|
2015-07-09 14:56:01 +00:00
|
|
|
|
|
|
|
break if @sync[:limit] && @sync[:limit] <= counter
|
|
|
|
|
2015-12-18 10:47:05 +00:00
|
|
|
post = @facebook.client.get_object( feed_item['id'] )
|
2015-07-09 14:56:01 +00:00
|
|
|
|
|
|
|
@facebook.to_group( post, @sync[:group_id] )
|
|
|
|
|
|
|
|
counter += 1
|
|
|
|
}
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
2013-06-12 15:59:58 +00:00
|
|
|
end
|