facebook.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2015 Zammad Foundation, http://zammad-foundation.org/
  2. require 'facebook'
  3. class Channel::Driver::Facebook
  4. def fetch (_adapter_options, channel)
  5. @channel = channel
  6. @facebook = Facebook.new( @channel[:options] )
  7. @sync = @channel[:options][:sync]
  8. Rails.logger.debug 'facebook fetch started'
  9. fetch_feed
  10. disconnect
  11. Rails.logger.debug 'facebook fetch completed'
  12. end
  13. def send(article, _notification = false)
  14. @channel = Channel.find_by( area: 'Facebook::Inbound', active: true )
  15. @facebook = Facebook.new( @channel[:options] )
  16. tweet = @facebook.from_article(article)
  17. disconnect
  18. tweet
  19. end
  20. def disconnect
  21. @facebook.disconnect
  22. end
  23. private
  24. def fetch_feed
  25. return if !@sync[:group_id]
  26. counter = 0
  27. feed = @facebook.client.get_connections('me', 'feed')
  28. feed.each { |f|
  29. break if @sync[:limit] && @sync[:limit] <= counter
  30. post = @facebook.client.get_object( f['id'] )
  31. @facebook.to_group( post, @sync[:group_id] )
  32. counter += 1
  33. }
  34. end
  35. end