Sha256: 50c116bea9e8848df249e68e41d2b815b90fdb739b5798bb061afe3c3bfe819e
Contents?: true
Size: 671 Bytes
Versions: 1
Compression:
Stored size: 671 Bytes
Contents
#!/usr/bin/evn ruby require 'net/http' require 'open-uri' class XKCD 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"] 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
xkcd-0.0.2 | lib/xkcd.rb |