chuck_norris 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +90 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/chuck_norris.gemspec +35 -0
- data/lib/chuck_norris.rb +11 -0
- data/lib/chuck_norris/joke.rb +10 -0
- data/lib/chuck_norris/joke_finder.rb +32 -0
- data/lib/chuck_norris/utility.rb +26 -0
- data/lib/chuck_norris/version.rb +3 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1984303cbf408d25f4ae79ee0e38dccce15ac8f0
|
4
|
+
data.tar.gz: 418cc700cc8d5ba3ed82adbe1def42438902de3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 594b690222b65c6f06f8b18a1a3b973c0a2a6310f8678e08a653090d743db477b1f74d426e11fa276192ae0326491248ff3bad11337d40303623ebffdda89344
|
7
|
+
data.tar.gz: 9809e491743bc49394f322cb71cea4733494cf0a027b4a11fb16e313f526b5e33c8a5c5a49f373b08666449c0f6584d7b19f7c680474e4d24e0e3347d15de530
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Spencer Dixon
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# ChuckNorris
|
2
|
+
|
3
|
+
ChuckNorris is a light weight Ruby wrapper around the Chuck Norris Joke API [found
|
4
|
+
here](http://www.icndb.com/api/). It contains a series of Chuck Norris jokes
|
5
|
+
which can be customized with an individuals first and last name.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
#### Getting Random Joke
|
10
|
+
Jokes have an id, joke, and categories you can query.
|
11
|
+
```
|
12
|
+
joke = ChuckNorris::JokeFinder.get_joke
|
13
|
+
joke.id # => 497
|
14
|
+
joke.joke # => "If Chuck Norris writes code with bugs, the bugs fix themselves."
|
15
|
+
joke.categories # => ["nerdy"]
|
16
|
+
```
|
17
|
+
|
18
|
+
You can customize the name of the person in the joke by passing in the
|
19
|
+
`first_name` and `last_name` as options:
|
20
|
+
|
21
|
+
```
|
22
|
+
joke = ChuckNorris::JokeFinder.get_joke(first_name: 'Spencer', last_name: 'Dixon')
|
23
|
+
joke.joke # => "Spencer Dixon doesn't read books. He stares them down until he gets the information he wants."
|
24
|
+
```
|
25
|
+
|
26
|
+
|
27
|
+
#### Getting Multiple Jokes
|
28
|
+
You can get multiple jokes by passing the number you want as an argument to the
|
29
|
+
`ChuckNorris.get_jokes` method. **NOTE** the `s` at the end.
|
30
|
+
|
31
|
+
```
|
32
|
+
jokes = ChuckNorris::JokeFinder.get_jokes(3)
|
33
|
+
jokes[0].joke
|
34
|
+
# => "When Chuck Norris throws exceptions, it's across the room."
|
35
|
+
|
36
|
+
jokes[1].joke
|
37
|
+
# => "The only sure things are Death and Taxes and when Chuck Norris goes to work for the IRS, they'll be the same thing."
|
38
|
+
|
39
|
+
jokes[2].joke
|
40
|
+
# =>
|
41
|
+
```
|
42
|
+
|
43
|
+
#### Finding Specific Joke
|
44
|
+
You can fetch a specific joke by its `id`
|
45
|
+
|
46
|
+
```
|
47
|
+
bug_joke = ChuckNorris::JokeFinder.find_joke(497)
|
48
|
+
bug_joke.joke # => "If Chuck Norris writes code with bugs, the bugs fix themselves."
|
49
|
+
```
|
50
|
+
|
51
|
+
#### Fetching Joke Categories
|
52
|
+
```
|
53
|
+
categories = ChuckNorris::JokeFinder.joke_categories
|
54
|
+
```
|
55
|
+
|
56
|
+
#### Fetching Total Number Of Jokes
|
57
|
+
```
|
58
|
+
total = ChuckNorris::JokeFinder.joke_count
|
59
|
+
```
|
60
|
+
|
61
|
+
## Installation
|
62
|
+
|
63
|
+
Add this line to your application's Gemfile:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
gem 'chuck_norris'
|
67
|
+
```
|
68
|
+
|
69
|
+
And then execute:
|
70
|
+
|
71
|
+
$ bundle
|
72
|
+
|
73
|
+
Or install it yourself as:
|
74
|
+
|
75
|
+
$ gem install chuck_norris
|
76
|
+
|
77
|
+
|
78
|
+
## Development
|
79
|
+
|
80
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
81
|
+
|
82
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
1. Fork it ( https://github.com/[my-github-username]/chuck_norris/fork )
|
87
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
88
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
89
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
90
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "chuck_norris"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chuck_norris/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chuck_norris"
|
8
|
+
spec.version = ChuckNorris::VERSION
|
9
|
+
spec.authors = ["Spencer Dixon"]
|
10
|
+
spec.email = ["spencercdixon@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Light weight Chuck Norris API wrapper}
|
13
|
+
spec.description = %q{API wrapper to get funny Chuck Norris jokes}
|
14
|
+
spec.homepage = "https://github.com/spencercdixon/chuck_norris"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rest-client", '~> 0'
|
33
|
+
spec.add_development_dependency "json", '~> 0'
|
34
|
+
spec.add_development_dependency "pry", '~> 0'
|
35
|
+
end
|
data/lib/chuck_norris.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'chuck_norris/utility'
|
2
|
+
|
3
|
+
module ChuckNorris
|
4
|
+
class JokeFinder
|
5
|
+
extend Utility
|
6
|
+
|
7
|
+
def self.get_joke(options={})
|
8
|
+
response = execute(:get, '/jokes/random/', options)
|
9
|
+
Joke.new(response["value"])
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_jokes(num, options={})
|
13
|
+
response = execute(:get, "/jokes/random/#{num}", options)
|
14
|
+
response["value"].map { |args| Joke.new(args) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.joke_categories
|
18
|
+
response = execute(:get, "/categories")
|
19
|
+
response["value"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.joke_count
|
23
|
+
response = execute(:get, "/jokes/count")
|
24
|
+
response["value"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_joke(id)
|
28
|
+
response = execute(:get, "/jokes/#{id}")
|
29
|
+
Joke.new(response["value"])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ChuckNorris
|
2
|
+
module Utility
|
3
|
+
API_URI = 'http://api.icndb.com'
|
4
|
+
|
5
|
+
def execute(method, path, options={})
|
6
|
+
options = sanitize_options(options)
|
7
|
+
url = API_URI + path + options
|
8
|
+
response = RestClient::Request.execute(method: method, url: url)
|
9
|
+
JSON.parse(response)
|
10
|
+
end
|
11
|
+
|
12
|
+
def sanitize_options(options)
|
13
|
+
return '' if options.empty?
|
14
|
+
final = {}
|
15
|
+
final[:firstName] = options.fetch(:first_name, 'Chuck')
|
16
|
+
final[:lastName] = options.fetch(:last_name, 'Norris')
|
17
|
+
to_query(final)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_query(hash)
|
21
|
+
query = '?'
|
22
|
+
hash.each {|k, v| query << "#{k}=#{v}&" }
|
23
|
+
query.chop
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chuck_norris
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Spencer Dixon
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-13 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: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
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: json
|
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: pry
|
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
|
+
description: API wrapper to get funny Chuck Norris jokes
|
84
|
+
email:
|
85
|
+
- spencercdixon@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- chuck_norris.gemspec
|
101
|
+
- lib/chuck_norris.rb
|
102
|
+
- lib/chuck_norris/joke.rb
|
103
|
+
- lib/chuck_norris/joke_finder.rb
|
104
|
+
- lib/chuck_norris/utility.rb
|
105
|
+
- lib/chuck_norris/version.rb
|
106
|
+
homepage: https://github.com/spencercdixon/chuck_norris
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata:
|
110
|
+
allowed_push_host: https://rubygems.org
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.2.2
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Light weight Chuck Norris API wrapper
|
131
|
+
test_files: []
|