Class: Typed::HTTP::StatusCode
- Inherits:
-
T::Enum
- Object
- T::Enum
- Typed::HTTP::StatusCode
- Extended by:
- T::Sig
- Defined in:
- lib/typed/http/status_code.rb
Overview
Enumerates all valid HTTP response status codes and provides conversion and convenience methods.
Class Method Summary collapse
- .from_i(int) ⇒ Object (also: from_code)
Instance Method Summary collapse
- #client_error? ⇒ Boolean
- #informational? ⇒ Boolean
- #redirection? ⇒ Boolean
- #server_error? ⇒ Boolean
- #successful? ⇒ Boolean
- #to_i ⇒ Object (also: #to_code)
Class Method Details
.from_i(int) ⇒ Object Also known as: from_code
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/typed/http/status_code.rb', line 81 def from_i(int) case int when 100 Continue when 101 SwitchingProtocols when 102 Processing when 103 EarlyHints when 200 OK when 201 Created when 202 Accepted when 203 NonAuthoritativeInformation when 204 NoContent when 205 ResetContent when 206 PartialContent when 300 MultipleChoices when 301 MovedPermanently when 302 Found when 303 SeeOther when 304 NotModified when 307 TemporaryRedirect when 308 PermanentRedirect when 400 BadRequest when 401 Unauthorized when 402 PaymentRequired when 403 Forbidden when 404 NotFound when 405 MethodNotAllowed when 406 NotAcceptable when 407 ProxyAuthenticationRequired when 408 RequestTimeout when 409 Conflict when 410 Gone when 411 LengthRequired when 412 PreconditionFailed when 413 ContentTooLarge when 414 URITooLong when 415 UnsupportedMediaType when 416 RangeNotSatisfied when 417 ExpectationFailed when 418 ImATeapot when 421 MisdirectedRequest when 422 UnprocessableContent when 423 Locked when 424 FailedDependency when 425 TooEarly when 426 UpgradeRequired when 428 PreconditionRequired when 429 TooManyRequests when 431 RequestHeaderFieldsTooLarge when 451 UnavailableForLegalReasons when 500 InternalServerError when 501 NotImplemented when 502 BadGateway when 503 ServiceUnavailable when 504 GatewayTimeout when 505 HTTPVersionNotSupported when 506 VariantAlsoNegotiates when 507 InsufficientStorage when 508 LoopDetected when 510 NotExtended when 511 NetworkAuthenticationRequired else raise ArgumentError, "#{int} is not a valid HTTP status code." end end |
Instance Method Details
#client_error? ⇒ Boolean
349 350 351 |
# File 'lib/typed/http/status_code.rb', line 349 def client_error? first_digit == 4 end |
#informational? ⇒ Boolean
334 335 336 |
# File 'lib/typed/http/status_code.rb', line 334 def informational? first_digit == 1 end |
#redirection? ⇒ Boolean
344 345 346 |
# File 'lib/typed/http/status_code.rb', line 344 def redirection? first_digit == 3 end |
#server_error? ⇒ Boolean
354 355 356 |
# File 'lib/typed/http/status_code.rb', line 354 def server_error? first_digit == 5 end |
#successful? ⇒ Boolean
339 340 341 |
# File 'lib/typed/http/status_code.rb', line 339 def successful? first_digit == 2 end |
#to_i ⇒ Object Also known as: to_code
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/typed/http/status_code.rb', line 208 def to_i case self when Continue 100 when SwitchingProtocols 101 when Processing 102 when EarlyHints 103 when OK 200 when Created 201 when Accepted 202 when NonAuthoritativeInformation 203 when NoContent 204 when ResetContent 205 when PartialContent 206 when MultipleChoices 300 when MovedPermanently 301 when Found 302 when SeeOther 303 when NotModified 304 when TemporaryRedirect 307 when PermanentRedirect 308 when BadRequest 400 when Unauthorized 401 when PaymentRequired 402 when Forbidden 403 when NotFound 404 when MethodNotAllowed 405 when NotAcceptable 406 when ProxyAuthenticationRequired 407 when RequestTimeout 408 when Conflict 409 when Gone 410 when LengthRequired 411 when PreconditionFailed 412 when ContentTooLarge 413 when URITooLong 414 when UnsupportedMediaType 415 when RangeNotSatisfied 416 when ExpectationFailed 417 when ImATeapot 418 when MisdirectedRequest 421 when UnprocessableContent 422 when Locked 423 when FailedDependency 424 when TooEarly 425 when UpgradeRequired 426 when PreconditionRequired 428 when TooManyRequests 429 when RequestHeaderFieldsTooLarge 431 when UnavailableForLegalReasons 451 when InternalServerError 500 when NotImplemented 501 when BadGateway 502 when ServiceUnavailable 503 when GatewayTimeout 504 when HTTPVersionNotSupported 505 when VariantAlsoNegotiates 506 when InsufficientStorage 507 when LoopDetected 508 when NotExtended 510 when NetworkAuthenticationRequired 511 else T.absurd(self) end end |