Class: Pinger
- Inherits:
-
Object
- Object
- Pinger
- Defined in:
- lib/pinger.rb
Instance Attribute Summary collapse
-
#expected_redirect_url ⇒ Object
Returns the value of attribute expected_redirect_url.
-
#expected_status_code ⇒ Object
Returns the value of attribute expected_status_code.
-
#follow_location ⇒ Object
Returns the value of attribute follow_location.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
Instance Attribute Details
#expected_redirect_url ⇒ Object
Returns the value of attribute expected_redirect_url.
3 4 5 |
# File 'lib/pinger.rb', line 3 def expected_redirect_url @expected_redirect_url end |
#expected_status_code ⇒ Object
Returns the value of attribute expected_status_code.
3 4 5 |
# File 'lib/pinger.rb', line 3 def expected_status_code @expected_status_code end |
#follow_location ⇒ Object
Returns the value of attribute follow_location.
3 4 5 |
# File 'lib/pinger.rb', line 3 def follow_location @follow_location end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/pinger.rb', line 3 def url @url end |
Instance Method Details
#perform ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pinger.rb', line 8 def perform if response_code.to_i == @expected_status_code # Everything's fine puts "Sucessfully ping #{url} with expected status code #{@expected_status_code}" if @expected_status_code == 301 and @expected_redirect_url if redirect_url == @expected_redirect_url # Everything's fine puts "Sucessfully redirect #{url} to #{@expected_redirect_url} with status #{response_code}" else = "Unable to redirect #{url} to #{@expected_redirect_url} with expected status code #{@expected_status_code} - Received location #{redirect_url} with #{response_code} instead" puts "Something went wrong, we must notify someone" Notifier.new().perform end end else = "Unable to ping #{url} with expected status code #{@expected_status_code} - Received #{response_code} instead" puts "Something went wrong, we must notify someone" Notifier.new().perform end end |
#redirect_url ⇒ Object
34 35 36 |
# File 'lib/pinger.rb', line 34 def redirect_url request.redirect_url end |
#request ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/pinger.rb', line 38 def request @request ||= Curl::Easy.new(@url) do |curl| curl.follow_location = @follow_location end @request.perform @request end |
#response_code ⇒ Object
30 31 32 |
# File 'lib/pinger.rb', line 30 def response_code request.response_code end |