Class: Ayadn::CheckBase

Inherits:
Object show all
Defined in:
lib/ayadn/diagnostics.rb

Direct Known Subclasses

CheckADN, CheckAccounts, CheckAyadn, CheckNiceRank

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCheckBase

Returns a new instance of CheckBase.



52
53
54
# File 'lib/ayadn/diagnostics.rb', line 52

def initialize
  @status = Status.new
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



50
51
52
# File 'lib/ayadn/diagnostics.rb', line 50

def response
  @response
end

#statusObject

Returns the value of attribute status.



50
51
52
# File 'lib/ayadn/diagnostics.rb', line 50

def status
  @status
end

Instance Method Details

#check_response_codeObject



60
61
62
63
64
65
66
67
# File 'lib/ayadn/diagnostics.rb', line 60

def check_response_code
  code = @response.code
  if code == 200
    @status.say_green :status, "OK"
  else
    @status.say_red :status, "#{code}"
  end
end

#get_response(url) ⇒ Object



56
57
58
# File 'lib/ayadn/diagnostics.rb', line 56

def get_response(url)
  @response = RestClient.get(url) {|response, request, result| response}
end

#rescue_network(error) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ayadn/diagnostics.rb', line 69

def rescue_network(error)
  begin
    raise error
  rescue RestClient::RequestTimeout => e
    @status.say_error "connection timeout"
    @status.say_trace e
  rescue SocketError, SystemCallError, OpenSSL::SSL::SSLError => e
    @status.say_error "connection problem"
    @status.say_trace e
  rescue Interrupt
    @status.say_error "operation canceled"
    exit
  rescue => e
    @status.say_error "unknown error"
    @status.say_trace e
  end
end