xkcd 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/xkcd.rb +9 -15
  2. metadata +3 -3
@@ -1,5 +1,5 @@
1
- #!/usr/bin/evn ruby
2
- require 'net/http'
1
+ #!/usr/bin/env ruby
2
+ require 'hpricot'
3
3
  require 'open-uri'
4
4
  # The main XKCD driver
5
5
  class XKCD
@@ -12,21 +12,15 @@ class XKCD
12
12
  # >> XKCD.comic
13
13
  # => "http://xkcd.com/891/"
14
14
 
15
- def self.comic()
16
- # This method gets random comic links from xkcd, the uri is the redirected location found in the resp headers
17
- uri = URI.parse 'http://dynamic.xkcd.com/random/comic/'
18
- req = Net::HTTP::Get.new(uri.request_uri)
19
- http = Net::HTTP.new(uri.host)
20
- res = http.start { |server|
21
- server.request(req)
22
- }
23
- res["location"]
15
+ def self.comic
16
+ open('http://dynamic.xkcd.com/random/comic/').base_uri.to_s
24
17
  end
25
18
 
19
+ class << XKCD
20
+ alias_method :get, :comic
21
+ end
22
+
26
23
  def self.img
27
- url = 'http://dynamic.xkcd.com/random/comic/'
28
- html = open(url).read()
29
- imgs = URI.extract(html).select{ |l| l[/comics\//]}
30
- imgs.first
24
+ Hpricot(open('http://dynamic.xkcd.com/random/comic/')).search("#comic img").first.raw_attributes["src"]
31
25
  end
32
26
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xkcd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hemanth.HM