Permalink
Browse files

Fix for tweeting moderator items

  • Loading branch information...
1 parent 46c69d5 commit fbd98d9806101c5bfa6cdcbd7f4723285ec68005 @adahmash adahmash committed Apr 2, 2012
Showing with 36 additions and 1 deletion.
  1. +6 −1 app/models/user.rb
  2. +5 −0 app/workers/twitter_scheduled_worker.rb
  3. +9 −0 lib/acts_as_tweetable.rb
  4. +16 −0 lib/tweeter.rb
View
7 app/models/user.rb
@@ -392,7 +392,12 @@ def get_prediction_score
def mogli_user
return nil unless authentications.for_facebook.any?
- @mogli_user ||= Mogli::User.find("me", mogli_client)
+ begin
+ @mogli_user ||= Mogli::User.find("me", mogli_client)
+ return @mogli_user
+ rescue Exception => e
+ return nil
+ end
end
def mogli_friends
View
5 app/workers/twitter_scheduled_worker.rb
@@ -7,6 +7,11 @@ def self.perform
rescue Newscloud::TweeterDisabled => e
Rails.logger.info("ERROR:: TwitterScheduledWorker failed with: #{e.inspect}")
end
+ begin
+ Newscloud::Tweeter.new.tweet_moderator_items
+ rescue Newscloud::TweeterDisabled => e
+ Rails.logger.info("ERROR:: TwitterScheduledWorker failed with: #{e.inspect}")
+ end
end
end
View
9 lib/acts_as_tweetable.rb
@@ -45,6 +45,15 @@ def hot_items
end
end
+ def moderator_items
+ begin
+ self.find(:all, :include => [:user, :tweeted_item], :conditions => ["users.is_moderator =? AND tweeted_items.item_id IS NULL", true])
+ rescue Exception => e
+ Rails.logger.error("ERROR: Tweet Moderator Items error:: #{e}")
+ return false
+ end
+ end
+
def tweet_setting_group
self.table_name
end
View
16 lib/tweeter.rb
@@ -167,6 +167,22 @@ def tweet_hot_items
end
end
+ def tweet_moderator_items
+ enabled = Metadata::Setting.find_setting('tweet_all_moderator_items').try(:value)
+ raise Newscloud::TweeterDisabled.new("You must enable the setting 'tweet_all_moderator_items' to use Tweeter.") unless enabled
+ klasses = Dir.glob("#{Rails.root}/app/models/*.rb").map {|f| f.sub(%r{^.*/(.*?).rb$}, '\1').pluralize.classify }.map {|s| s == "Metadatum" ? "Metadata" : s}.map(&:constantize).select {|m| m.respond_to?(:tweetable?) and m.tweetable? }
+ puts "tweeting moderator items"
+ klasses.each do |klass|
+ begin
+ moderator_items = klass.moderator_items
+ next unless moderator_items
+ tweet_items moderator_items
+ rescue Exception => e
+ Rails.logger.error("ERROR TWEETING MODERATOR ITEMS: #{e}")
+ end
+ end
+ end
+
def self.shorten_url(url)
@bitly_username = Metadata::Setting.find_setting('bitly_username').try(:value)
@bitly_api_key = Metadata::Setting.find_setting('bitly_api_key').try(:value)

0 comments on commit fbd98d9

Please sign in to comment.