Sha256: 818b9bcc1ac519bc52d23aba46222ef8f5d6f6b4f0563ab9be35f46879488b2c

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 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.

module Flapjack
  module Data
    class Message

      attr_accessor :medium, :address, :id, :duration, :contact, :notification

      def self.for_contact(opts = {})
        self.new(:contact => opts[:contact])
      end

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

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

    private

      def initialize(opts = {})
        @contact = opts[:contact]
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
flapjack-0.7.6 lib/flapjack/data/message.rb
flapjack-0.7.5 lib/flapjack/data/message.rb
flapjack-0.7.4 lib/flapjack/data/message.rb
flapjack-0.7.3 lib/flapjack/data/message.rb
flapjack-0.7.2 lib/flapjack/data/message.rb
flapjack-0.7.1 lib/flapjack/data/message.rb
flapjack-0.7.0 lib/flapjack/data/message.rb