Skip to content

Instantly share code, notes, and snippets.

@maddox
Created February 10, 2011 03:48
Show Gist options
  • Save maddox/819903 to your computer and use it in GitHub Desktop.
Save maddox/819903 to your computer and use it in GitHub Desktop.
PugTime
require 'rubygems'
require 'httparty'
class PugTime
include HTTParty
base_uri "http://pugtime.tumblr.com/rss"
def self.random_pug
pugs = get_pugs
pugs[rand(pugs.size)]
end
def self.get_pugs
response = get('')
return [] unless response.code == 200
response.parsed_response['rss']['channel']['item'].collect{|i| i['description'].match(/http.*(jpg|gif|png)/)}
end
end
# PugTime.get_pugs => ["http://25.media.tumblr.com/tumblr_lfuc2pjBIC1qeiw6ro1_500.jpg", ...]
# PugTime.random_pug => "http://25.media.tumblr.com/tumblr_lfuc2pjBIC1qeiw6ro1_500.jpg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment