Created
February 8, 2013 17:39
-
-
Save pavana21/4740635 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FacebookPageFeedsJob | |
@queue = :page_feeds | |
class << self | |
def perform | |
puts "Am in perform" | |
Account.customers.each do |account| | |
social_profile = account.social_profile | |
puts "Am in Facebook" | |
if social_profile && social_profile.facebook.present? | |
facebook = social_profile.facebook | |
page_id = facebook.page_id | |
if facebook.social_feeds && facebook.social_feeds.length > 0 | |
start_time = facebook.social_feeds.last.updated_time.to_time.to_i | |
puts "Start Time: #{start_time} " | |
list_pages(page_id, start_time, account, facebook) | |
else | |
puts "Start Time Count: 0" | |
list_pages(page_id, (DateTime.now - 6.months).to_time.to_i, account, facebook) | |
end | |
end | |
end | |
end | |
def list_pages(page_id, start_time, account, facebook) | |
pages = FacebookApi.page_feeds(page_id, start_time, account).sort_by {|_key, value| value}.reverse | |
if pages && pages.length > 0 | |
pages.each do |feed| | |
user_picture = FacebookApi.profile_picture(feed["from"]["id"], account) | |
attributes = {message: feed["message"], photo: feed["picture"], link: feed["link"], | |
created_time: feed["created_time"], updated_time: feed["updated_time"], | |
user_name: feed["from"]["name"], user_picture: user_picture, | |
feed_id: feed["id"]} | |
facebook.social_feeds.create(attributes) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment