lib/flapjack/data/contact.rb in flapjack-0.7.14 vs lib/flapjack/data/contact.rb in flapjack-0.7.15

- old
+ new

@@ -14,11 +14,11 @@ module Data class Contact - attr_accessor :id, :first_name, :last_name, :email, :media, :pagerduty_credentials + attr_accessor :id, :first_name, :last_name, :email, :media, :media_intervals, :pagerduty_credentials TAG_PREFIX = 'contact_tag' def self.all(options = {}) raise "Redis connection not set" unless redis = options[:redis] @@ -74,10 +74,11 @@ # used in this class def refresh self.first_name, self.last_name, self.email = @redis.hmget("contact:#{@id}", 'first_name', 'last_name', 'email') self.media = @redis.hgetall("contact_media:#{@id}") + self.media_intervals = @redis.hgetall("contact_media_intervals:#{self.id}") # similar to code in instance method pagerduty_credentials if service_key = @redis.hget("contact_media:#{@id}", 'pagerduty') self.pagerduty_credentials = @redis.hgetall("contact_pagerduty:#{@id}").merge('service_key' => service_key) @@ -197,32 +198,33 @@ def delete_notification_rule(rule) @redis.srem("contact_notification_rules:#{self.id}", rule.id) @redis.del("notification_rule:#{rule.id}") end - def media_intervals - @redis.hgetall("contact_media_intervals:#{self.id}") - end - # how often to notify this contact on the given media # return 15 mins if no value is set def interval_for_media(media) interval = @redis.hget("contact_media_intervals:#{self.id}", media) (interval.nil? || (interval.to_i <= 0)) ? (15 * 60) : interval.to_i end def set_interval_for_media(media, interval) - raise "invalid interval" unless interval.is_a?(Integer) + if interval.nil? + @redis.hdel("contact_media_intervals:#{self.id}", media) + return + end @redis.hset("contact_media_intervals:#{self.id}", media, interval) + self.media_intervals = @redis.hgetall("contact_media_intervals:#{self.id}") end def set_address_for_media(media, address) @redis.hset("contact_media:#{self.id}", media, address) if media == 'pagerduty' # FIXME - work out what to do when changing the pagerduty service key (address) # probably best solution is to remove the need to have the username and password # and subdomain as pagerduty's updated api's mean we don't them anymore I think... end + self.media = @redis.hgetall("contact_media:#{@id}") end def remove_media(media) @redis.hdel("contact_media:#{self.id}", media) @redis.hdel("contact_media_intervals:#{self.id}", media)