1
0
Fork 0
forked from wezm/wezm.net
wezm.net/lib/articles.rb

43 lines
957 B
Ruby
Raw Normal View History

require 'bitly'
module WezM
module Helpers
module Articles
def personal_articles
sorted_articles.select { |a| a.identifier =~ %r{^/personal/} }
end
def technical_articles
sorted_articles.select { |a| a.identifier =~ %r{^/technical/} }
end
def article_to_json(article)
{
:title => article[:title],
:path => article.identifier,
:date => Time.parse(article[:created_at]).rfc2822,
:text => article[:title],
2010-03-29 21:05:41 +00:00
:extra => article[:extra] || " "
}
end
def short_url(url)
begin
@bitly ||= Bitly.new('wezm', 'R_f2bfdace56c886671086eb0c8acb9ce7')
@cache ||= {}
unless u = @cache[url]
u = @bitly.shorten(url)
else
puts "Cache hit on #{url}"
end
u.short_url
rescue BitlyError
nil
end
end
end
end
end