Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncated RSS feeds and implemented the reply-based invite email (with a template) #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/resque_schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
4 changes: 4 additions & 0 deletions lib/kick_off.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions lib/reply_invite_job.rb
Original file line number Diff line number Diff line change
@@ -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

14 changes: 13 additions & 1 deletion lib/rss_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ def self.strip_feedflare(html)
HTMLEntities.new.decode(html.gsub(/<div class=\"feedflare\">(.*)<\/div>/m, ""))
end

def self.truncate_feed(feed, source)
words = feed.split(/\s/)
word_limit = 148
if words.size >= word_limit
ending = "<a href=\"" + source + "\">...read more</a>"
words[0,(word_limit-1)].join(' ') + ending
else
feed
end
end

def self.perform
RSSAnnouncement.record_timestamps = false

Expand All @@ -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)

Expand Down
31 changes: 31 additions & 0 deletions mail/reply_based_invite.rb
Original file line number Diff line number Diff line change
@@ -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


26 changes: 26 additions & 0 deletions mail/templates/reply_based_invite.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
<head>
<style>
{{styles}}
</style>
</head>
<body>

<table id="body">
{{< header}}
<tr>
<td>
{{#t}}body{{/t}}
</td>
<td>
{{#t}}thanks{{/t}}
</td>
</tr>
<tr>
<td id="footer">
{{< legal }}
</td>
</tr>
</table>
</body>
</html>
15 changes: 15 additions & 0 deletions mail/text/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
reply_based_invite:
body: |
<p>Dear {{short_user_name}},</p>

<p>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!</p>

<p>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.</p>

<p><a href="http://www.ourcommonplace.com/account/facebook_invite"><img src="images/mail/invite-them-now.png""></a></p>


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

thanks: |
<p>Thanks for being a great neighbor,<br>The {{community_name}} CommonPlace team</p>

post_notification:
intro: Hi {{user_name}}, <br> {{poster_name}} just posted to your neighborhood board on CommonPlace.

Expand Down
12 changes: 12 additions & 0 deletions spec/lib/rss_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<a href="http://en.wikipedia.org/wiki/Robert_D._Putnam">...read more</a>'

RSSImporter.truncate_feed(orig_feed, source).should == truncated
end
end


end