Class: Trustpilot::ErrorChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/trustpilot/error_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ErrorChecker

args:

response: Net::HTTPResponse


9
10
11
# File 'lib/trustpilot/error_checker.rb', line 9

def initialize response
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/trustpilot/error_checker.rb', line 5

def response
  @response
end

Instance Method Details

#bodyObject



31
32
33
# File 'lib/trustpilot/error_checker.rb', line 31

def body
  response.body
end

#codeObject



27
28
29
# File 'lib/trustpilot/error_checker.rb', line 27

def code
  response.code.to_i
end

#error_if_appropriateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/trustpilot/error_checker.rb', line 13

def error_if_appropriate
  if code >= 500
    init_error ServerError
  elsif code == 429
    init_error RateLimitError
  elsif code == 401
    init_error AuthenticationError
  elsif code >= 400
    init_error ClientError
  elsif code >= 300
    init_error ServerError
  end
end

#messageObject



35
36
37
# File 'lib/trustpilot/error_checker.rb', line 35

def message
  response.message
end