xkcd 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/xkcd +0 -1
- data/lib/xkcd.rb +23 -15
- metadata +33 -39
data/bin/xkcd
CHANGED
data/lib/xkcd.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
#!/usr/bin/
|
2
|
-
require '
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'nokogiri'
|
3
3
|
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
|
4
6
|
# The main XKCD driver
|
5
7
|
class XKCD
|
6
8
|
# Get img/comic URL from xkcd
|
@@ -12,21 +14,27 @@ class XKCD
|
|
12
14
|
# >> XKCD.comic
|
13
15
|
# => "http://xkcd.com/891/"
|
14
16
|
|
15
|
-
def self.comic
|
16
|
-
|
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"]
|
17
|
+
def self.comic
|
18
|
+
open('http://dynamic.xkcd.com/random/comic/').base_uri.to_s
|
24
19
|
end
|
25
20
|
|
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
|
26
33
|
def self.img
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
34
|
+
max = JSON.parse(open('http://xkcd.com/info.0.json').read)["num"]
|
35
|
+
comic_num = Random.rand(max)
|
36
|
+
comic_num = 1 if comic_num == 404 # Avoid 404th comic ;)
|
37
|
+
comic = JSON.parse(open("http://xkcd.com/#{comic_num}/info.0.json").read)
|
38
|
+
"#{comic['alt']} : #{comic['img']}"
|
31
39
|
end
|
32
40
|
end
|
metadata
CHANGED
@@ -1,68 +1,62 @@
|
|
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
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 8
|
10
|
-
version: 0.0.8
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Hemanth.HM
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
date: 2012-05-20 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: &72954180 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *72954180
|
21
25
|
description: A simple gem to get random img/comic url from xkcd
|
22
26
|
email: hemanth.hm@gmail.com
|
23
|
-
executables:
|
27
|
+
executables:
|
24
28
|
- xkcd
|
25
29
|
extensions: []
|
26
|
-
|
27
30
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
files:
|
31
|
+
files:
|
30
32
|
- Rakefile
|
31
33
|
- lib/xkcd.rb
|
32
34
|
- bin/xkcd
|
33
35
|
- test/test_karam.rb
|
34
36
|
homepage: http://rubygems.org/gems/xkcd
|
35
37
|
licenses: []
|
36
|
-
|
37
38
|
post_install_message:
|
38
39
|
rdoc_options: []
|
39
|
-
|
40
|
-
require_paths:
|
40
|
+
require_paths:
|
41
41
|
- lib
|
42
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
43
|
none: false
|
44
|
-
requirements:
|
45
|
-
- -
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
48
|
-
|
49
|
-
- 0
|
50
|
-
version: "0"
|
51
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
49
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
60
54
|
requirements: []
|
61
|
-
|
62
55
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.8.
|
56
|
+
rubygems_version: 1.8.10
|
64
57
|
signing_key:
|
65
58
|
specification_version: 3
|
66
59
|
summary: XCKD random img urls!
|
67
|
-
test_files:
|
60
|
+
test_files:
|
68
61
|
- test/test_karam.rb
|
62
|
+
has_rdoc:
|