From add1658274f654ea0a5354985af2540fcd37c696 Mon Sep 17 00:00:00 2001 From: Michael Anzuoni Date: Fri, 16 Sep 2011 14:43:28 -0400 Subject: [PATCH 1/2] Truncated RSS feeds and implemented reply-based invite email --- config/resque_schedule.yml | 6 +++++ lib/kick_off.rb | 4 +++ lib/reply_invite_job.rb | 10 +++++++ lib/rss_importer.rb | 14 +++++++++- mail/reply_based_invite.rb | 31 ++++++++++++++++++++++ mail/templates/reply_based_invite.mustache | 26 ++++++++++++++++++ mail/text/en.yml | 15 +++++++++++ 7 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 lib/reply_invite_job.rb create mode 100644 mail/reply_based_invite.rb create mode 100644 mail/templates/reply_based_invite.mustache diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index cafb48320..4d6e5e26a 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -12,3 +12,9 @@ import_feeds_rss: queue: rss_importer description: "Imports feed announcements from rss" +reply_based_email: + cron: "30 09 * * 1" + class: ReplyInviteJob + args: + queue: reply_based_invite + description: "Sends out invitation to the users if they receive replies to their posts." diff --git a/lib/kick_off.rb b/lib/kick_off.rb index 93ffcd0cf..a86cea632 100644 --- a/lib/kick_off.rb +++ b/lib/kick_off.rb @@ -149,6 +149,10 @@ def deliver_feed_owner_welcome(feed) enqueue(FeedWelcome, feed.id) end + def deliver_reply_based_invite(user_id) + Resque.enqueue(ReplyBasedInvite, user_id) + end + private def enqueue(*args) diff --git a/lib/reply_invite_job.rb b/lib/reply_invite_job.rb new file mode 100644 index 000000000..de8df7a4b --- /dev/null +++ b/lib/reply_invite_job.rb @@ -0,0 +1,10 @@ +class ReplyInviteJob + @queue = :reply_based_invite + + def self.perform + Reply.between(days_ago.days.ago, Time.now).where("repliable_type = ?",repliable_type).map {|reply| Reply.repliable.user_id } do |reply| + Resque.enqueue(ReplyBasedInvite, user_id) + end + end +end + diff --git a/lib/rss_importer.rb b/lib/rss_importer.rb index b78ddac65..2ba7b686b 100644 --- a/lib/rss_importer.rb +++ b/lib/rss_importer.rb @@ -7,6 +7,17 @@ def self.strip_feedflare(html) HTMLEntities.new.decode(html.gsub(/
(.*)<\/div>/m, "")) end + def self.truncate_feed(feed, source) + words = feed.split(/\s/) + word_limit = 148 + if words.size >= word_limit + ending = "...read more" + words[0,(word_limit-1)].join(' ') + ending + else + feed + end + end + def self.perform RSSAnnouncement.record_timestamps = false @@ -16,11 +27,12 @@ def self.perform unless RSSAnnouncement.exists?(:url => item.link) description = RSSImporter.strip_feedflare(item.description) + feedText = McBean.fragment(description).to_markdown RSSAnnouncement.create(:owner => feed, :subject => item.title, :url => item.link, :community_id => feed.community_id, - :body => McBean.fragment(description).to_markdown, + :body => RSSImporter.truncate_feed(feedText, feed.feed_url), :created_at => item.date.to_datetime, :updated_at => item.date.to_datetime) diff --git a/mail/reply_based_invite.rb b/mail/reply_based_invite.rb new file mode 100644 index 000000000..7ae81ecd7 --- /dev/null +++ b/mail/reply_based_invite.rb @@ -0,0 +1,31 @@ +class ReplyBasedInvite < MailBase + + def initialize(user_id) + @user = User.find(user_id) + end + + def subject + "The #{community_name} CommonPlace community helped you this past week. Give back by inviting neighbors to the network." + end + + def user + @user + end + + def short_user_name + user.first_name + end + + def community + @user.community + end + + def community_name + community.name + end + + def tag + 'reply_based_invite' + end + + diff --git a/mail/templates/reply_based_invite.mustache b/mail/templates/reply_based_invite.mustache new file mode 100644 index 000000000..ec1e116fd --- /dev/null +++ b/mail/templates/reply_based_invite.mustache @@ -0,0 +1,26 @@ + + + + + + + + {{< header}} + + + + + + + +
+ {{#t}}body{{/t}} + + {{#t}}thanks{{/t}} +
+ + diff --git a/mail/text/en.yml b/mail/text/en.yml index ec4fe915e..865e163d7 100644 --- a/mail/text/en.yml +++ b/mail/text/en.yml @@ -1,4 +1,19 @@ +reply_based_invite: + body: | +

Dear {{short_user_name}},

+ +

This past week, you received a reply to one of your CommonPlace neighborhood posts. We hope one of your neighbors was able to help you out!

+ +

If you were helped through {{community_name}}’s CommonPlace, we hope you can help give back to the network by inviting neighbors to CommonPlace. The more {community_name}} residents on CommonPlace, the better a tool CommonPlace is for community engagement.

+ +

+ +

Hope you can make CommonPlace an even better place to share and connect with your neighbors.

+ + thanks: | +

Thanks for being a great neighbor,
The {{community_name}} CommonPlace team

+ post_notification: intro: Hi {{user_name}},
{{poster_name}} just posted to your neighborhood board on CommonPlace. From da9db5b6d2fa154cbe9a4c0993283b1bd7c21aa5 Mon Sep 17 00:00:00 2001 From: Michael Anzuoni Date: Fri, 16 Sep 2011 14:48:55 -0400 Subject: [PATCH 2/2] Test for RSS truncation --- spec/lib/rss_importer_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/lib/rss_importer_spec.rb b/spec/lib/rss_importer_spec.rb index db2e0d826..dbbcea7be 100644 --- a/spec/lib/rss_importer_spec.rb +++ b/spec/lib/rss_importer_spec.rb @@ -17,4 +17,16 @@ RssImporter.strip_feedflare(html).should == html end end + + context "given a markdown feed and an RSS source link" do + it "should truncate the feed to 150 words and link to the source" do + source = "http://en.wikipedia.org/wiki/Robert_D._Putnam" + orig_feed = 'Roger Putnam graduated from Swarthmore College in 1963, won a Fulbright Fellowship to study at Balliol College, Oxford, and went on to earn master\'s and doctorate degrees from Yale University, the latter in 1970. He taught at the University of Michigan until going to Harvard in 1979, where he has held a variety of positions, including Dean of the Kennedy School, and is currently the Malkin Professor of Public Policy. Putnam was born as a religiously observant Methodist. Around the time of his marriage, he converted to Judaism, his wife\'s religion. His first work in the area of social capital was Making Democracy Work: Civic Traditions in Modern Italy, a comparative study of regional governments in Italy which drew great scholarly attention for its argument that the success of democracies depends in large part on the horizontal bonds that make up social capital.In 1995 he published "Bowling Alone: America\'s Declining Social Capital" in the Journal of Democracy. The article was widely read and garnered much attention for Putnam, including an invitation to meet with then-President Bill Clinton and a spot in the pages of People magazine. Some critics argued that Putnam was ignoring new organizations and forms of social capital; others argued that many of the included organizations were responsible for the suppression of civil rights movements and the reinforcement of anti-egalitarian social norms. Over the last decade and a half, the United States had seen an increase in bowlers but a decrease in bowling leagues.' + truncated = 'Roger Putnam graduated from Swarthmore College in 1963, won a Fulbright Fellowship to study at Balliol College, Oxford, and went on to earn master\'s and doctorate degrees from Yale University, the latter in 1970. He taught at the University of Michigan until going to Harvard in 1979, where he has held a variety of positions, including Dean of the Kennedy School, and is currently the Malkin Professor of Public Policy. Putnam was born as a religiously observant Methodist. Around the time of his marriage, he converted to Judaism, his wife\'s religion. His first work in the area of social capital was Making Democracy Work: Civic Traditions in Modern Italy, a comparative study of regional governments in Italy which drew great scholarly attention for its argument that the success of democracies depends in large part on the horizontal bonds that make up social capital.In 1995 he published "Bowling...read more' + + RSSImporter.truncate_feed(orig_feed, source).should == truncated + end + end + + end