Class: Pingify::Runnable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { :timeout => 2.0, :open_timeout => 2.0 }) ⇒ Runnable

Returns a new instance of Runnable.



10
11
12
13
14
# File 'lib/pingify.rb', line 10

def initialize(options={ :timeout => 2.0, :open_timeout => 2.0 })
  @uri = options.delete :uri
  @times = options.delete(:times) || 4
  @http_opts = { :timeout => options.delete(:timeout), :open_timeout => options.delete(:open_timeout) }
end

Instance Attribute Details

#uriObject

Returns the value of attribute uri.



8
9
10
# File 'lib/pingify.rb', line 8

def uri
  @uri
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
# File 'lib/pingify.rb', line 16

def run
  res = ping!

  data = { :average => average_time(@times - 1), :body => res.body }.merge(ping_headers(res))

  return Result.new(data)
rescue
  return ErrorResult.new({}, [$!])
end