Created
February 10, 2011 03:48
-
-
Save maddox/819903 to your computer and use it in GitHub Desktop.
PugTime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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