errors 0.0.1 → 0.0.2
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 +8 -8
- data/Gemfile.lock +2 -0
- data/README.md +17 -2
- data/errors.gemspec +1 -0
- data/lib/errors.rb +60 -5
- data/lib/errors/version.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDk0Yzg3MjM0ZjM3ZWY4MzZkN2I1NGYyNjBjNjcwMjdiZWNmNDhiOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzhmYzMzYzU1MTE0ZTg5MDE3NTk3MzEzMTJiZTRhNGUwYTIyZGFkOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Mzc2YTkzNTkzNTRjMWFlNjk0YmJjNTVkYmQ1M2NiOGZjYmQxZTVkMjRmNmYx
|
10
|
+
NTIzY2U4YmJhM2YwOTUyNmIyYmZhMzBhMzMyMmQxNTdkNGY1OWUwM2UzMzhk
|
11
|
+
MDcwZjdkYTQxY2JjZDVkOTdlYjcxYmQzYzU4MTA3ZmY4ZTg1NzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDRmNDlhMWZjMmE0NzI4ZmZiZjk1YWQxMjNmM2FhYmIyNDMzZDA1ZTI1Njg0
|
14
|
+
ZTkxYzE3ZWRkOWEzNjcxNGEwMGMzMzQ4NmQyMjY0ZWRkYjJkN2ZkY2M1M2Uw
|
15
|
+
MjVjODgyODMxY2ZlNzI2MmVkNTJkOTQzYTg1YzQ3YmFiY2E3ODM=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Errors
|
2
2
|
|
3
|
-
|
3
|
+
Handles HTTP status codes to give more detailed information.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,22 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
``error = Errors::Base.new(404)``
|
22
|
+
|
23
|
+
``error.code
|
24
|
+
=> 404``
|
25
|
+
|
26
|
+
``error.phrase
|
27
|
+
=> 'Not Found' ``
|
28
|
+
|
29
|
+
``error.description
|
30
|
+
=> indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists.``
|
31
|
+
|
32
|
+
``error.spec_title
|
33
|
+
=> RFC7231#6.5.4``
|
34
|
+
|
35
|
+
``error.spec_href
|
36
|
+
=> http://tools.ietf.org/html/rfc7231#section-6.5.4``
|
22
37
|
|
23
38
|
## Contributing
|
24
39
|
|
data/errors.gemspec
CHANGED
data/lib/errors.rb
CHANGED
@@ -1,11 +1,66 @@
|
|
1
|
-
require
|
1
|
+
require 'errors/version'
|
2
2
|
require 'multi_json'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'json'
|
3
5
|
|
4
6
|
module Errors
|
5
|
-
|
6
|
-
|
7
|
+
class Base
|
8
|
+
|
9
|
+
attr_accessor :data
|
10
|
+
|
11
|
+
def initialize(code=nil)
|
12
|
+
@code = code
|
13
|
+
read_file
|
14
|
+
end
|
15
|
+
|
16
|
+
def read_file
|
17
|
+
@data = JSON.parse(File.read("#{Dir.pwd}/lib/json/status-codes.json"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def code
|
21
|
+
@code
|
22
|
+
end
|
23
|
+
|
24
|
+
def phrase
|
25
|
+
result['phrase']
|
26
|
+
end
|
27
|
+
|
28
|
+
def description
|
29
|
+
result['description']
|
30
|
+
end
|
31
|
+
|
32
|
+
def spec_title
|
33
|
+
result['spec_title']
|
34
|
+
end
|
35
|
+
|
36
|
+
def spec_href
|
37
|
+
result['spec_href']
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def result
|
43
|
+
raise "Out of status code bounds, 100 to 799" if (@code < 100 || @code > 800)
|
44
|
+
result = @data.select {|d| d['code'] == @code.to_s }.first
|
45
|
+
if result.nil?
|
46
|
+
new_code = case @code
|
47
|
+
when 100..199
|
48
|
+
"1xx"
|
49
|
+
when 200.299
|
50
|
+
"2xx"
|
51
|
+
when 300.399
|
52
|
+
"3xx"
|
53
|
+
when 400..499
|
54
|
+
"4xx"
|
55
|
+
when 500..599
|
56
|
+
"5xx"
|
57
|
+
when 700..799
|
58
|
+
"7xx"
|
59
|
+
end
|
60
|
+
result = @data.select {|d| d['code'] == new_code }.first
|
61
|
+
end
|
62
|
+
result
|
63
|
+
end
|
7
64
|
|
8
|
-
def read_file
|
9
|
-
file = File.read('json/status-codes.json')
|
10
65
|
end
|
11
66
|
end
|
data/lib/errors/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -14,6 +14,8 @@
|
|
14
14
|
# users commonly want.
|
15
15
|
#
|
16
16
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
require_relative '../lib/errors.rb'
|
18
|
+
|
17
19
|
RSpec.configure do |config|
|
18
20
|
# The settings below are suggested to provide a good initial experience
|
19
21
|
# with RSpec, but feel free to customize to your heart's content.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|