pstatus 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d61c948a7052d86b183c9c56a886a542ee6fe78d
4
+ data.tar.gz: 36e549b0762af3fd889a0d11f3ea7754366c8a61
5
+ SHA512:
6
+ metadata.gz: 51ab42cacdff9e65d468748eb5f45e1d966523b85a2365e7ba07d555eacf1ed2591557285851033c812ecf119565aa5d48b3d73a244cfd6f729d69344638ec7c
7
+ data.tar.gz: 7def15aa7df0bf663db90ed1059252518175bb8da33ae6958ed7b89e5ffa467a0218a09d91ee94d8583a39af7c08948b1d3d68297f8127d233f2443e35693682
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - 2.0.0
6
+
7
+ script: 'bundle exec rake'
8
+
9
+ notifications:
10
+ email:
11
+ recipients:
12
+ - vinh.nguyenlexuan@asnet.com.vn
13
+ on_failure: change
14
+ on_success: change
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pstatus.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Vinh Nguyen Le
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.
@@ -0,0 +1,32 @@
1
+ # Pstatus
2
+
3
+ Display the HTTP Status messages.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pstatus'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pstatus
20
+
21
+ ## Usage
22
+
23
+ $ Pstatus.get_status_msg(200) # OK
24
+ $ Pstatus.get_status_msg(201) # Created
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( https://github.com/vinhnguyenleasnet/pstatus/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,30 @@
1
+ require "pstatus/version/version"
2
+ require "pstatus/core"
3
+
4
+ module Pstatus
5
+
6
+ MESSAGE = {200 => "OK", 201 => "Created", 202 => "Accepted", 203 => "Non-Authoritative Information",
7
+ 204 => "No Content", 205 => "Reset Content", 206 => "Partial Content",
8
+ 207 => "Multi-Status (WebDAV)", 208 => "Already Reported (WebDAV)", 226 => "IM Used",
9
+ 100 => "Continue", 101 => "Switching Protocols", 102 => "Processing (WebDAV)",
10
+ 300 => "Multiple Choices", 301 => "Moved Permanently", 302 => "Found",
11
+ 303 => "See Other", 304 => "Not Modified", 305 => "Use Proxy",
12
+ 307 => "Temporary Redirect", 308 => "Permanent Redirect (experiemental)",
13
+ 400 => "Bad Request", 401 => "Unauthorized", 402 => "Payment Required", 403 => "Forbidden",
14
+ 404 => "Not Found", 405 => "Method Not Allowed", 406 => "Not Acceptable", 407 => "Proxy Authentication Required",
15
+ 408 => "Request Timeout", 409 => "Conflict", 410 => "Gone", 411 => "Length Required", 412 => "Precondition Failed",
16
+ 413 => "Request Entity Too Large", 414 => "Request-URI Too Long", 415 => "Unsupported Media Type",
17
+ 416 => "Requested Range Not Satisfiable", 417 => "Expectation Failed", 418 => "I'm a teapot (RFC 2324)",
18
+ 420 => "Enhance Your Calm (Twitter)", 422 => "Unprocessable Entity (WebDAV)", 423 => "Locked (WebDAV)",
19
+ 424 => "Failed Dependency (WebDAV)", 425 => "Reserved for WebDAV", 426 => "Upgrade Required", 428 => "Precondition Required",
20
+ 429 => "Too Many Requests", 431 => "Request Header Fields Too Large", 444 => "No Response (Nginx)", 449 => "Retry With (Microsoft)",
21
+ 450 => "Blocked by Windows Parental Controls (Microsoft)", 499 => "Client Closed Request (Nginx)",
22
+ 500 => "Internal Server Error", 501 => "Not Implemented", 502 => "Bad Gateway", 503 => "Service Unavailable",
23
+ 504 => "Gateway Timeout", 505 => "HTTP Version Not Supported", 506 => "Variant Also Negotiates (Experimental)",
24
+ 507 => "Insufficient Storage (WebDAV)", 508 => "Loop Detected (WebDAV)", 509 => "Bandwidth Limit Exceeded (Apache)",
25
+ 510 => "Not Extended", 511 => "Authentication Required", 598 => "Network read timeout error", 599 => "Network connect timeout error"}
26
+
27
+ def self.get_status_msg status_code
28
+ PrettyStatus.new(status_code).get_status_msg
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ module Pstatus
2
+ class PrettyStatus
3
+
4
+ def initialize status_code
5
+ @status_code = status_code
6
+ end
7
+
8
+ def get_status_msg
9
+ if @status_code
10
+ if Pstatus::MESSAGE[@status_code.to_i]
11
+ return Pstatus::MESSAGE[@status_code.to_i]
12
+ else
13
+ raise("This status code does not exist. Please check again!")
14
+ end
15
+ else
16
+ raise("Missing parameter status_code.")
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Pstatus
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pstatus/version/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pstatus"
8
+ spec.version = Pstatus::VERSION
9
+ spec.authors = ["Vinh Nguyen Le"]
10
+ spec.email = ["vinh.nguyenlexuan@asnet.com.vn"]
11
+ spec.summary = %q{Display http status message.}
12
+ spec.description = %q{A gem support display http status message.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2.0"
24
+ end
@@ -0,0 +1,74 @@
1
+ require "spec_helper"
2
+
3
+ describe Pstatus do
4
+ let(:success){[200, 201, 202, 203, 204, 205, 206, 207, 208, 226]}
5
+ let(:success_message) { ["OK", "Created", "Accepted", "Non-Authoritative Information",
6
+ "No Content", "Reset Content", "Partial Content",
7
+ "Multi-Status (WebDAV)", "Already Reported (WebDAV)", "IM Used"] }
8
+
9
+ let(:information) { [100, 101, 102] }
10
+ let(:information_message) { ["Continue", "Switching Protocols", "Processing (WebDAV)"] }
11
+
12
+ let(:redirection) { [300, 301, 302, 303, 304, 305, 307, 308] }
13
+ let(:redirection_message) { ["Multiple Choices", "Moved Permanently", "Found",
14
+ "See Other", "Not Modified", "Use Proxy",
15
+ "Temporary Redirect", "Permanent Redirect (experiemental)"] }
16
+
17
+ let(:client) { [400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410,
18
+ 411, 412, 413, 414, 415, 416, 417, 418, 420, 422, 423,
19
+ 424, 425, 426, 428, 429, 431, 444, 449, 450, 499] }
20
+ let(:client_message) { ["Bad Request", "Unauthorized", "Payment Required", "Forbidden",
21
+ "Not Found", "Method Not Allowed", "Not Acceptable", "Proxy Authentication Required",
22
+ "Request Timeout", "Conflict", "Gone", "Length Required", "Precondition Failed",
23
+ "Request Entity Too Large", "Request-URI Too Long", "Unsupported Media Type",
24
+ "Requested Range Not Satisfiable", "Expectation Failed", "I'm a teapot (RFC 2324)",
25
+ "Enhance Your Calm (Twitter)", "Unprocessable Entity (WebDAV)", "Locked (WebDAV)",
26
+ "Failed Dependency (WebDAV)", "Reserved for WebDAV", "Upgrade Required", "Precondition Required",
27
+ "Too Many Requests", "Request Header Fields Too Large", "No Response (Nginx)", "Retry With (Microsoft)",
28
+ "Blocked by Windows Parental Controls (Microsoft)", "Client Closed Request (Nginx)"] }
29
+
30
+ let(:server) { [500, 501, 502, 503, 504, 505, 506, 507, 508, 509,
31
+ 510, 511, 598, 599] }
32
+ let(:server_message) { ["Internal Server Error", "Not Implemented", "Bad Gateway", "Service Unavailable",
33
+ "Gateway Timeout", "HTTP Version Not Supported", "Variant Also Negotiates (Experimental)",
34
+ "Insufficient Storage (WebDAV)", "Loop Detected (WebDAV)", "Bandwidth Limit Exceeded (Apache)",
35
+ "Not Extended", "Authentication Required", "Network read timeout error", "Network connect timeout error"] }
36
+
37
+ it "should raise an error if the status_code is missing" do
38
+ expect{Pstatus.get_status_msg(nil)}.to raise_error("Missing parameter status_code.")
39
+ end
40
+
41
+ it "should raise an error if the status_code does not exist" do
42
+ expect{Pstatus.get_status_msg(4042)}.to raise_error("This status code does not exist. Please check again!")
43
+ end
44
+
45
+ it "should display the success messages" do
46
+ success.each_with_index do |s, i|
47
+ expect(Pstatus.get_status_msg(s)).to eq(success_message[i])
48
+ end
49
+ end
50
+
51
+ it "should display the information messages" do
52
+ information.each_with_index do |s, i|
53
+ expect(Pstatus.get_status_msg(s)).to eq(information_message[i])
54
+ end
55
+ end
56
+
57
+ it "should display the redirection_messages" do
58
+ redirection.each_with_index do |s, i|
59
+ expect(Pstatus.get_status_msg(s)).to eq(redirection_message[i])
60
+ end
61
+ end
62
+
63
+ it "should display the client messages" do
64
+ client.each_with_index do |s, i|
65
+ expect(Pstatus.get_status_msg(s)).to eq(client_message[i])
66
+ end
67
+ end
68
+
69
+ it "should display the server messages" do
70
+ server.each_with_index do |s, i|
71
+ expect(Pstatus.get_status_msg(s)).to eq(server_message[i])
72
+ end
73
+ end
74
+ end
@@ -0,0 +1 @@
1
+ require "pstatus"
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pstatus
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vinh Nguyen Le
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-08 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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ description: A gem support display http status message.
56
+ email:
57
+ - vinh.nguyenlexuan@asnet.com.vn
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/pstatus.rb
69
+ - lib/pstatus/core.rb
70
+ - lib/pstatus/version/version.rb
71
+ - pstatus.gemspec
72
+ - spec/lib/pstatus_spec.rb
73
+ - spec/spec_helper.rb
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Display http status message.
98
+ test_files:
99
+ - spec/lib/pstatus_spec.rb
100
+ - spec/spec_helper.rb