errawr-http 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a055eb85e219338c01bf736c54b556909989d27b
4
+ data.tar.gz: 09ddfecf1fcbf432bc0481157d267412cbc2c734
5
+ SHA512:
6
+ metadata.gz: fab633ceb51111d24d305ae56e7f9987ba1770ba57544309c5601a6ed776a69abbbd176a23c2b0df0c2b7d4e81d617f37e8e75582e785816fb6d286573ed1d4f
7
+ data.tar.gz: f911558f263fb8384fc34426e07daa504fcb05cbe09b55ec945b098c3e5c46afb4772fd6ba81be2e5aa64c889d05a3cdbfe44d1712937ecf557d5e0f9e3592c8
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rbenv*
19
+ .rvmrc
20
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+ - jruby-19mode
7
+ - jruby-head
8
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in errawr-http.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Anthony Smith
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.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Errawr::HTTP
2
+
3
+ Raise 4xx and 5xx HTTP status code errors using Errawr.
4
+
5
+ [![Build Status](https://travis-ci.org/anthonator/errawr-http.png?branch=master)](https://travis-ci.org/anthonator/errawr-http) [![Dependency Status](https://gemnasium.com/anthonator/errawr-http.png)](https://gemnasium.com/anthonator/errawr-http) [![Coverage Status](https://coveralls.io/repos/anthonator/errawr-http/badge.png)](https://coveralls.io/r/anthonator/errawr-http) [![Code Climate](https://codeclimate.com/github/anthonator/errawr-http.png)](https://codeclimate.com/github/anthonator/errawr-http)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'errawr-http'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install errawr-http
20
+
21
+ ## Usage
22
+
23
+ ### Raise HTTP Error
24
+
25
+ ```ruby
26
+ begin
27
+ Errawr.error!(:bad_request)
28
+ rescue => e
29
+ puts e.message # => Will return "Bad Request"
30
+ puts e.context[:http_status] # => Will return 400
31
+ end
32
+ ```
33
+
34
+ ### Supported 4xx Status Codes
35
+
36
+ | Message | HTTP Status Code | Symbol |
37
+ | -------------------------------- | ---------------- | -------------------------------- |
38
+ | Bad Request | 400 | :bad_request |
39
+ | Unauthorized | 401 | :unauthorized |
40
+ | Payment Required | 402 | :payment_required |
41
+ | Forbidden | 403 | :forbidden |
42
+ | Not Found | 404 | :not_found |
43
+ | Method Not Allowed | 405 | :method_not_allowed |
44
+ | Not Acceptable | 406 | :not_acceptable |
45
+ | Proxy Authentication Required | 407 | :proxy_authentication_required |
46
+ | Request Timeout | 408 | :request_timeout |
47
+ | Conflict | 409 | :conflict |
48
+ | Gone | 410 | :gone |
49
+ | Length Required | 411 | :length_required |
50
+ | Precondition Failed | 412 | :precondition_failed |
51
+ | Request Entity Too Large | 413 | :request_entity_too_large |
52
+ | Request-URI Too Long | 414 | :request_uri_too_long |
53
+ | Unsupported Media Type | 415 | :unsupported_media_type |
54
+ | Request Range Not Satisfiable | 416 | :requested_range_not_satisfiable |
55
+ | Expectation Failed | 417 | :expectation_failed |
56
+ | Unprocessable Entity | 422 | :unprocessable_entity |
57
+ | Locked | 423 | :locked |
58
+ | Failed Dependency | 424 | :failed_dependency |
59
+ | Upgrade Required | 426 | :upgrade_required |
60
+ | Precondition Required | 428 | :precondition_required |
61
+ | Too Many Requests | 429 | :too_many_requests |
62
+ | Request Header Fields Too Large | 431 | :request_header_fields_too_large |
63
+
64
+ ### Supported 5xx Status Codes
65
+
66
+ | Message | HTTP Status Code | Symbol |
67
+ | -------------------------------- | ---------------- | -------------------------------- |
68
+ | Internal Server Error | 500 | :internal_server_error |
69
+ | Not Implemented | 501 | :not_implemented |
70
+ | Bad Gateway | 502 | :bad_gateway |
71
+ | Service Unavailable | 503 | :service_unavailable |
72
+ | Gateway Timeout | 504 | :gateway_timeout |
73
+ | HTTP Version Not Supported | 505 | :http_version_not_supported |
74
+ | Variant Also Negotiates | 506 | :variant_also_negotiates |
75
+ | Insufficient Storage | 507 | :insufficient_storage |
76
+ | Loop Detected | 508 | :loop_detected |
77
+ | Not Extended | 510 | :not_extended |
78
+ | Network Authentication Required | 511 | :network_authentication_required |
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork it
83
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
84
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
85
+ 4. Push to the branch (`git push origin my-new-feature`)
86
+ 5. Create new Pull Request
87
+
88
+ ## Credits
89
+
90
+ [![Sticksnleaves](http://sticksnleaves-wordpress.herokuapp.com/wp-content/themes/sticksnleaves/images/snl-logo-116x116.png)](http://www.sticksnleaves.com)
91
+
92
+ Errawr::HTTP is maintained and funded by [Sticksnleaves](http://www.sticksnleaves.com)
93
+
94
+ Thanks to all of our [contributors](https://github.com/anthonator/errawr-http/graphs/contributors)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'errawr/http/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'errawr-http'
8
+ spec.version = Errawr::HTTP::VERSION
9
+ spec.authors = ['Anthony Smith']
10
+ spec.email = ['anthony@sticksnleaves.com']
11
+ spec.description = %q{Raise 4xx and 5xx HTTP status code errors using Errawr}
12
+ spec.summary = %q{Predefined 4xx and 5xx HTTP status codes in Errawr}
13
+ spec.homepage = 'http://www.github.com/anthonator/errawr-http'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
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_runtime_dependency 'errawr', '>= 1.1'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec'
26
+ end
@@ -0,0 +1,110 @@
1
+ en:
2
+ errawr:
3
+ bad_request:
4
+ message: Bad Request
5
+ http_status: 400
6
+ unauthorized:
7
+ message: Unauthorized
8
+ http_status: 401
9
+ payment_required:
10
+ message: Payment Required
11
+ http_status: 402
12
+ forbidden:
13
+ message: Forbidden
14
+ http_status: 403
15
+ not_found:
16
+ message: Not Found
17
+ http_status: 404
18
+ method_not_allowed:
19
+ message: Method Not Allowed
20
+ http_status: 405
21
+ not_acceptable:
22
+ message: Not Acceptable
23
+ http_status: 406
24
+ proxy_authentication_required:
25
+ message: Proxy Authentication Required
26
+ http_status: 407
27
+ request_timeout:
28
+ message: Request Timeout
29
+ http_status: 408
30
+ conflict:
31
+ message: Conflict
32
+ http_status: 409
33
+ gone:
34
+ message: Gone
35
+ http_status: 410
36
+ length_required:
37
+ message: Length Required
38
+ http_status: 411
39
+ precondition_failed:
40
+ message: Precondition Failed
41
+ http_status: 412
42
+ request_entity_too_large:
43
+ message: Request Entity Too Large
44
+ http_status: 413
45
+ request_uri_too_long:
46
+ message: Request-URI Too Large
47
+ http_status: 414
48
+ unsupported_media_type:
49
+ message: Unsupported Media Type
50
+ http_status: 415
51
+ requested_range_not_satisfiable:
52
+ message: Requested Range Not Satisfiable
53
+ http_status: 416
54
+ expectation_failed:
55
+ message: Expectation Failed
56
+ http_status: 417
57
+ unprocessable_entity:
58
+ message: Unprocessable Entity
59
+ http_status: 422
60
+ locked:
61
+ message: Locked
62
+ http_status: 423
63
+ failed_dependency:
64
+ message: Failed Dependency
65
+ http_status: 424
66
+ upgrade_required:
67
+ message: Upgrade Required
68
+ http_status: 426
69
+ precondition_required:
70
+ message: Precondition Required
71
+ http_status: 428
72
+ too_many_requests:
73
+ message: Too Many Requests
74
+ http_status: 429
75
+ request_header_fields_too_large:
76
+ message: Request Header Fields Too Large
77
+ http_status: 431
78
+ internal_server_error:
79
+ message: Internal Server Error
80
+ http_status: 500
81
+ not_implemented:
82
+ message: Not Implemented
83
+ http_status: 501
84
+ bad_gateway:
85
+ message: Bad Gateway
86
+ http_status: 502
87
+ service_unavailable:
88
+ message: Service Unavailable
89
+ http_status: 503
90
+ gateway_timeout:
91
+ message: Gateway Timeout
92
+ http_status: 504
93
+ http_version_not_supported:
94
+ message: HTTP Version Not Supported
95
+ http_status: 505
96
+ variant_also_negotiates:
97
+ message: Variant Also Negotiates
98
+ http_status: 506
99
+ insufficient_storage:
100
+ message: Insufficient Storage
101
+ http_status: 507
102
+ loop_detected:
103
+ message: Loop Detected
104
+ http_status: 508
105
+ not_extended:
106
+ message: Not Extended
107
+ http_status: 510
108
+ network_authentication_required:
109
+ message: Network Authentication Required
110
+ http_status: 511
@@ -0,0 +1,5 @@
1
+ module Errawr
2
+ module HTTP
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ require 'errawr'
2
+
3
+ require 'errawr/http/version'
4
+
5
+ module Errawr
6
+ module HTTP
7
+ I18n.load_path += Dir.glob('lib/errawr/http/locale/*.{rb,yml}')
8
+ I18n.reload!
9
+
10
+ ERRORS_4XX = [
11
+ :bad_request,
12
+ :unauthorized,
13
+ :payment_required,
14
+ :forbidden,
15
+ :not_found,
16
+ :method_not_allowed,
17
+ :not_acceptable,
18
+ :proxy_authentication_required,
19
+ :request_timeout,
20
+ :conflict,
21
+ :gone,
22
+ :length_required,
23
+ :precondition_failed,
24
+ :request_entity_too_large,
25
+ :request_uri_too_long,
26
+ :unsupported_media_type,
27
+ :requested_range_not_satisfiable,
28
+ :expectation_failed,
29
+ :unprocessable_entity,
30
+ :locked,
31
+ :failed_dependency,
32
+ :upgrade_required,
33
+ :precondition_required,
34
+ :too_many_requests,
35
+ :request_header_fields_too_large
36
+ ]
37
+
38
+ ERRORS_5XX = [
39
+ :internal_server_error,
40
+ :not_implemented,
41
+ :bad_gateway,
42
+ :service_unavailable,
43
+ :gateway_timeout,
44
+ :http_version_not_supported,
45
+ :variant_also_negotiates,
46
+ :insufficient_storage,
47
+ :loop_detected,
48
+ :not_extended,
49
+ :network_authentication_required
50
+ ]
51
+
52
+ ERRORS_4XX.each do |e|
53
+ Errawr.register!(e)
54
+ end
55
+
56
+ ERRORS_5XX.each do |e|
57
+ Errawr.register!(e)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe Errawr::HTTP do
4
+ ERRORS_4XX = [
5
+ [400, :bad_request],
6
+ [401, :unauthorized],
7
+ [402, :payment_required],
8
+ [403, :forbidden],
9
+ [404, :not_found],
10
+ [405, :method_not_allowed],
11
+ [406, :not_acceptable],
12
+ [407, :proxy_authentication_required],
13
+ [408, :request_timeout],
14
+ [409, :conflict],
15
+ [410, :gone],
16
+ [411, :length_required],
17
+ [412, :precondition_failed],
18
+ [413, :request_entity_too_large],
19
+ [414, :request_uri_too_long],
20
+ [415, :unsupported_media_type],
21
+ [416, :requested_range_not_satisfiable],
22
+ [417, :expectation_failed],
23
+ [422, :unprocessable_entity],
24
+ [423, :locked],
25
+ [424, :failed_dependency],
26
+ [426, :upgrade_required],
27
+ [428, :precondition_required],
28
+ [429, :too_many_requests],
29
+ [431, :request_header_fields_too_large]
30
+ ]
31
+
32
+ ERRORS_5XX = [
33
+ [500, :internal_server_error],
34
+ [501, :not_implemented],
35
+ [502, :bad_gateway],
36
+ [503, :service_unavailable],
37
+ [504, :gateway_timeout],
38
+ [505, :http_version_not_supported],
39
+ [506, :variant_also_negotiates],
40
+ [507, :insufficient_storage],
41
+ [508, :loop_detected],
42
+ [510, :not_extended],
43
+ [511, :network_authentication_required]
44
+ ]
45
+
46
+ ERRORS_4XX.each do |error|
47
+ it "should define 4XX error #{error[0]}" do
48
+ begin
49
+ Errawr.error!(error[1])
50
+ rescue => e
51
+ e.context[:http_status].should == error[0]
52
+ end
53
+ end
54
+ end
55
+
56
+ ERRORS_5XX.each do |error|
57
+ it "should define 5XX error #{error[0]}" do
58
+ begin
59
+ Errawr.error!(error[1])
60
+ rescue => e
61
+ e.context[:http_status].should == error[0]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,8 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'errawr/http'
5
+
6
+ # Require supporting ruby files with custom matchers and macros, etc,
7
+ # in spec/support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: errawr-http
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: errawr
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Raise 4xx and 5xx HTTP status code errors using Errawr
70
+ email:
71
+ - anthony@sticksnleaves.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - errawr-http.gemspec
83
+ - lib/errawr/http.rb
84
+ - lib/errawr/http/locale/en.yml
85
+ - lib/errawr/http/version.rb
86
+ - spec/errawr_http_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: http://www.github.com/anthonator/errawr-http
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Predefined 4xx and 5xx HTTP status codes in Errawr
112
+ test_files:
113
+ - spec/errawr_http_spec.rb
114
+ - spec/spec_helper.rb