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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGRmZmFhMTkwMmI5NzAzMWZkMDYzMmQ1ZmQ4MWQ1NWM3OTI5YzI3Nw==
4
+ NDk0Yzg3MjM0ZjM3ZWY4MzZkN2I1NGYyNjBjNjcwMjdiZWNmNDhiOQ==
5
5
  data.tar.gz: !binary |-
6
- OTRkYTkzY2FkYzJlNGFhZTdjMGEzOTI3ODU0ZTg3NzdlZDVkMDEwNg==
6
+ NzhmYzMzYzU1MTE0ZTg5MDE3NTk3MzEzMTJiZTRhNGUwYTIyZGFkOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTMwNzE0NDhjZTM3YWZhODllM2MzYzZiYmJjOGM1MjQxNjNkMDczYzJkYWQw
10
- NWY2ODY1Mzc0ZmI2ZDFjMWNjZTIwYzQxMjA5Mzk2NzE3NDhkNDRhMWZlZTUx
11
- NzRjYzc5Nzk2NjQ3ZDZjOTNiYTg4M2U2NWRhMDk4YmQzNDkzOTE=
9
+ Mzc2YTkzNTkzNTRjMWFlNjk0YmJjNTVkYmQ1M2NiOGZjYmQxZTVkMjRmNmYx
10
+ NTIzY2U4YmJhM2YwOTUyNmIyYmZhMzBhMzMyMmQxNTdkNGY1OWUwM2UzMzhk
11
+ MDcwZjdkYTQxY2JjZDVkOTdlYjcxYmQzYzU4MTA3ZmY4ZTg1NzQ=
12
12
  data.tar.gz: !binary |-
13
- MTk3ZjE1NzVmMTQ4MWFmMzhlMDE3YTM0NmE5NDRmYzcyZTEwMGFiYzVlNTZh
14
- YmQyMGZkYjAyNzZlZGM2Y2RiM2JlMzhhNTk0MzgyZDhiZDc0NDEwODU5ZjYw
15
- YWY0MDcxODhmNTZjN2NjNjU4ZWNlNzY1NGVlZTRiNzExMTU3MzE=
13
+ MDRmNDlhMWZjMmE0NzI4ZmZiZjk1YWQxMjNmM2FhYmIyNDMzZDA1ZTI1Njg0
14
+ ZTkxYzE3ZWRkOWEzNjcxNGEwMGMzMzQ4NmQyMjY0ZWRkYjJkN2ZkY2M1M2Uw
15
+ MjVjODgyODMxY2ZlNzI2MmVkNTJkOTQzYTg1YzQ3YmFiY2E3ODM=
@@ -2,12 +2,14 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  errors (0.0.1)
5
+ json
5
6
  multi_json
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  diff-lcs (1.2.5)
12
+ json (1.8.1)
11
13
  multi_json (1.10.1)
12
14
  rake (10.3.2)
13
15
  rspec (3.0.0)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Errors
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
 
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency 'multi_json'
22
+ spec.add_runtime_dependency 'json'
22
23
 
23
24
  spec.add_development_dependency 'bundler', '~> 1.6'
24
25
  spec.add_development_dependency 'rake'
@@ -1,11 +1,66 @@
1
- require "errors/version"
1
+ require 'errors/version'
2
2
  require 'multi_json'
3
+ require 'ostruct'
4
+ require 'json'
3
5
 
4
6
  module Errors
5
- def initalise
6
- end
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
@@ -1,3 +1,3 @@
1
1
  module Errors
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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.1
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-04 00:00:00.000000000 Z
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