chucknorris 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/chucknorris.rb +70 -0
  3. metadata +199 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: adb9001c331fdea852acf4428986030f1710a066
4
+ data.tar.gz: 6f9974b43668cbde0187f702a2d035a4324ace34
5
+ SHA512:
6
+ metadata.gz: d725f695cd9d6a024c5b77020b6f90937f2507030dd3a71a3a5bb76f4a9dbf725d4804acbacbaf9d9b3cfe8ea7a52c2513af845caa4d52a4fc81ac853a94a234
7
+ data.tar.gz: 28372c7e85a427728fdb194742af33c0c287de9086d6ab0663bd1a7755a701b553fa678d62fc415228a8334a126217249d520dea229ac6b6098baa1c558d9151
@@ -0,0 +1,70 @@
1
+ require 'unirest'
2
+ require 'uri'
3
+ class ChuckNorris
4
+ attr_accessor :categories, :first_name, :last_name
5
+ def initialize
6
+ @categories = []
7
+ end
8
+ def self.random
9
+ response = Unirest.get "http://api.icndb.com/jokes/random"
10
+ begin
11
+ body = response.body
12
+ if body["type"] == "success"
13
+ return body["value"]["joke"]
14
+ end
15
+ rescue
16
+ puts "Error occured"
17
+ end
18
+ end
19
+ def personal(firstname,lastname)
20
+ begin
21
+ body = request "http://api.icndb.com/jokes/random?firstName=#{firstname}&lastName=#{lastname}"
22
+ return body["value"]["joke"]
23
+ rescue ChuckNorris::UnsuccessfulError => e
24
+ puts e
25
+ end
26
+ end
27
+ def jokes(num=4)
28
+ jokes = []
29
+ begin
30
+ body = request "http://api.icndb.com/jokes/random/#{num}"
31
+ body["value"].each do |x|
32
+ jokes.push x["joke"]
33
+ end
34
+ return jokes
35
+ rescue ChuckNorris::UnsuccessfulError => e
36
+ puts e
37
+ end
38
+ end
39
+ def joke(num)
40
+ begin
41
+ body = request "http://api.icndb.com/jokes/#{num}"
42
+ if body["type"] == "success"
43
+ return body["value"]["joke"]
44
+ end
45
+ rescue ChuckNorris::UnsuccessfulError => e
46
+ puts e
47
+ end
48
+ end
49
+ def get_categories
50
+ begin
51
+ body = request "http://api.icndb.com/categories"
52
+ body["value"].each do |x|
53
+ @categories << x
54
+ end
55
+ return @categories
56
+ rescue ChuckNorris::UnsuccessfulError => e
57
+ puts e
58
+ end
59
+ end
60
+
61
+ private
62
+ def request(path)
63
+ response = Unirest.get(URI.escape(path))
64
+ body = response.body
65
+ raise ChuckNorris::UnsuccessfulError if body['value'] == "value"
66
+ body
67
+ end
68
+ class UnsuccessfulError < StandardError
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chucknorris
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Suraj Shirvankar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-nc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-remote
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-nav
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: growl
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: unirest
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: A ruby gem which displays random chuck norris jokes
168
+ email: surajshirvankar@gmail.com
169
+ executables: []
170
+ extensions: []
171
+ extra_rdoc_files: []
172
+ files:
173
+ - lib/chucknorris.rb
174
+ homepage: https://github.com/h0lyalg0rithm/chucknorris
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.2.2
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: ChuckNorris on ruby
198
+ test_files: []
199
+ has_rdoc: