Class: Dialers::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/dialers/status.rb

Overview

A wrapper over an HTTP status to answer some questions related to what a state means.

Instance Method Summary collapse

Constructor Details

#initialize(status) ⇒ Status

Returns a new instance of Status.


4
5
6
# File 'lib/dialers/status.rb', line 4

def initialize(status)
  self.status = status
end

Instance Method Details

#accepted?Boolean

Returns wether the status is 202.

Returns:

  • (Boolean)

    wether the status is 202.


45
46
47
# File 'lib/dialers/status.rb', line 45

def accepted?
  is?(202)
end

#bad_request?Boolean

Returns wether the status is 400.

Returns:

  • (Boolean)

    wether the status is 400.


55
56
57
# File 'lib/dialers/status.rb', line 55

def bad_request?
  is?(400)
end

#client_error?Boolean

Returns wether the status is a 4xx one.

Returns:

  • (Boolean)

    wether the status is a 4xx one.


25
26
27
# File 'lib/dialers/status.rb', line 25

def client_error?
  initial_letter == "4"
end

#created?Boolean

Returns wether the status is 201.

Returns:

  • (Boolean)

    wether the status is 201.


40
41
42
# File 'lib/dialers/status.rb', line 40

def created?
  is?(201)
end

#is?(code) ⇒ Boolean

Returns wether the status is the argument.

Parameters:

  • code (Fixnum)

    The code to compare

Returns:

  • (Boolean)

    wether the status is the argument


10
11
12
# File 'lib/dialers/status.rb', line 10

def is?(code)
  status.to_i == code.to_i
end

#method_not_allowed?Boolean

Returns wether the status is 405.

Returns:

  • (Boolean)

    wether the status is 405.


70
71
72
# File 'lib/dialers/status.rb', line 70

def method_not_allowed?
  is?(405)
end

#no_content?Boolean

Returns wether the status is 204.

Returns:

  • (Boolean)

    wether the status is 204.


50
51
52
# File 'lib/dialers/status.rb', line 50

def no_content?
  is?(204)
end

#not_found?Boolean

Returns wether the status is 404.

Returns:

  • (Boolean)

    wether the status is 404.


65
66
67
# File 'lib/dialers/status.rb', line 65

def not_found?
  is?(404)
end

#ok?Boolean

Returns wether the status is 200.

Returns:

  • (Boolean)

    wether the status is 200.


35
36
37
# File 'lib/dialers/status.rb', line 35

def ok?
  is?(200)
end

#redirect?Boolean

Returns wether the status is a 3xx one.

Returns:

  • (Boolean)

    wether the status is a 3xx one.


20
21
22
# File 'lib/dialers/status.rb', line 20

def redirect?
  initial_letter == "3"
end

#server_error?Boolean

Returns wether the status is a 5xx one.

Returns:

  • (Boolean)

    wether the status is a 5xx one.


30
31
32
# File 'lib/dialers/status.rb', line 30

def server_error?
  initial_letter == "5"
end

#success?Boolean

Returns wether the status is a 2xx one.

Returns:

  • (Boolean)

    wether the status is a 2xx one.


15
16
17
# File 'lib/dialers/status.rb', line 15

def success?
  initial_letter == "2"
end

#unauthorized?Boolean

Returns wether the status is 401.

Returns:

  • (Boolean)

    wether the status is 401.


60
61
62
# File 'lib/dialers/status.rb', line 60

def unauthorized?
  is?(401)
end