httpcode 1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in httpcode.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Misha Conway
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,106 @@
1
+ ## Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ gem 'httpcode'
6
+
7
+ Or install it yourself as:
8
+
9
+ $ gem install httpcode
10
+
11
+ ## Usage
12
+
13
+ Allows you to specify http status codes by name rather than magic numbers for more readable code.
14
+
15
+ Example:
16
+ HttpStatus.created.code or HttpStatus.not_modified.code
17
+
18
+ More Examples:
19
+ status = HttpStatus.accepted
20
+ => #<StatusCode:0x007fb85403e1c0 @code=202, @message="Accepted", @symbol=:accepted>
21
+ status.code
22
+ => 202
23
+ status.message
24
+ => "Accepted"
25
+ status.code_and_message
26
+ => [202, "Accepted"]
27
+
28
+ If you know the number of the status code, but are not sure what function to call you can use from_code.
29
+ Last Example:
30
+ We know we want to use the 200 code, but not sure what function to call.
31
+
32
+ status = HttpStatus.from_code 200
33
+ => #<StatusCode:0x007fb85403e2b0 @code=200, @message="OK", @symbol=:ok>
34
+ status.symbol
35
+ => :ok
36
+
37
+ Now we know that we can call HttpStatus.ok
38
+
39
+ ## Full list of statuses you can call:
40
+ HttpStatus.continue
41
+ HttpStatus.switching_protocols
42
+ HttpStatus.processing
43
+ HttpStatus.ok
44
+ HttpStatus.created
45
+ HttpStatus.accepted
46
+ HttpStatus.non_authoritative_information
47
+ HttpStatus.no_content
48
+ HttpStatus.reset_content
49
+ HttpStatus.partial_content
50
+ HttpStatus.multi_status
51
+ HttpStatus.im_used
52
+ HttpStatus.multiple_choices
53
+ HttpStatus.moved_permanently
54
+ HttpStatus.found
55
+ HttpStatus.see_other
56
+ HttpStatus.not_modified
57
+ HttpStatus.use_proxy
58
+ HttpStatus.reserved
59
+ HttpStatus.temporary_redirect
60
+ HttpStatus.bad_request
61
+ HttpStatus.unauthorized
62
+ HttpStatus.payment_required
63
+ HttpStatus.forbidden
64
+ HttpStatus.not_found
65
+ HttpStatus.method_not_allowed
66
+ HttpStatus.not_acceptable
67
+ HttpStatus.proxy_authentication_required
68
+ HttpStatus.request_timeout
69
+ HttpStatus.conflict
70
+ HttpStatus.gone
71
+ HttpStatus.length_required
72
+ HttpStatus.precondition_failed
73
+ HttpStatus.request_entity_too_large
74
+ HttpStatus.request_uri_too_long
75
+ HttpStatus.unsupported_media_type
76
+ HttpStatus.requested_range_not_satisfiable
77
+ HttpStatus.expectation_failed
78
+ HttpStatus.im_a_teapot
79
+ HttpStatus.unprocessable_entity
80
+ HttpStatus.locked
81
+ HttpStatus.failed_dependency
82
+ HttpStatus.upgrade_required
83
+ HttpStatus.internal_server_error
84
+ HttpStatus.not_implemented
85
+ HttpStatus.bad_gateway
86
+ HttpStatus.service_unavailable
87
+ HttpStatus.gateway_timeout
88
+ HttpStatus.http_version_not_supported
89
+ HttpStatus.variant_also_negotiates
90
+ HttpStatus.insufficient_storage
91
+ HttpStatus.not_extended
92
+
93
+ ## Additional methods
94
+ HttpStatus.valid_codes
95
+ HttpStatus.from_code http_status_code
96
+
97
+
98
+
99
+
100
+ ## Contributing
101
+
102
+ 1. Fork it
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
105
+ 4. Push to the branch (`git push origin my-new-feature`)
106
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/httpcode.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'httpcode/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "httpcode"
8
+ gem.version = Httpcode::VERSION
9
+ gem.authors = ["Misha Conway"]
10
+ gem.email = ["MishaAConway@gmail.com"]
11
+
12
+
13
+ gem.summary = %q{Allows you to specify http status codes by name rather than magic numbers for more readable code.
14
+ Go to https://github.com/MishaConway/httpcode for detailed examples.}
15
+ gem.homepage = "https://github.com/MishaConway/httpcode"
16
+
17
+ gem.files = `git ls-files`.split($/)
18
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
19
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
20
+ gem.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,3 @@
1
+ module Httpcode
2
+ VERSION = "1.2"
3
+ end
data/lib/httpcode.rb ADDED
@@ -0,0 +1,138 @@
1
+ require "httpcode/version"
2
+
3
+ class StatusCode
4
+ attr_reader :symbol, :code, :message
5
+
6
+ def initialize symbol, code, message
7
+ @symbol, @code, @message = symbol, code, message
8
+ end
9
+
10
+ def code_and_message
11
+ [code, message]
12
+ end
13
+
14
+ def to_i
15
+ code
16
+ end
17
+
18
+ #def to_s
19
+ # code.to_s
20
+ #end
21
+ end
22
+
23
+ class HttpStatus
24
+ def self.valid_codes
25
+ [:continue,
26
+ :switching_protocols,
27
+ :processing,
28
+ :ok,
29
+ :created,
30
+ :accepted,
31
+ :non_authoritative_information,
32
+ :no_content,
33
+ :reset_content,
34
+ :partial_content,
35
+ :multi_status,
36
+ :im_used,
37
+ :multiple_choices,
38
+ :moved_permanently,
39
+ :found,
40
+ :see_other,
41
+ :not_modified,
42
+ :use_proxy,
43
+ :reserved,
44
+ :temporary_redirect,
45
+ :bad_request,
46
+ :unauthorized,
47
+ :payment_required,
48
+ :forbidden,
49
+ :not_found,
50
+ :method_not_allowed,
51
+ :not_acceptable,
52
+ :proxy_authentication_required,
53
+ :request_timeout,
54
+ :conflict,
55
+ :gone,
56
+ :length_required,
57
+ :precondition_failed,
58
+ :request_entity_too_large,
59
+ :request_uri_too_long,
60
+ :unsupported_media_type,
61
+ :requested_range_not_satisfiable,
62
+ :expectation_failed,
63
+ :im_a_teapot,
64
+ :unprocessable_entity,
65
+ :locked,
66
+ :failed_dependency,
67
+ :upgrade_required,
68
+ :internal_server_error,
69
+ :not_implemented,
70
+ :bad_gateway,
71
+ :service_unavailable,
72
+ :gateway_timeout,
73
+ :http_version_not_supported,
74
+ :variant_also_negotiates,
75
+ :insufficient_storage,
76
+ :not_extended]
77
+ end
78
+ valid_codes.each { |c| cattr_reader c }
79
+
80
+ def self.from_code code
81
+ valid_codes.each{ |c| return send(c) if send(c).code == code }
82
+ nil
83
+ end
84
+
85
+ @@continue= StatusCode.new :continue, 100, 'Continue'
86
+ @@switching_protocols= StatusCode.new :switching_protocols, 101, 'Switching Protocols'
87
+ @@processing= StatusCode.new :processing, 102, 'Processing'
88
+ @@ok= StatusCode.new :ok, 200, 'OK'
89
+ @@created= StatusCode.new :created, 201, 'Created'
90
+ @@accepted= StatusCode.new :accepted, 202, 'Accepted'
91
+ @@non_authoritative_information= StatusCode.new :non_authoritative_information, 203, 'Non-Authoritative Information'
92
+ @@no_content= StatusCode.new :no_content, 204, 'No Content'
93
+ @@reset_content= StatusCode.new :reset_content, 205, 'Reset Content'
94
+ @@partial_content= StatusCode.new :partial_content, 206, 'Partial Content'
95
+ @@multi_status= StatusCode.new :multi_status, 207, 'Multi-Status'
96
+ @@im_used= StatusCode.new :im_used, 226, 'IM Used'
97
+ @@multiple_choices= StatusCode.new :multiple_choices, 300, 'Multiple Choices'
98
+ @@moved_permanently= StatusCode.new :moved_permanently, 301, 'Moved Permanently'
99
+ @@found= StatusCode.new :found, 302, 'Found'
100
+ @@see_other= StatusCode.new :see_other, 303, 'See Other'
101
+ @@not_modified= StatusCode.new :not_modified, 304, 'Not Modified'
102
+ @@use_proxy= StatusCode.new :use_proxy, 305, 'Use Proxy'
103
+ @@reserved= StatusCode.new :reserved, 306, 'Reserved'
104
+ @@temporary_redirect= StatusCode.new :temporary_redirect, 307, 'Temporary Redirect'
105
+ @@bad_request= StatusCode.new :bad_request, 400, 'Bad Request'
106
+ @@unauthorized= StatusCode.new :unauthorized, 401, 'Unauthorized'
107
+ @@payment_required= StatusCode.new :payment_required, 402, 'Payment Required'
108
+ @@forbidden= StatusCode.new :forbidden, 403, 'Forbidden'
109
+ @@not_found= StatusCode.new :not_found, 404, 'Not Found'
110
+ @@method_not_allowed= StatusCode.new :method_not_allowed, 405, 'Method Not Allowed'
111
+ @@not_acceptable= StatusCode.new :not_acceptable, 406, 'Not Acceptable'
112
+ @@proxy_authentication_required= StatusCode.new :proxy_authentication_required, 407, 'Proxy Authentication Required'
113
+ @@request_timeout= StatusCode.new :request_timeout, 408, 'Request Timeout'
114
+ @@conflict= StatusCode.new :conflict, 409, 'Conflict'
115
+ @@gone= StatusCode.new :gone, 410, 'Gone'
116
+ @@length_required= StatusCode.new :length_required, 411, 'Length Required'
117
+ @@precondition_failed= StatusCode.new :precondition_failed, 412, 'Precondition Failed'
118
+ @@request_entity_too_large= StatusCode.new :request_entity_too_large, 413, 'Request Entity Too Large'
119
+ @@request_uri_too_long= StatusCode.new :request_uri_too_long, 414, 'Request-URI Too Long'
120
+ @@unsupported_media_type= StatusCode.new :unsupported_media_type, 415, 'Unsupported Media Type'
121
+ @@requested_range_not_satisfiable= StatusCode.new :requested_range_not_satisfiable, 416, 'Requested Range Not Satisfiable'
122
+ @@expectation_failed= StatusCode.new :expectation_failed, 417, 'Expectation Failed'
123
+ @@im_a_teapot= StatusCode.new :im_a_teapot, 418, "I'm a Teapot"
124
+ @@unprocessable_entity= StatusCode.new :unprocessable_entity, 422, 'Unprocessable Entity'
125
+ @@locked= StatusCode.new :locked, 423, 'Locked'
126
+ @@failed_dependency= StatusCode.new :failed_dependency, 424, 'Failed Dependency'
127
+ @@upgrade_required= StatusCode.new :upgrade_required, 426, 'Upgrade Required'
128
+ @@internal_server_error= StatusCode.new :internal_server_error, 500, 'Internal Server Error'
129
+ @@not_implemented= StatusCode.new :not_implemented, 501, 'Not Implemented'
130
+ @@bad_gateway= StatusCode.new :bad_gateway, 502, 'Bad Gateway'
131
+ @@service_unavailable= StatusCode.new :service_unavailable, 503, 'Service Unavailable'
132
+ @@gateway_timeout= StatusCode.new :gateway_timeout, 504, 'Gateway Timeout'
133
+ @@http_version_not_supported= StatusCode.new :http_version_not_supported, 505, 'HTTP Version Not Supported'
134
+ @@variant_also_negotiates= StatusCode.new :variant_also_negotiates, 506, 'Variant Also Negotiates'
135
+ @@insufficient_storage= StatusCode.new :insufficient_storage, 507, 'Insufficient Storage'
136
+ @@not_extended= StatusCode.new :not_extended, 510, 'Not Extended'
137
+
138
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httpcode
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.2'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Misha Conway
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ - MishaAConway@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - httpcode.gemspec
27
+ - lib/httpcode.rb
28
+ - lib/httpcode/version.rb
29
+ homepage: https://github.com/MishaConway/httpcode
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ none: false
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ none: false
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Allows you to specify http status codes by name rather than magic numbers
53
+ for more readable code. Go to https://github.com/MishaConway/httpcode for detailed
54
+ examples.
55
+ test_files: []