jok 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +16 -0
- data/bin/jok +29 -0
- data/jok.gemspec +27 -0
- data/lib/jok/joke_factory.rb +49 -0
- data/lib/jok/version.rb +3 -0
- data/lib/jok.rb +23 -0
- data/test/jok_test.rb +7 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d03420a3d120a88ec9eda060bba6daf1265cd4c7
|
4
|
+
data.tar.gz: 10fabd8ef998aa43ccffcdee08615caad0ebaf95
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26549a6491789ff0897b289c3a23e478b367a4d8d44cbc72b43ee0b8008b3785a3fbf166479d3ea90b521bf1d18a5d1f8d4dd09320e2b6595a28a10fe66dcd8a
|
7
|
+
data.tar.gz: 19c121c46af65d5260155278022544c2abad87dc743bec27d62585d3b516c4080923d108e0854a7d70ba5ad90c34fae0d4c00d38351c758c00a21ba5de9ba330
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jingkai He
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Jok
|
2
|
+
|
3
|
+
Jok will bring you a good laugh.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'jok'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install jok
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To show all the available joke list
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Jok.list
|
27
|
+
```
|
28
|
+
|
29
|
+
Randomly get a joke
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Jok.da
|
33
|
+
```
|
34
|
+
|
35
|
+
Pick up a specified topic
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Jok.blonde_jokes
|
39
|
+
```
|
40
|
+
## Command Line Relax
|
41
|
+
```
|
42
|
+
Commands:
|
43
|
+
jok da # Randomly get a joke
|
44
|
+
jok help [COMMAND] # Describe available commands or one specific command
|
45
|
+
jok list # To show all the available joke list
|
46
|
+
jok topic [YOUR_TOPIC] # Pick up a specified topic
|
47
|
+
```
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( https://github.com/jok/jok/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc "Run an IRB session with Jok preloaded"
|
4
|
+
task :console do
|
5
|
+
exec "irb -I lib -r jok"
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rake/testtask'
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
task :test do
|
13
|
+
require "jok"
|
14
|
+
$LOAD_PATH.unshift('lib', 'test')
|
15
|
+
Dir.glob('./test/**/*_test.rb') { |f| require f }
|
16
|
+
end
|
data/bin/jok
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH << File.dirname(__FILE__) + "/../lib" if $0 == __FILE__
|
4
|
+
|
5
|
+
require "jok"
|
6
|
+
require "thor"
|
7
|
+
|
8
|
+
class JokAtWork < Thor
|
9
|
+
desc "list", "To show all the available joke list"
|
10
|
+
def list
|
11
|
+
puts Jok.list
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "da", "Randomly get a joke"
|
15
|
+
def da
|
16
|
+
puts Jok.da
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "topic [YOUR_TOPIC]", "Pick up a specified topic"
|
20
|
+
def topic(topic)
|
21
|
+
if Jok.feed.method_list.include? topic
|
22
|
+
puts Jok.send(topic)
|
23
|
+
else
|
24
|
+
puts Jok.da
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
JokAtWork.start(ARGV)
|
data/jok.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jok/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jok"
|
8
|
+
spec.version = Jok::VERSION
|
9
|
+
spec.authors = ["Jingkai He"]
|
10
|
+
spec.email = ["jaxihe@gmail.com"]
|
11
|
+
spec.summary = %q{Bring you a good laugh.}
|
12
|
+
spec.description = %q{Bring you a good laugh.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "httparty", "~> 0.13.3"
|
22
|
+
spec.add_dependency "nokogiri", "~> 1.6.5"
|
23
|
+
spec.add_dependency "thor", "~> 0.19.1"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.4.3"
|
27
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Jok
|
2
|
+
class JokeFactory
|
3
|
+
BASE_URI = "http://www.laughfactory.com/jokes/".freeze
|
4
|
+
|
5
|
+
def list
|
6
|
+
@list ||= begin
|
7
|
+
dom.xpath('//div[@class="left-nav"]/ul/li/a').map(&:text)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def da
|
12
|
+
joke
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
method = method.to_s
|
17
|
+
super unless method_list.include? method
|
18
|
+
|
19
|
+
self.class.class_eval <<-EOT, __FILE__, __LINE__ + 1
|
20
|
+
def #{method}
|
21
|
+
@#{method} ||= begin
|
22
|
+
joke("#{method}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
EOT
|
26
|
+
|
27
|
+
send method
|
28
|
+
end
|
29
|
+
|
30
|
+
def method_list
|
31
|
+
@method_list ||= begin
|
32
|
+
list.map do |element|
|
33
|
+
element.split(" ").map(&:downcase).join("_")
|
34
|
+
end.push "da"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def dom(method="")
|
41
|
+
response_body = HTTParty.get("#{BASE_URI}/#{method.gsub("_", "-")}")
|
42
|
+
dom = Nokogiri::HTML(response_body)
|
43
|
+
end
|
44
|
+
|
45
|
+
def joke(topic="")
|
46
|
+
dom(topic).xpath('//div[@class="joke3-pop-box"]/p').map(&:text).map(&:strip)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/jok/version.rb
ADDED
data/lib/jok.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Jok
|
2
|
+
require "httparty"
|
3
|
+
require "nokogiri"
|
4
|
+
|
5
|
+
require "jok/joke_factory"
|
6
|
+
|
7
|
+
class << self
|
8
|
+
extend ::Forwardable
|
9
|
+
|
10
|
+
delegate [:list, :method_list] => :feed
|
11
|
+
|
12
|
+
def feed
|
13
|
+
@feed ||= JokeFactory.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
method_list.each do |method|
|
18
|
+
define_singleton_method method do
|
19
|
+
feeds = feed.send(method)
|
20
|
+
feeds[ srand % feeds.length]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/test/jok_test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jok
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jingkai He
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.19.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.19.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 5.4.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 5.4.3
|
97
|
+
description: Bring you a good laugh.
|
98
|
+
email:
|
99
|
+
- jaxihe@gmail.com
|
100
|
+
executables:
|
101
|
+
- jok
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/jok
|
111
|
+
- jok.gemspec
|
112
|
+
- lib/jok.rb
|
113
|
+
- lib/jok/joke_factory.rb
|
114
|
+
- lib/jok/version.rb
|
115
|
+
- test/jok_test.rb
|
116
|
+
homepage: ''
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.2.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: Bring you a good laugh.
|
140
|
+
test_files:
|
141
|
+
- test/jok_test.rb
|