http_help 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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +9 -0
- data/bin/http +10 -0
- data/http_help.gemspec +22 -0
- data/lib/http_help.rb +52 -0
- data/lib/http_help/version.rb +3 -0
- data/lib/status_codes.yml +46 -0
- data/lib/string.rb +25 -0
- data/test/test_http_help.rb +32 -0
- data/test/test_string.rb +8 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 82311d2856d7a90f24e6646474c44f8ca8c6e766
|
4
|
+
data.tar.gz: 550b3329dd574829b0b2efe47e084d83d1cde4e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad5cc67693e4307828bfa7a5c5f66f92de36bec795b74ece276f11ff49f11ba2ceb36aaaa41c032e5fd880d8e2d42c283f6b9e47590e0e92d0de02a287751f72
|
7
|
+
data.tar.gz: 9c4232ccd7ffb46969141ea57f87d37bc0f163ac36c465fc33e5501249c1e1ac3ab938cf91bb7ecab3d681937886386b28fd5e6c3dce097f7116a8a11fcef6eb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Błażej Pankowiak
|
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,23 @@
|
|
1
|
+
# HttpHelp
|
2
|
+
|
3
|
+
Find HTTP status codes from the command line.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem install http_help
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```http [number]``` finds the description of a given code
|
14
|
+
```http [description]``` finds the number of a given description
|
15
|
+
```http all``` lists all status codes
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
1. Fork it ( https://github.com/blase/http_help/fork )
|
20
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
21
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
22
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
23
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/http
ADDED
data/http_help.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'http_help/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "http_help"
|
8
|
+
spec.version = HttpHelp::VERSION
|
9
|
+
spec.authors = ["Błażej Pankowiak"]
|
10
|
+
spec.email = ["blasecodes@gmail.com"]
|
11
|
+
spec.summary = %q{Find HTTP status codes from the command line}
|
12
|
+
spec.homepage = "http://github.com/blase/http_help"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
data/lib/http_help.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "http_help/version"
|
2
|
+
require 'yaml'
|
3
|
+
require 'string'
|
4
|
+
|
5
|
+
module HttpHelp
|
6
|
+
class StatusCodeNotFoundException < Exception; end
|
7
|
+
class StatusNotFoundException < Exception; end
|
8
|
+
|
9
|
+
def self.find status
|
10
|
+
if status == "all"
|
11
|
+
list_all_statuses
|
12
|
+
elsif status.to_i > 0
|
13
|
+
find_by_code status.to_i
|
14
|
+
else
|
15
|
+
find_by_description status
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def self.find_by_code status_code
|
22
|
+
status_codes.each do |category|
|
23
|
+
category.each do |code|
|
24
|
+
return code[status_code] unless code[status_code].nil?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
raise StatusCodeNotFoundException, "Status code not found."
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.find_by_description status_description
|
32
|
+
status_codes.keys.each do |category|
|
33
|
+
status_codes[category].each_pair do |code, description|
|
34
|
+
return "#{code}: #{description}" if description.downcase.levenshtein(status_description.downcase) < 3
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
raise StatusNotFoundException, "Status not found."
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.list_all_statuses
|
42
|
+
File.open(File.join(__dir__, 'status_codes.yml')) do |file|
|
43
|
+
while line = file.gets
|
44
|
+
puts line
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.status_codes
|
50
|
+
YAML::load_file(File.join(__dir__, 'status_codes.yml'))
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
informational:
|
2
|
+
100: Continue
|
3
|
+
101: Switching Protocols
|
4
|
+
successful:
|
5
|
+
200: OK
|
6
|
+
201: Created
|
7
|
+
202: Accepted
|
8
|
+
203: Non-Authoritative Information
|
9
|
+
204: No Content
|
10
|
+
205: Reset Content
|
11
|
+
206: Partial Content
|
12
|
+
redirection:
|
13
|
+
300: Multiple Choices
|
14
|
+
301: Moved Permanently
|
15
|
+
302: Found
|
16
|
+
303: See Other
|
17
|
+
304: Not Modified
|
18
|
+
305: Use Proxy
|
19
|
+
306: (Unused)
|
20
|
+
307: Temporary Redirect
|
21
|
+
client error:
|
22
|
+
400: Bad Request
|
23
|
+
401: Unauthorized
|
24
|
+
402: Payment Required
|
25
|
+
403: Forbidden
|
26
|
+
404: Not Found
|
27
|
+
405: Method Not Allowed
|
28
|
+
406: Not Acceptable
|
29
|
+
407: Proxy Authentication Required
|
30
|
+
408: Request Timeout
|
31
|
+
409: Conflict
|
32
|
+
410: Gone
|
33
|
+
411: Length Required
|
34
|
+
412: Precondition Failed
|
35
|
+
413: Request Entity Too Large
|
36
|
+
414: Request-URI Too Long
|
37
|
+
415: Unsupported Media Type
|
38
|
+
416: Requested Range Not Satisfiable
|
39
|
+
417: Expectation Failed
|
40
|
+
server error:
|
41
|
+
500: Internal Server Error
|
42
|
+
501: Not Implemented
|
43
|
+
502: Bad Gateway
|
44
|
+
503: Service Unavailable
|
45
|
+
504: Gateway Timeout
|
46
|
+
505: HTTP Version Not Supported
|
data/lib/string.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class String
|
2
|
+
# Stolen from:
|
3
|
+
# http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Ruby
|
4
|
+
def levenshtein(string)
|
5
|
+
matrix = [(0..self.length).to_a]
|
6
|
+
(1..string.length).each do |j|
|
7
|
+
matrix << [j] + [0] * (self.length)
|
8
|
+
end
|
9
|
+
|
10
|
+
(1..string.length).each do |i|
|
11
|
+
(1..self.length).each do |j|
|
12
|
+
if self[j-1] == string[i-1]
|
13
|
+
matrix[i][j] = matrix[i-1][j-1]
|
14
|
+
else
|
15
|
+
matrix[i][j] = [
|
16
|
+
matrix[i-1][j],
|
17
|
+
matrix[i][j-1],
|
18
|
+
matrix[i-1][j-1],
|
19
|
+
].min + 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
return matrix.last.last
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'http_help'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class TestHttpHelp < Test::Unit::TestCase
|
5
|
+
def test_that_it_can_find_response_description
|
6
|
+
assert_equal "Not Found", HttpHelp.find(404)
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_that_it_can_find_response_code
|
10
|
+
assert_equal "404: Not Found", HttpHelp.find("Not Found")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_that_it_can_find_response_code_given_different_letter_case
|
14
|
+
assert_equal "404: Not Found", HttpHelp.find("nOT fOUND")
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_that_it_can_find_response_code_given_similar_description
|
18
|
+
assert_equal "404: Not Found", HttpHelp.find("got fund")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_that_it_raises_an_exception_when_code_is_not_found
|
22
|
+
assert_raise_with_message HttpHelp::StatusCodeNotFoundException, "Status code not found." do
|
23
|
+
HttpHelp.find("999")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_that_it_raises_an_exception_when_status_is_not_found
|
28
|
+
assert_raise_with_message HttpHelp::StatusNotFoundException, "Status not found." do
|
29
|
+
HttpHelp.find("Some weird status")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/test_string.rb
ADDED
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http_help
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Błażej Pankowiak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-07 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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
|
+
description:
|
42
|
+
email:
|
43
|
+
- blasecodes@gmail.com
|
44
|
+
executables:
|
45
|
+
- http
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/http
|
55
|
+
- http_help.gemspec
|
56
|
+
- lib/http_help.rb
|
57
|
+
- lib/http_help/version.rb
|
58
|
+
- lib/status_codes.yml
|
59
|
+
- lib/string.rb
|
60
|
+
- test/test_http_help.rb
|
61
|
+
- test/test_string.rb
|
62
|
+
homepage: http://github.com/blase/http_help
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.2.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Find HTTP status codes from the command line
|
86
|
+
test_files:
|
87
|
+
- test/test_http_help.rb
|
88
|
+
- test/test_string.rb
|