xkcd 0.0.7 → 0.0.8
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.
- data/bin/xkcd +2 -2
- data/lib/xkcd.rb +15 -23
- metadata +40 -35
data/bin/xkcd
CHANGED
data/lib/xkcd.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#!/usr/bin/
|
2
|
-
require '
|
1
|
+
#!/usr/bin/evn ruby
|
2
|
+
require 'net/http'
|
3
3
|
require 'open-uri'
|
4
|
-
require 'json'
|
5
|
-
|
6
4
|
# The main XKCD driver
|
7
5
|
class XKCD
|
8
6
|
# Get img/comic URL from xkcd
|
@@ -14,27 +12,21 @@ class XKCD
|
|
14
12
|
# >> XKCD.comic
|
15
13
|
# => "http://xkcd.com/891/"
|
16
14
|
|
17
|
-
def self.comic
|
18
|
-
|
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"]
|
19
24
|
end
|
20
25
|
|
21
|
-
class << XKCD
|
22
|
-
alias_method :get, :comic
|
23
|
-
end
|
24
|
-
|
25
|
-
=begin
|
26
|
-
def self.img
|
27
|
-
img = Nokogiri::HTML(open('http://dynamic.xkcd.com/random/comic/')).css('#comic img')[0]
|
28
|
-
img_url = img.attributes["src"].value
|
29
|
-
img_title = img.attributes["title"].value
|
30
|
-
"#{img_title} : #{img_url}"
|
31
|
-
end
|
32
|
-
=end
|
33
26
|
def self.img
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
"#{comic['alt']} : #{comic['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
|
39
31
|
end
|
40
32
|
end
|
metadata
CHANGED
@@ -1,63 +1,68 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: xkcd
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Hemanth.HM
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirement: &73470780 !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 1.5.2
|
22
|
-
- - ! '>='
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 1.5.0
|
25
|
-
type: :runtime
|
26
|
-
prerelease: false
|
27
|
-
version_requirements: *73470780
|
17
|
+
|
18
|
+
date: 2012-05-20 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
28
21
|
description: A simple gem to get random img/comic url from xkcd
|
29
22
|
email: hemanth.hm@gmail.com
|
30
|
-
executables:
|
23
|
+
executables:
|
24
|
+
- xkcd
|
31
25
|
extensions: []
|
26
|
+
|
32
27
|
extra_rdoc_files: []
|
33
|
-
|
28
|
+
|
29
|
+
files:
|
34
30
|
- Rakefile
|
35
31
|
- lib/xkcd.rb
|
36
32
|
- bin/xkcd
|
37
33
|
- test/test_karam.rb
|
38
34
|
homepage: http://rubygems.org/gems/xkcd
|
39
35
|
licenses: []
|
36
|
+
|
40
37
|
post_install_message:
|
41
38
|
rdoc_options: []
|
42
|
-
|
39
|
+
|
40
|
+
require_paths:
|
43
41
|
- lib
|
44
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
43
|
none: false
|
46
|
-
requirements:
|
47
|
-
- -
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
|
50
|
-
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
52
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
56
60
|
requirements: []
|
61
|
+
|
57
62
|
rubyforge_project:
|
58
|
-
rubygems_version: 1.8.
|
63
|
+
rubygems_version: 1.8.24
|
59
64
|
signing_key:
|
60
65
|
specification_version: 3
|
61
66
|
summary: XCKD random img urls!
|
62
|
-
test_files:
|
67
|
+
test_files:
|
63
68
|
- test/test_karam.rb
|