hscode 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: a277d28d6132a0415c01cfc8b34c1fd236ec6650
4
- data.tar.gz: 80107dbdbe3569c6af08d8a31a337a07cb9c02cd
3
+ metadata.gz: 8ba75b84c873bd24488f57b3ba9495adde410f6c
4
+ data.tar.gz: 44e49b551d43c3e925854c295441c5bf8704bbaf
5
5
  SHA512:
6
- metadata.gz: c235ef44e741370fd0e5aea54b146615ddd61962140151e4afecfda38df0f5c177a4e66c4f4a17884e17bf9b14486fa947e2716309a851b19e931b574d3f65b9
7
- data.tar.gz: 6e02f4426fc6e10d7392a17479215b5dfc0764c9a66b38b95d6aded5e430b291c2227bd51b1abb03e194ef9c5496b3e79bc7efe3782e6bcd78a1fee06842d4e6
6
+ metadata.gz: 288bbe23d7491261b40f1333da46adeed05b577d9753374e48edb389b919805e5be8ae8d3a912a4a53d5cee00ae77bb34cd58f2222f562b37b1b0db5c77ffd75
7
+ data.tar.gz: ac59a9eefb2f3104603f62c98f6ad336238e57582a4565a5d43c9875c7d83af73162d28c3c7e32c3ec0069e6b0083c7384d6c74a527967b5d1e22e01b59f6eb5
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  /config/env.yaml
11
11
  /*.gem
12
+ test.log
@@ -1,6 +1,7 @@
1
1
  require 'hscode/version'
2
2
  require 'hscode/input_parser'
3
3
  require 'hscode/http_status_codes'
4
+ require 'hscode/status_code_types'
4
5
  require 'optparse'
5
6
  require 'ostruct'
6
7
 
@@ -18,7 +19,7 @@ module Hscode
18
19
 
19
20
  unless status_code
20
21
  puts "#{options.status_code} is not a valid code. See 'hscode --help'."
21
- exit
22
+ exit 1
22
23
  end
23
24
 
24
25
  PrettyPrint.print(
@@ -52,8 +52,11 @@ module Hscode
52
52
  end
53
53
 
54
54
  def list_status_codes(opts)
55
- opts.on('-l', '--list', 'List all HTTP status codes') do
56
- print_all_codes
55
+ opts.on('-l', '--list [TYPE]',
56
+ 'List all HTTP status codes of type') do |type|
57
+ print_all_codes unless type
58
+ options.status_type = type
59
+ print_all_codes_by_type(type)
57
60
  end
58
61
  end
59
62
 
@@ -63,6 +66,7 @@ module Hscode
63
66
  hscode -c 200
64
67
  hscode -c 200 -v
65
68
  hscode -l
69
+ hscode -l 2xx
66
70
  '
67
71
  exit
68
72
  end
@@ -75,6 +79,31 @@ module Hscode
75
79
  end
76
80
  end
77
81
 
82
+ def print_all_codes_by_type(type)
83
+ unless type =~ /\A[1-5]x{2}\z/
84
+ abort "#{type} is not a valid code type. See 'hscode --help'."
85
+ end
86
+
87
+ colour_code = type.to_s[0]
88
+ PrettyPrint.print("#{type} #{STATUS_CODE_TYPES[type]}\n", colour_code)
89
+
90
+ process_code_type(type, colour_code)
91
+ end
92
+
93
+ def process_code_type(type, colour)
94
+ code_type_group(type).map do |code, info_hash|
95
+ PrettyPrint.print("#{code} - #{info_hash[:title]}", colour)
96
+ end
97
+
98
+ exit
99
+ end
100
+
101
+ def code_type_group(type)
102
+ HTTP_STATUS_CODES.select do |code, _|
103
+ type.start_with? code.to_s[0]
104
+ end
105
+ end
106
+
78
107
  def print_all_codes
79
108
  HTTP_STATUS_CODES.map do |code, info_hash|
80
109
  colour_code = code.to_s[0]
@@ -0,0 +1,9 @@
1
+ module Hscode
2
+ STATUS_CODE_TYPES = {
3
+ '1xx' => 'Informational',
4
+ '2xx' => 'Sucess',
5
+ '3xx' => 'Redirection',
6
+ '4xx' => 'Client Error',
7
+ '5xx' => 'Server Error'
8
+ }.freeze
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Hscode
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hscode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Herbert Kagumba
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-03-03 00:00:00.000000000 Z
12
+ date: 2017-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -206,6 +206,7 @@ files:
206
206
  - lib/hscode/http_status_codes.rb
207
207
  - lib/hscode/input_parser.rb
208
208
  - lib/hscode/pretty_print.rb
209
+ - lib/hscode/status_code_types.rb
209
210
  - lib/hscode/version.rb
210
211
  homepage: https://akabiru.github.io/hscode/
211
212
  licenses: