cat_facts 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/cat_facts.gemspec +17 -0
- data/lib/cat_facts.rb +8 -0
- data/lib/cat_facts/library.rb +42 -0
- data/lib/cat_facts/middleware.rb +26 -0
- data/lib/cat_facts/version.rb +3 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Christian Baeuerlein
|
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,34 @@
|
|
1
|
+
# Cat Facts
|
2
|
+
|
3
|
+
Rack middleware that adds cat facts in headers of HTTP responses.
|
4
|
+
|
5
|
+
|
6
|
+
Response Headers:
|
7
|
+
X-Cat-Facts: The cats of this lib's developer are called Elvis and Mira.
|
8
|
+
|
9
|
+
|
10
|
+
## Enhance your web platform by adding high quality cat facts!
|
11
|
+
|
12
|
+

|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'cat_facts'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install cat_facts
|
27
|
+
|
28
|
+
Add it to your Rails middleware stack in `config/application.rb` (in the config block)
|
29
|
+
|
30
|
+
config.middleware.use CatFacts::Middleware
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Just add a `catfact=1` parameter to any URL you want to retrieve an additional `X-Cat-Fact` header in the response, that will contain a random cat fact for your amusement.
|
data/Rakefile
ADDED
data/cat_facts.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/cat_facts/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Christian Baeuerlein"]
|
6
|
+
gem.email = ["fabrik42@gmail.com"]
|
7
|
+
gem.description = %q{Rack middleware that to add cat facts in headers of HTTP responses.}
|
8
|
+
gem.summary = %q{Enhance your web platform by adding high quality cat facts.}
|
9
|
+
gem.homepage = "https://github.com/fabrik42/cat_facts"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "cat_facts"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = CatFacts::VERSION
|
17
|
+
end
|
data/lib/cat_facts.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module CatFacts
|
2
|
+
module Library
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
FACTS = [
|
7
|
+
# facts taken from http://maxellah.tripod.com/catfacts.htm
|
8
|
+
"Cats sleep about 16 hours a day.",
|
9
|
+
"Cats can't taste sweets.",
|
10
|
+
"Cat's urine glows under a black light.",
|
11
|
+
"Cats must have fat in their diet because they can't produce it on their own.",
|
12
|
+
"A cat has 32 muscles in each ear.",
|
13
|
+
"In ancient Egypt, killing a cat was a crime punishable by death.",
|
14
|
+
"The average cat food meal is the equivalent to about five mice.",
|
15
|
+
"Napoleon was terrified of cats.",
|
16
|
+
"Mother cats teach their kittens to use the litter box.",
|
17
|
+
"A cat has four rows of whiskers on each side.",
|
18
|
+
"Cats have over one hundred vocal sounds, while dogs only have about ten.",
|
19
|
+
"A cat can jump even seven times as high as it is tall.",
|
20
|
+
"A cat is pregnant for about 58-65 days.",
|
21
|
+
"Female cats tend to be right pawed, while male cats are more often left pawed.",
|
22
|
+
# facts taken from http://user.xmission.com/~emailbox/trivia.htm
|
23
|
+
"Both humans and cats have identical regions in the brain responsible for emotion.",
|
24
|
+
"A cat's brain is more similar to a man's brain than that of a dog.",
|
25
|
+
"The cat has 500 skeletal muscles (humans have 650).",
|
26
|
+
"A cat's field of vision is about 200 degrees.",
|
27
|
+
"A cat cannot see directly under its nose.",
|
28
|
+
"A cat's tongue has tiny barbs on it.",
|
29
|
+
"A domestic cat can sprint at about 31 miles per hour.",
|
30
|
+
"Cats take between 20-40 breaths per minute.",
|
31
|
+
"A cat has two vocal chords, and can make over 100 sounds.",
|
32
|
+
# by me
|
33
|
+
"Almost 100% of all cats don't give a shit about cat facts.",
|
34
|
+
"The cats of this lib's developer are called Elvis and Mira."
|
35
|
+
]
|
36
|
+
|
37
|
+
def random_cat_fact
|
38
|
+
FACTS.sample
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CatFacts
|
2
|
+
class Middleware
|
3
|
+
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
request = Rack::Request.new(env)
|
10
|
+
status, headers, response = @app.call(env)
|
11
|
+
|
12
|
+
if wants_cat_fact?(request)
|
13
|
+
headers["X-Cat-Fact"] = CatFacts::Library.random_cat_fact
|
14
|
+
end
|
15
|
+
|
16
|
+
[status, headers, response]
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def wants_cat_fact?(request)
|
22
|
+
request.params.include?('catfact') && !request.params['catfact'].empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cat_facts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christian Baeuerlein
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Rack middleware that to add cat facts in headers of HTTP responses.
|
15
|
+
email:
|
16
|
+
- fabrik42@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- cat_facts.gemspec
|
27
|
+
- lib/cat_facts.rb
|
28
|
+
- lib/cat_facts/library.rb
|
29
|
+
- lib/cat_facts/middleware.rb
|
30
|
+
- lib/cat_facts/version.rb
|
31
|
+
homepage: https://github.com/fabrik42/cat_facts
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.17
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Enhance your web platform by adding high quality cat facts.
|
55
|
+
test_files: []
|