Permalink
Browse files

cleaned up XKCD#comic

  • Loading branch information...
1 parent 72d39dd commit e482a5dffa8dd9e5af326d453edad0e06afb0090 Fraser Murray committed May 20, 2012
Showing with 3 additions and 10 deletions.
  1. +3 −10 lib/xkcd.rb
View
13 lib/xkcd.rb
@@ -13,20 +13,13 @@ class XKCD
# => "http://xkcd.com/891/"
def self.comic()
- # This method gets random comic links from xkcd, the uri is the redirected location found in the resp headers
- uri = URI.parse 'http://dynamic.xkcd.com/random/comic/'
- req = Net::HTTP::Get.new(uri.request_uri)
- http = Net::HTTP.new(uri.host)
- res = http.start { |server|
- server.request(req)
- }
- res["location"]
+ open('http://dynamic.xkcd.com/random/comic/').base_uri.to_s
end
def self.img
url = 'http://dynamic.xkcd.com/random/comic/'
html = open(url).read()
- imgs = URI.extract(html).select{ |l| l[/comics\//]}
- imgs.first
+ imgs = URI.extract(html).select{ |l| l[/comics\//]}
+ imgs.first
end
end

0 comments on commit e482a5d

Please sign in to comment.