http_codes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +14 -0
- data/Gemfile +9 -0
- data/README.md +36 -0
- data/Rakefile +8 -0
- data/bin/http_codes +24 -0
- data/http_codes.gemspec +21 -0
- data/lib/http_codes.rb +2 -0
- data/lib/http_codes/http_codes_fetcher.rb +43 -0
- data/lib/http_codes/version.rb +6 -0
- data/spec/fixtures/vcr_cassettes/http_csv.yml +80 -0
- data/spec/http_codes_spec.rb +44 -0
- data/usage_example.rb +10 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c9a94a9b12b36c9d6b1dc4d74de65eacffc5e63
|
4
|
+
data.tar.gz: 45019a28a0f498200df9e3cbd20af7973916e85f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9a2ab41bfec7aa34e408f08a13e8a890029fbfdf54c6ea65a1c448442a9252d4febff3427705476dc6970f4299558e21bc1e06d98bb1944decd06a1d60fe74a4
|
7
|
+
data.tar.gz: 817c2dedcf46016d18fd75df8cdc60675479c75dab806b82aa87728b94f1135a4a17f71718f4940962d19cd98578a776d114da39a9ee6eb5a6682a412e5cda81
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Http_Codes [![Build Status](https://travis-ci.org/csrordzhn/httpcodes.svg?branch=master)](https://travis-ci.org/csrordzhn/httpcodes)
|
2
|
+
## Description
|
3
|
+
The idea behind this project is to have HTTP codes as a searchable list in your code or usable in pry
|
4
|
+
instead of going to Wikipedia and search for codes. In the end, its all about saving you some clicks.
|
5
|
+
|
6
|
+
The source for the codes is [Internet Assigned Numbers Authority.](http://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv)
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
Install at the command line,
|
10
|
+
```sh
|
11
|
+
$ gem install http_codes
|
12
|
+
```
|
13
|
+
include in your project gemfile,
|
14
|
+
```ruby
|
15
|
+
gem 'http_codes'
|
16
|
+
```
|
17
|
+
or require in directly in pry
|
18
|
+
```ruby
|
19
|
+
require 'http_codes'
|
20
|
+
```
|
21
|
+
Once installed, you can run from the command line.
|
22
|
+
```sh
|
23
|
+
$ http_codes desc/code val
|
24
|
+
```
|
25
|
+
Search by description 'BAD' will return a list of the codes that contain the value 'BAD':
|
26
|
+
```sh
|
27
|
+
$ http_codes desc BAD
|
28
|
+
400 - BAD REQUEST
|
29
|
+
502 - BAD GATEWAY
|
30
|
+
```
|
31
|
+
Search by code number 100 will return the description that matches that code:
|
32
|
+
```sh
|
33
|
+
$ http_codes code 100
|
34
|
+
100 - CONTINUE
|
35
|
+
```
|
36
|
+
For usage inside a Ruby project, refer to the file ```usage_example.rb```
|
data/Rakefile
ADDED
data/bin/http_codes
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Local
|
3
|
+
# require '../lib/http_codes/http_codes_fetcher.rb'
|
4
|
+
# Production
|
5
|
+
require 'http_codes'
|
6
|
+
|
7
|
+
begin
|
8
|
+
fail ArgumentError, "Usage: http_codes [desc/code] [val]\n" if ARGV.count != 2
|
9
|
+
|
10
|
+
mode = ARGV[0]
|
11
|
+
val = ARGV[1]
|
12
|
+
code_list = HttpCodesFetcher::Httpcodes.new
|
13
|
+
|
14
|
+
if mode == 'desc'
|
15
|
+
code_list.find_by_desc(val).map do |c|
|
16
|
+
puts c
|
17
|
+
end
|
18
|
+
elsif mode == 'code'
|
19
|
+
puts code_list.find_by_code(val.to_i)
|
20
|
+
end
|
21
|
+
|
22
|
+
rescue => e
|
23
|
+
puts "Something went wrong: #{e}"
|
24
|
+
end
|
data/http_codes.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'http_codes/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'http_codes'
|
6
|
+
s.version = HttpCodesFetcher::VERSION
|
7
|
+
s.date = HttpCodesFetcher::DATE
|
8
|
+
s.executables << 'http_codes'
|
9
|
+
s.summary = 'Get http codes'
|
10
|
+
s.description = 'Provides a easy and fast way to find http codes by number or description.'
|
11
|
+
s.authors = ['Cesar Ordonez']
|
12
|
+
s.email = ['c_man182@yahoo.com']
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files spec/*`.split("\n")
|
15
|
+
s.homepage = 'https://github.com/csrordzhn/httpcodes'
|
16
|
+
s.license = 'MIT'
|
17
|
+
|
18
|
+
s.add_development_dependency 'minitest'
|
19
|
+
s.add_development_dependency 'vcr'
|
20
|
+
s.add_development_dependency 'webmock'
|
21
|
+
end
|
data/lib/http_codes.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
# Creates a hash of http codes from iana.org for developer reference inside pry
|
5
|
+
module HttpCodesFetcher
|
6
|
+
class Httpcodes
|
7
|
+
def initialize
|
8
|
+
@list = code_list
|
9
|
+
end
|
10
|
+
|
11
|
+
def code_list
|
12
|
+
url = 'http://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv'
|
13
|
+
codes = {}
|
14
|
+
CSV.new(open(url), headers: :first_row).each do |line|
|
15
|
+
codes[line['Description'].upcase] = line['Value'].to_i
|
16
|
+
end
|
17
|
+
codes
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_by_code(code)
|
21
|
+
desc = @list.key(code)
|
22
|
+
fail 'Code not found' unless @list.key?(desc)
|
23
|
+
@list[desc].to_s + ' - ' + desc
|
24
|
+
rescue => e
|
25
|
+
e.message
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_by_desc(desc)
|
29
|
+
search_val = Regexp.new desc.upcase
|
30
|
+
matches = @list.keys.grep search_val
|
31
|
+
fail 'Description not found' unless matches.size > 0
|
32
|
+
matches.map do |k|
|
33
|
+
@list[k].to_s + ' - ' + k.to_s
|
34
|
+
end
|
35
|
+
rescue => e
|
36
|
+
e.message
|
37
|
+
end
|
38
|
+
|
39
|
+
def size
|
40
|
+
@list.size
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Last-Modified:
|
22
|
+
- Thu, 05 Nov 2015 01:13:26 GMT
|
23
|
+
Vary:
|
24
|
+
- Accept-Encoding
|
25
|
+
Content-Type:
|
26
|
+
- text/csv; charset=UTF-8; header=present
|
27
|
+
Cache-Control:
|
28
|
+
- public, max-age=3600
|
29
|
+
Content-Length:
|
30
|
+
- '1031'
|
31
|
+
Accept-Ranges:
|
32
|
+
- bytes
|
33
|
+
Date:
|
34
|
+
- Thu, 05 Nov 2015 15:35:11 GMT
|
35
|
+
Connection:
|
36
|
+
- keep-alive
|
37
|
+
Server:
|
38
|
+
- Apache
|
39
|
+
X-Cache-Hits:
|
40
|
+
- '0'
|
41
|
+
body:
|
42
|
+
encoding: ASCII-8BIT
|
43
|
+
string: "Value,Description,Reference\r\n100,Continue,\"[RFC7231, Section 6.2.1]\"\r\n101,Switching
|
44
|
+
Protocols,\"[RFC7231, Section 6.2.2]\"\r\n102,Processing,[RFC2518]\r\n103-199,Unassigned,\r\n200,OK,\"[RFC7231,
|
45
|
+
Section 6.3.1]\"\r\n201,Created,\"[RFC7231, Section 6.3.2]\"\r\n202,Accepted,\"[RFC7231,
|
46
|
+
Section 6.3.3]\"\r\n203,Non-Authoritative Information,\"[RFC7231, Section
|
47
|
+
6.3.4]\"\r\n204,No Content,\"[RFC7231, Section 6.3.5]\"\r\n205,Reset Content,\"[RFC7231,
|
48
|
+
Section 6.3.6]\"\r\n206,Partial Content,\"[RFC7233, Section 4.1]\"\r\n207,Multi-Status,[RFC4918]\r\n208,Already
|
49
|
+
Reported,[RFC5842]\r\n209-225,Unassigned,\r\n226,IM Used,[RFC3229]\r\n227-299,Unassigned,\r\n300,Multiple
|
50
|
+
Choices,\"[RFC7231, Section 6.4.1]\"\r\n301,Moved Permanently,\"[RFC7231,
|
51
|
+
Section 6.4.2]\"\r\n302,Found,\"[RFC7231, Section 6.4.3]\"\r\n303,See Other,\"[RFC7231,
|
52
|
+
Section 6.4.4]\"\r\n304,Not Modified,\"[RFC7232, Section 4.1]\"\r\n305,Use
|
53
|
+
Proxy,\"[RFC7231, Section 6.4.5]\"\r\n306,(Unused),\"[RFC7231, Section 6.4.6]\"\r\n307,Temporary
|
54
|
+
Redirect,\"[RFC7231, Section 6.4.7]\"\r\n308,Permanent Redirect,[RFC7538]\r\n309-399,Unassigned,\r\n400,Bad
|
55
|
+
Request,\"[RFC7231, Section 6.5.1]\"\r\n401,Unauthorized,\"[RFC7235, Section
|
56
|
+
3.1]\"\r\n402,Payment Required,\"[RFC7231, Section 6.5.2]\"\r\n403,Forbidden,\"[RFC7231,
|
57
|
+
Section 6.5.3]\"\r\n404,Not Found,\"[RFC7231, Section 6.5.4]\"\r\n405,Method
|
58
|
+
Not Allowed,\"[RFC7231, Section 6.5.5]\"\r\n406,Not Acceptable,\"[RFC7231,
|
59
|
+
Section 6.5.6]\"\r\n407,Proxy Authentication Required,\"[RFC7235, Section
|
60
|
+
3.2]\"\r\n408,Request Timeout,\"[RFC7231, Section 6.5.7]\"\r\n409,Conflict,\"[RFC7231,
|
61
|
+
Section 6.5.8]\"\r\n410,Gone,\"[RFC7231, Section 6.5.9]\"\r\n411,Length Required,\"[RFC7231,
|
62
|
+
Section 6.5.10]\"\r\n412,Precondition Failed,\"[RFC7232, Section 4.2]\"\r\n413,Payload
|
63
|
+
Too Large,\"[RFC7231, Section 6.5.11]\"\r\n414,URI Too Long,\"[RFC7231, Section
|
64
|
+
6.5.12]\"\r\n415,Unsupported Media Type,\"[RFC7231, Section 6.5.13][RFC7694,
|
65
|
+
Section 3]\"\r\n416,Range Not Satisfiable,\"[RFC7233, Section 4.4]\"\r\n417,Expectation
|
66
|
+
Failed,\"[RFC7231, Section 6.5.14]\"\r\n418-420,Unassigned,\r\n421,Misdirected
|
67
|
+
Request,\"[RFC7540, Section 9.1.2]\"\r\n422,Unprocessable Entity,[RFC4918]\r\n423,Locked,[RFC4918]\r\n424,Failed
|
68
|
+
Dependency,[RFC4918]\r\n425,Unassigned,\r\n426,Upgrade Required,\"[RFC7231,
|
69
|
+
Section 6.5.15]\"\r\n427,Unassigned,\r\n428,Precondition Required,[RFC6585]\r\n429,Too
|
70
|
+
Many Requests,[RFC6585]\r\n430,Unassigned,\r\n431,Request Header Fields Too
|
71
|
+
Large,[RFC6585]\r\n432-499,Unassigned,\r\n500,Internal Server Error,\"[RFC7231,
|
72
|
+
Section 6.6.1]\"\r\n501,Not Implemented,\"[RFC7231, Section 6.6.2]\"\r\n502,Bad
|
73
|
+
Gateway,\"[RFC7231, Section 6.6.3]\"\r\n503,Service Unavailable,\"[RFC7231,
|
74
|
+
Section 6.6.4]\"\r\n504,Gateway Timeout,\"[RFC7231, Section 6.6.5]\"\r\n505,HTTP
|
75
|
+
Version Not Supported,\"[RFC7231, Section 6.6.6]\"\r\n506,Variant Also Negotiates,[RFC2295]\r\n507,Insufficient
|
76
|
+
Storage,[RFC4918]\r\n508,Loop Detected,[RFC5842]\r\n509,Unassigned,\r\n510,Not
|
77
|
+
Extended,[RFC2774]\r\n511,Network Authentication Required,[RFC6585]\r\n512-599,Unassigned,\r\n"
|
78
|
+
http_version:
|
79
|
+
recorded_at: Thu, 05 Nov 2015 15:35:11 GMT
|
80
|
+
recorded_with: VCR 3.0.0
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require './lib/http_codes'
|
3
|
+
require 'vcr'
|
4
|
+
require 'webmock/minitest'
|
5
|
+
|
6
|
+
def random_str(n)
|
7
|
+
srand(n)
|
8
|
+
(0..n).map { ('a'..'z').to_a[rand(26)]}.join
|
9
|
+
end
|
10
|
+
random_code = Random.rand(1000...9999)
|
11
|
+
|
12
|
+
VCR.configure do |config|
|
13
|
+
config.cassette_library_dir = './spec/fixtures/vcr_cassettes'
|
14
|
+
config.hook_into :webmock
|
15
|
+
end
|
16
|
+
|
17
|
+
VCR.use_cassette('http_csv') do
|
18
|
+
httpcodes_list = HttpCodesFetcher::Httpcodes.new
|
19
|
+
|
20
|
+
describe 'httpcodes' do
|
21
|
+
|
22
|
+
it 'should load the code list' do
|
23
|
+
httpcodes_list.size.must_be :>=, 1
|
24
|
+
end
|
25
|
+
it 'should return a string with code and desc' do
|
26
|
+
code_desc = httpcodes_list.find_by_code(100)
|
27
|
+
code_desc.wont_be_empty
|
28
|
+
end
|
29
|
+
it 'should return err when code not found' do
|
30
|
+
code_desc = httpcodes_list.find_by_code(random_code)
|
31
|
+
code_desc.must_match "Code not found"
|
32
|
+
end
|
33
|
+
it 'should return an string array with code and description' do
|
34
|
+
code_list = httpcodes_list.find_by_desc('Continue')
|
35
|
+
code_list.must_be_instance_of Array
|
36
|
+
code_list.wont_be_empty
|
37
|
+
end
|
38
|
+
it 'should return err when code not found' do
|
39
|
+
code_list = httpcodes_list.find_by_desc(random_str(15))
|
40
|
+
code_list.must_match "Description not found"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/usage_example.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
require 'http_codes'
|
3
|
+
# create a new httpcodes
|
4
|
+
http_codes = HttpCodesFetcher::Httpcodes.new
|
5
|
+
|
6
|
+
#puts http_codes.size
|
7
|
+
puts http_codes.find_by_code(100)
|
8
|
+
# => string '100 - CONTINUE'
|
9
|
+
puts http_codes.find_by_desc('BAD')
|
10
|
+
# => array ['400 - BAD REQUEST','502 - BAD GATEWAY']
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http_codes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cesar Ordonez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
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: vcr
|
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: webmock
|
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
|
+
description: Provides a easy and fast way to find http codes by number or description.
|
56
|
+
email:
|
57
|
+
- c_man182@yahoo.com
|
58
|
+
executables:
|
59
|
+
- http_codes
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/http_codes
|
69
|
+
- http_codes.gemspec
|
70
|
+
- lib/http_codes.rb
|
71
|
+
- lib/http_codes/http_codes_fetcher.rb
|
72
|
+
- lib/http_codes/version.rb
|
73
|
+
- spec/fixtures/vcr_cassettes/http_csv.yml
|
74
|
+
- spec/http_codes_spec.rb
|
75
|
+
- usage_example.rb
|
76
|
+
homepage: https://github.com/csrordzhn/httpcodes
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.6
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Get http codes
|
100
|
+
test_files:
|
101
|
+
- spec/fixtures/vcr_cassettes/http_csv.yml
|
102
|
+
- spec/http_codes_spec.rb
|