Class: UptrendsExtended::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/uptrends_extended/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/uptrends_extended/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')

  # 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

Instance Attribute Details

#usernameObject (readonly)

Returns the value of attribute username.



12
13
14
# File 'lib/uptrends_extended/client.rb', line 12

def username
  @username
end

Instance Method Details

#add_probe(opts = {}) ⇒ Object



46
47
48
49
# File 'lib/uptrends_extended/client.rb', line 46

def add_probe(opts = {})
  p = UptrendsExtended::Probe.new(self, nil, opts)
  p.create!
end

#add_probe_group(opts = {}) ⇒ Object



51
52
53
54
# File 'lib/uptrends_extended/client.rb', line 51

def add_probe_group(opts = {})
  pg = UptrendsExtended::ProbeGroup.new(self, nil, opts)
  pg.create!
end

#checkpointsObject



38
39
40
# File 'lib/uptrends_extended/client.rb', line 38

def checkpoints
  get(UptrendsExtended::Checkpoint, all: true)
end

#probe(guid) ⇒ Object



26
27
28
# File 'lib/uptrends_extended/client.rb', line 26

def probe(guid)
  get(UptrendsExtended::Probe, guid: guid)
end

#probe_group(guid) ⇒ Object



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

def probe_group(guid)
  get(UptrendsExtended::ProbeGroup, guid: guid)
end

#probe_groupsObject



42
43
44
# File 'lib/uptrends_extended/client.rb', line 42

def probe_groups
  get(UptrendsExtended::ProbeGroup, all: true)
end

#probesObject



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

def probes
  get(UptrendsExtended::Probe, all: true)
end