Skip to content
Browse files

Recreated RSS feed

  • Loading branch information...
1 parent 967b34d commit f63ffcd27d54210250e405db48732a82a15c22f4 @konklone konklone committed Mar 24, 2010
Showing with 33 additions and 3 deletions.
  1. +14 −3 ohnomymoney.rb
  2. +19 −0 views/worth.erb
View
17 ohnomymoney.rb
@@ -36,13 +36,20 @@
:account => account,
:oldest => account.balances.first(:order => "created_at ASC"),
:newest => account.balances.first(:order => "created_at DESC"),
- :balances => account.balances.all(:limit => 180)
+ :balances => account.balances.all(:limit => 180, :order => "created_at DESC")
}
end
get "/:handle/worth.xml" do
- headers['Content-Type'] = 'application/rss+xml'
- "<?xml><xml/>"
+ halt 404 unless user = User.find_by_handle(params[:handle])
+ halt 404 unless account = user.accounts.worth.first
+
+ response['Content-Type'] = 'application/rss+xml'
+ erb :worth, :locals => {
+ :user => user,
+ :account => account,
+ :balances => account.balances.all(:limit => 10, :order => "created_at DESC")
+ }
end
helpers do
@@ -67,4 +74,8 @@ def format_amount(amount)
answer
end
+ def midnight_stamp(date)
+ date.strftime "%a, %d %b %Y 00:00:00 EST"
+ end
+
end
View
19 views/worth.erb
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
+ <channel>
+ <title>Oh No My Money: <%= user.name %></title>
+ <link>http://ohnomymoney.com/<%= user.handle %></link>
+ <language>en-us</language>
+ <description><%= user.name %>'s money.</description>
+ <atom:link href="http://ohnomymoney.com/<%= user.handle %>/worth.xml" rel="self" type="application/rss+xml"></atom:link>
+ <% balances.each_with_index do |balance, i| %>
+ <item>
+ <title><%= user.name %>'s <%= account.name %>: <%= format_amount balance.amount %></title>
+ <description><%= format_amount balance.amount %></description>
+ <link>http://ohnomymoney.com#<%= i + 1 %></link>
+ <guid>http://ohnomymoney.com#<%= i + 1 %></guid>
+ <pubDate><%= midnight_stamp balance.date_of %></pubDate>
+ </item>
+ <% end %>
+ </channel>
+</rss>

0 comments on commit f63ffcd

Please sign in to comment.
Something went wrong with that request. Please try again.