Class: Triggers

Inherits:
Base
  • Object
show all
Defined in:
lib/zapix/proxies/triggers.rb

Defined Under Namespace

Classes: NonExistingTrigger

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Base

Instance Method Details

#create(options) ⇒ Object



3
4
5
# File 'lib/zapix/proxies/triggers.rb', line 3

def create(options)
  client.trigger_create(options) unless exists?(options)
end

#delete(*trigger_ids) ⇒ Object



7
8
9
# File 'lib/zapix/proxies/triggers.rb', line 7

def delete(*trigger_ids)
  client.trigger_delete(trigger_ids)
end

#exists?(options) ⇒ Boolean

this is very unefficient but there is no other way to verify that a trigger exists..

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/zapix/proxies/triggers.rb', line 13

def exists?(options)
  result = client.trigger_get('output' => 'extend',
                              'expandExpression' => true)

  id = extract_id(result, options['expression'])
  if id.nil?
    false
  else
    true
  end
end

#get_id(options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/zapix/proxies/triggers.rb', line 25

def get_id(options)
  result = client.trigger_get('output' => 'extend',
                              'expandExpression' => true)
  id = extract_id(result, options['expression'])
  if id.nil?
    raise NonExistingTrigger, "Trigger with expression #{options['expression']} not found."
  else
    id
  end
end