Class: WaybackArchiver::HTTPCode

Inherits:
Object
  • Object
show all
Defined in:
lib/wayback_archiver/http_code.rb

Overview

Convience class for HTTP response codes

Class Method Summary collapse

Class Method Details

.error?(code) ⇒ Boolean

Whether the code is a error type

Examples:

HttpCode.error?('301')

Parameters:

  • code (String)

    the response code

Returns:

  • (Boolean)

    is error or not



45
46
47
# File 'lib/wayback_archiver/http_code.rb', line 45

def self.error?(code)
  !!code.to_s.match(/4\d\d/) || !!code.to_s.match(/5\d\d/)
end

.redirect?(code) ⇒ Boolean

Whether the code is a redirect type

Examples:

HttpCode.redirect?('301')

Parameters:

  • code (String)

    the response code

Returns:

  • (Boolean)

    is redirect or not



36
37
38
# File 'lib/wayback_archiver/http_code.rb', line 36

def self.redirect?(code)
  !!code.to_s.match(/3\d\d/)
end

.success?(code) ⇒ Boolean

Whether the code is a success type

Examples:

HttpCode.success?('200') # => true
HttpCode.success?(200) # => true
HttpCode.success?(nil) # => false

Parameters:

  • code (String)

    the response code

Returns:

  • (Boolean)

    is success or not



27
28
29
# File 'lib/wayback_archiver/http_code.rb', line 27

def self.success?(code)
  !!code.to_s.match(/2\d\d/)
end

.type(code) ⇒ Symbol

Type of code as symbol

Examples:

HttpCode.type('200')

Parameters:

  • code (String/Integer)

    the response code

Returns:

  • (Symbol)

    code type



9
10
11
12
13
14
15
16
# File 'lib/wayback_archiver/http_code.rb', line 9

def self.type(code)
  code = code.to_s
  return :success if success?(code)
  return :redirect if redirect?(code)
  return :error if error?(code)

  :unknown
end