Class: Rappfirst::Alert

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rappfirst/alert.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, api_options = nil, json_data = nil) ⇒ Alert

Returns a new instance of Alert.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rappfirst/alert.rb', line 20

def initialize(id, api_options=nil, json_data=nil)
  if api_options && api_options.keys.include?(:basic_auth)
    username = api_options[:basic_auth][:username]
    api_key = api_options[:basic_auth][:password]
  else
    username = get_config('username')
    api_key = get_config('password')
  end

  if api_options && api_options.keys.include?(:basic_uri)
    base_uri = api_options[:base_uri]
  else
    base_uri = 'https://wwws.appfirst.com/api'
  end

  self.class.basic_auth username, api_key
  self.class.base_uri base_uri

  self.id = id
  set_attributes(json_data=json_data)
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/rappfirst/alert.rb', line 9

def id
  @id
end

Instance Method Details

#deleteObject



42
43
44
# File 'lib/rappfirst/alert.rb', line 42

def delete
  delete_self
end

#syncObject



46
47
48
# File 'lib/rappfirst/alert.rb', line 46

def sync
  sync_self
end

#writeable?(name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rappfirst/alert.rb', line 16

def writeable?(name)
  return writeable_attributes.include?(name)
end

#writeable_attributesObject



11
12
13
14
# File 'lib/rappfirst/alert.rb', line 11

def writeable_attributes
  # Strip out attributes that are hard to serialize for now, because their API is weird
  ['name', 'active', 'direction', 'interval', 'time_above_threshold', 'threshold']
end