class Uptrends::Client
Attributes
debug[R]
username[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/uptrends/client.rb, line 14 def initialize(opts = {}) @username = opts[:username] ? opts[:username] : fail("You must specify the :username option") password = opts[:password] ? opts[:password] : fail("You must specify the :password option") @debug = opts[:debug] # This makes it so that every request uses basic auth self.class.basic_auth(@username, password) # This makes it so that every request uses ?format=json self.class.default_params({format: 'json'}) # This makes it so that every request uses ?format=json self.class.headers({'Content-Type' => 'application/json', 'Accept' => 'application/json'}) end
Public Instance Methods
add_probe(opts = {})
click to toggle source
# File lib/uptrends/client.rb, line 47 def add_probe(opts = {}) p = Uptrends::Probe.new(self, nil, opts) p.create! end
add_probe_group(opts = {})
click to toggle source
# File lib/uptrends/client.rb, line 52 def add_probe_group(opts = {}) pg = Uptrends::ProbeGroup.new(self, nil, opts) pg.create! end
checkpoints()
click to toggle source
# File lib/uptrends/client.rb, line 39 def checkpoints get(Uptrends::Checkpoint, all: true) end
probe(guid)
click to toggle source
# File lib/uptrends/client.rb, line 27 def probe(guid) get(Uptrends::Probe, guid: guid) end
probe_group(guid)
click to toggle source
# File lib/uptrends/client.rb, line 31 def probe_group(guid) get(Uptrends::ProbeGroup, guid: guid) end
probe_groups()
click to toggle source
# File lib/uptrends/client.rb, line 43 def probe_groups get(Uptrends::ProbeGroup, all: true) end
probes()
click to toggle source
# File lib/uptrends/client.rb, line 35 def probes get(Uptrends::Probe, all: true) end
Private Instance Methods
get(type, opts = {})
click to toggle source
# File lib/uptrends/client.rb, line 58 def get(type, opts = {}) all = opts[:all] ? opts[:all] : false guid = opts[:guid] ? opts[:guid] : nil if type == Uptrends::Probe uri = '/probes' elsif type == Uptrends::ProbeGroup uri = '/probegroups' elsif type == Uptrends::Checkpoint uri = '/checkpointservers' else fail("You passed an unknown type. Try Uptrends::Probe, Uptrends::ProbeGroup or Uptrends::Checkpoint") end if all response = self.class.get(uri) elsif guid response = self.class.get("#{uri}/#{guid}") end type.parse(self, response) end