Class: PingdomCap::Client

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

Constant Summary collapse

BASE_SERVER_ADDRESS =
"https://api.pingdom.com/api/2.0"
OPTIONS =
{
  url: BASE_SERVER_ADDRESS
}
REQUIRED_OPTIONS =
[ :key, :url, :username, :password ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pingdom_cap/client.rb', line 15

def initialize(options = {})
  options = OPTIONS.merge(options)
  raise "Options #{REQUIRED_OPTIONS.join(', ')} are required" if REQUIRED_OPTIONS.any? { |op| options[op].nil? }
  headers = { 'App-Key' => options[:key] }
  @connection = Faraday::Connection.new(url: options[:url], headers: headers) do |builder|
    builder.response :logger if options[:logger]
    builder.adapter Faraday.default_adapter
    builder.request  :url_encoded
    builder.use Faraday::Response::Mashify
    builder.use Faraday::Response::ParseJson
  end
  @connection.basic_auth(options[:username], options[:password])
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



13
14
15
# File 'lib/pingdom_cap/client.rb', line 13

def connection
  @connection
end

Instance Method Details

#pause(name) ⇒ Object



34
35
36
37
# File 'lib/pingdom_cap/client.rb', line 34

def pause(name)
  puts "Pausing Pingdom '#{name}'"
  check_pause(name_to_checkid(name))
end

#status(name) ⇒ Object



29
30
31
32
# File 'lib/pingdom_cap/client.rb', line 29

def status(name)
  puts "Status for Pingdom '#{name}'"
  ap get_detailed_check_information(name_to_checkid(name)).to_hash, plain: true
end

#unpause(name) ⇒ Object



39
40
41
42
# File 'lib/pingdom_cap/client.rb', line 39

def unpause(name)
  puts "Unpausing Pingdom '#{name}'"
  check_unpause(name_to_checkid(name))
end