Sha256: fdeb2ffad9aa63243a56db757514d23cabe36fbbe5d5babeb48b8c38a0871298

Contents?: true

Size: 1.59 KB

Versions: 7

Compression:

Stored size: 1.59 KB

Contents

#!/usr/bin/env ruby

# 'Notification' refers to the template object created when an event occurs,
# from which individual 'Message' objects are created, one for each
# contact+media recipient.

require 'flapjack/data/contact'
require 'flapjack/data/notification'

module Flapjack
  module Data
    class Message

      attr_reader :medium, :address, :duration, :contact

      def self.for_contact(contact, opts = {})
        self.new(:contact => contact,
                 :notification_contents => opts[:notification_contents],
                 :medium => opts[:medium], :address => opts[:address],
                 :duration => opts[:duration])
      end

      def id
        return @id if @id
        t = Time.now
        # FIXME: consider using a UUID here
        # this is planned to be used as part of alert history keys
        @id = "#{self.object_id.to_i}-#{t.to_i}.#{t.tv_usec}"
      end

      def contents
        c = {'media'              => medium,
             'address'            => address,
             'id'                 => id,
             'contact_id'         => contact.id,
             'contact_first_name' => contact.first_name,
             'contact_last_name'  => contact.last_name}
        c['duration'] = duration if duration
        return c if @notification_contents.nil?
        c.merge(@notification_contents)
      end

    private

      def initialize(opts = {})
        @contact = opts[:contact]
        @notification_contents = opts[:notification_contents]
        @medium = opts[:medium]
        @address = opts[:address]
        @duration = opts[:duration]
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
flapjack-0.7.18 lib/flapjack/data/message.rb
flapjack-0.7.17 lib/flapjack/data/message.rb
flapjack-0.7.16 lib/flapjack/data/message.rb
flapjack-0.7.15 lib/flapjack/data/message.rb
flapjack-0.7.14 lib/flapjack/data/message.rb
flapjack-0.7.13 lib/flapjack/data/message.rb
flapjack-0.7.12 lib/flapjack/data/message.rb