response_code 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee5e9a44623d499f56154fe4e29fb9d7cd694dc5c468f6236bc599c2cec981f8
4
- data.tar.gz: a6c9d2dd370dee1b9f90fada6752181faa0b605789879abc23ae046b7434a801
3
+ metadata.gz: e11cb7c1bee1dee1e2b7c291422bcb11dbc6224e7d5a3f71839ce78885c0ee86
4
+ data.tar.gz: c85eecdf80cbfc6c9f5a8ccf8f9c1a16e8bd4ed560ac05a790789888353a6487
5
5
  SHA512:
6
- metadata.gz: b3baf5f6d77a84ebb270234a353959f0320193b4a58c9d4010271a1eee95501a86cb4178b32be41d52bd6e450e100faf169a37ea78ed6e251770a05795723b46
7
- data.tar.gz: f7d563400eb11fb1e3e66998d3706bdbe8f709fe53c52d553a8fa6705d02917cd45c5bc7d8bf3a48beac0c67da57def5de006f6a38ac4e81a3f3239ae1d97c01
6
+ metadata.gz: 47a97ea8beb5f06ff53189e479a0c2bbfe92f5a770b312315eba744005bf3c9f065e6b1bb40815393240e9b7d049bfacac33eb8892076b73d0379a6a3e4afa1e
7
+ data.tar.gz: 9857019a6488047faf7bfe08e38c49245010d0e9dc53b82948364447445b0f37e2dd38091d4c823fab1ac34c676ca8254e929ca6e70b2dc73dd885370bf0e62a
data/README.md CHANGED
@@ -1,2 +1,59 @@
1
- # response_code
2
- Response Code in readable way.
1
+ # ResponseCode
2
+
3
+ [![Build Status](https://travis-ci.org/torokmark/response_code.svg?branch=master)](https://travis-ci.org/torokmark/response_code)
4
+ [![Gem Version](https://badge.fury.io/rb/response_code.svg)](https://badge.fury.io/rb/response_code)
5
+
6
+ Who knows which response code represents the partial content? Or what code belongs to the error that says the request uri too long? Do you know the status code of the teapot?
7
+
8
+ ResponseCode is a tiny tool intended to give a handy way of handling response status codes with text instead of numbers.
9
+
10
+ ### Install
11
+
12
+ ```ruby
13
+ gem install response_code
14
+ ```
15
+
16
+ or
17
+
18
+ ```ruby
19
+ gem 'response_code'
20
+ ```
21
+
22
+ ### Usage
23
+
24
+ ```ruby
25
+ require 'response_code'
26
+
27
+ puts ResponseCode.ok
28
+ # => 200
29
+ ```
30
+
31
+ Using sinatra
32
+
33
+ ```ruby
34
+ #!/usr/bin/env ruby
35
+
36
+ require 'sinatra'
37
+ require 'response_code'
38
+
39
+ get('/') {
40
+ status ResponseCode.im_a_teapot
41
+ 'I\'m a teapot!'
42
+ }
43
+ ```
44
+
45
+ Executing `curl -i localhost:4567`
46
+
47
+ ```
48
+ HTTP/1.1 418
49
+ Content-Type: text/html;charset=utf-8
50
+ Content-Length: 13
51
+ X-Xss-Protection: 1; mode=block
52
+ X-Content-Type-Options: nosniff
53
+ X-Frame-Options: SAMEORIGIN
54
+ Server: WEBrick/1.4.2 (Ruby/2.5.0/2017-12-25)
55
+ Date: Thu, 03 May 2018 18:24:12 GMT
56
+ Connection: Keep-Alive
57
+
58
+ I'm a teapot!
59
+ ```
@@ -1,5 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'response_code'
4
+ require 'response_code/aborted'
4
5
 
5
6
  puts "Response code of OK is: #{ ResponseCode.ok }"
7
+
8
+ puts "#{ ResponseCode::Aborted.lookup(103) }"
9
+ puts "#{ ResponseCode::Aborted.checkpoint }"
@@ -0,0 +1,112 @@
1
+ Feature: ResponseCode
2
+ In order to use readable response codes
3
+ As a developer
4
+ I want to use ResponseCode for that
5
+
6
+ Scenario Outline: Codes
7
+ When I call a method with <name>
8
+ Then it should give me <code>
9
+
10
+ When I call lookup with <code>
11
+ Then it should return me <name>
12
+
13
+ Examples:
14
+ | name | code |
15
+ | continue| 100|
16
+ | switching_protocols| 101|
17
+ | processing| 102|
18
+ | ok| 200|
19
+ | created| 201|
20
+ | accepted| 202|
21
+ | non_authoritive_information| 203|
22
+ | no_content| 204|
23
+ | reset_content| 205|
24
+ | partial_content| 206|
25
+ | multi_status| 207|
26
+ | already_reported| 208|
27
+ | im_used| 226|
28
+ | multiple_choices| 300|
29
+ | moved_permanentaly| 301|
30
+ | found| 302|
31
+ | see_other| 303|
32
+ | not_modified| 304|
33
+ | use_proxy| 305|
34
+ | temporary_redirect| 307|
35
+ | permanent_redirect| 308|
36
+ | bad_request| 400|
37
+ | unauthorized| 401|
38
+ | payment_required| 402|
39
+ | forbidden| 403|
40
+ | not_found| 404|
41
+ | method_not_allowed| 405|
42
+ | not_acceptable| 406|
43
+ | proxy_authentication_required| 407|
44
+ | request_timeout| 408|
45
+ | conflict| 409|
46
+ | gone| 410|
47
+ | length_required| 411|
48
+ | precondition_failed| 412|
49
+ | payload_too_large| 413|
50
+ | request_uri_too_long| 414|
51
+ | unsupported_media_type| 415|
52
+ | requested_range_not_satisfiable| 416|
53
+ | expectation_failed| 417|
54
+ | im_a_teapot| 418|
55
+ | misdirected_request| 421|
56
+ | unprocessable_entity| 422|
57
+ | locked| 423|
58
+ | failed_dependency| 424|
59
+ | upgrade_required| 426|
60
+ | precondition_required| 428|
61
+ | internal_server_error| 500|
62
+ | not_implemented| 501|
63
+ | bad_gateway| 502|
64
+ | service_unavailable| 503|
65
+ | gateway_timeout| 504|
66
+ | http_version_not_supported| 505|
67
+ | variant_also_negotiates| 506|
68
+ | insufficiant_storage| 507|
69
+ | loop_detected| 508|
70
+ | not_extended| 510|
71
+ | network_authentication_required| 511|
72
+ | network_connect_timeout_error| 599|
73
+
74
+ Scenario Outline: Unofficial response codes
75
+ When I call a method in <module> with <name>
76
+ Then it should give me <code> from <module>
77
+
78
+ When I call <module> lookup with <code>
79
+ Then it should return me <name> from <module>
80
+
81
+ Examples:
82
+ | module | name | code |
83
+ | Aborted | checkpoint | 103 |
84
+ | SpringFramework | method_failure | 420 |
85
+ | Twitter | enhance_your_calm | 420 |
86
+ | Microsoft | blocked_by_windows_parental_controls | 450 |
87
+ | Esri | invalid_token | 498 |
88
+ | Esri | token_required | 499 |
89
+ | ApacheWebServer | bandwith_limit_exceeded | 509 |
90
+ | Pantheon | site_is_frozen | 530 |
91
+ | Signal | network_read_timeout_error | 598 |
92
+ | IIS | login_time_out | 440 |
93
+ | IIS | retry_with | 449 |
94
+ | IIS | redirect | 451 |
95
+ | Nginx | no_response | 444 |
96
+ | Nginx | request_header_too_large | 494 |
97
+ | Nginx | ssl_certificate_error | 495 |
98
+ | Nginx | ssl_certificate_required | 496 |
99
+ | Nginx | http_request_sent_to_https_port | 497 |
100
+ | Nginx | client_closed_request | 499 |
101
+ | Cloudflare | unknown_error | 520 |
102
+ | Cloudflare | web_server_is_down | 521 |
103
+ | Cloudflare | connection_timed_out | 522 |
104
+ | Cloudflare | origin_is_unreachable | 523 |
105
+ | Cloudflare | a_timeout_occurred | 524 |
106
+ | Cloudflare | ssl_handshake_failed | 525 |
107
+ | Cloudflare | invalid_ssl_certificate | 526 |
108
+ | Cloudflare | railgun_error | 527 |
109
+ | Cloudflare | origin_dns_error | 530 |
110
+
111
+
112
+
@@ -0,0 +1,17 @@
1
+ require 'response_code'
2
+
3
+ When(/^I call a method with (\w+)$/) do |name|
4
+ @result = ResponseCode.send(name.to_sym)
5
+ end
6
+
7
+ Then(/^it should give me (\d+)$/) do |expected|
8
+ expect(@result).to eq expected.to_i
9
+ end
10
+
11
+ When(/^I call lookup with (\d+)$/) do |code|
12
+ @name = ResponseCode.lookup(code)
13
+ end
14
+
15
+ Then(/^it should return me (\w+)$/) do |expected|
16
+ expect(@name.to_s).to eq expected
17
+ end
@@ -0,0 +1,28 @@
1
+ require 'response_code/aborted'
2
+ require 'response_code/spring_framework'
3
+ require 'response_code/twitter'
4
+ require 'response_code/microsoft'
5
+ require 'response_code/esri'
6
+ require 'response_code/apache_web_server'
7
+ require 'response_code/pantheon'
8
+ require 'response_code/signal'
9
+ require 'response_code/iis'
10
+ require 'response_code/nginx'
11
+ require 'response_code/cloudflare'
12
+
13
+ When(/^I call a method in (\w+) with (\w+)$/) do |module_name, name|
14
+ @result = Object.const_get("ResponseCode::#{ module_name }").send(name.to_sym)
15
+ end
16
+
17
+ Then(/^it should give me (\d+) from (\w+)$/) do |expected, module_name |
18
+ expect(@result).to eq expected.to_i
19
+ end
20
+
21
+ When(/^I call (\w+) lookup with (\d+)$/) do |module_name, code|
22
+ @name = Object.const_get("ResponseCode::#{ module_name }").lookup(code)
23
+ end
24
+
25
+ Then(/^it should return me (\w+) from (\w+)$/) do |expected, module_name|
26
+ expect(@name.to_s).to eq expected
27
+ end
28
+
@@ -1,5 +1,6 @@
1
1
  require 'response_code/version'
2
2
  require 'response_code/codes'
3
+ require 'response_code/aborted'
3
4
 
4
5
  module ResponseCode
5
6
 
@@ -10,5 +11,13 @@ module ResponseCode
10
11
  raise 'Not a valid status!'
11
12
  end
12
13
  end
14
+
15
+ def self.lookup(code)
16
+ if ResponseCode::CODES.value?(code.to_i)
17
+ ResponseCode::CODES.key(code.to_i)
18
+ else
19
+ raise 'Not a valid code!'
20
+ end
21
+ end
13
22
  end
14
23
 
@@ -0,0 +1,12 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module Aborted
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ checkpoint: 103
9
+ }
10
+
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module ApacheWebServer
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ bandwith_limit_exceeded: 509
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module ResponseCode
2
+ module BaseImp
3
+ extend self
4
+
5
+ def method_missing(m, *args, &block)
6
+ if @CODES.include?(m.to_sym)
7
+ @CODES[m.to_sym]
8
+ else
9
+ raise 'Not a valid status!'
10
+ end
11
+ end
12
+
13
+ def lookup(code)
14
+ if @CODES.value?(code.to_i)
15
+ @CODES.key(code.to_i)
16
+ else
17
+ raise 'Not a valid code!'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module Cloudflare
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ unknown_error: 520,
9
+ web_server_is_down: 521,
10
+ connection_timed_out: 522,
11
+ origin_is_unreachable: 523,
12
+ a_timeout_occurred: 524,
13
+ ssl_handshake_failed: 525,
14
+ invalid_ssl_certificate: 526,
15
+ railgun_error: 527,
16
+ origin_dns_error: 530
17
+ }
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module Esri
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ invalid_token: 498,
9
+ token_required: 499
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module IIS
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ login_time_out: 440,
9
+ retry_with: 449,
10
+ redirect: 451
11
+ }
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module Microsoft
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ blocked_by_windows_parental_controls: 450
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module Nginx
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ no_response: 444,
9
+ request_header_too_large: 494,
10
+ ssl_certificate_error: 495,
11
+ ssl_certificate_required: 496,
12
+ http_request_sent_to_https_port: 497,
13
+ client_closed_request: 499
14
+ }
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module Pantheon
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ site_is_frozen: 530
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module Signal
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ network_read_timeout_error: 598
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module SpringFramework
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ method_failure: 420
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'response_code/base_imp'
2
+
3
+ module ResponseCode
4
+ module Twitter
5
+ extend ResponseCode::BaseImp
6
+
7
+ @CODES = {
8
+ enhance_your_calm: 420
9
+ }
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module ResponseCode
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: response_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Torok
@@ -21,8 +21,23 @@ files:
21
21
  - LICENSE
22
22
  - README.md
23
23
  - bin/response_code
24
+ - features/response_code.feature
25
+ - features/step_definitions/response_code_steps.rb
26
+ - features/step_definitions/unofficial_response_codes_steps.rb
24
27
  - lib/response_code.rb
28
+ - lib/response_code/aborted.rb
29
+ - lib/response_code/apache_web_server.rb
30
+ - lib/response_code/base_imp.rb
31
+ - lib/response_code/cloudflare.rb
25
32
  - lib/response_code/codes.rb
33
+ - lib/response_code/esri.rb
34
+ - lib/response_code/iis.rb
35
+ - lib/response_code/microsoft.rb
36
+ - lib/response_code/nginx.rb
37
+ - lib/response_code/pantheon.rb
38
+ - lib/response_code/signal.rb
39
+ - lib/response_code/spring_framework.rb
40
+ - lib/response_code/twitter.rb
26
41
  - lib/response_code/version.rb
27
42
  homepage: http://github.com/torokmark/response_code
28
43
  licenses:
@@ -36,16 +51,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
51
  requirements:
37
52
  - - ">="
38
53
  - !ruby/object:Gem::Version
39
- version: '0'
54
+ version: '2.0'
40
55
  required_rubygems_version: !ruby/object:Gem::Requirement
41
56
  requirements:
42
57
  - - ">="
43
58
  - !ruby/object:Gem::Version
44
59
  version: '0'
45
60
  requirements: []
46
- rubyforge_project:
47
- rubygems_version: 2.7.3
61
+ rubygems_version: 3.0.3
48
62
  signing_key:
49
63
  specification_version: 4
50
64
  summary: Readable way of response codes.
51
- test_files: []
65
+ test_files:
66
+ - features/step_definitions/response_code_steps.rb
67
+ - features/step_definitions/unofficial_response_codes_steps.rb
68
+ - features/response_code.feature