Sha256: 479cff10d2913e6e1dfc8c4a4fbe08f9a8f24a40b980a19deab94963887cd7da

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 KB

Contents

#!/usr/bin/env ruby

require 'flapjack/data/message'

module Flapjack
  module Data
    class Notification

      attr_accessor :event, :type

      def self.for_event(event, opts = {})
        self.new(:event => event, :type => opts[:type])
      end

      def messages(opts = {})
        contacts = opts[:contacts]
        return [] if contacts.nil?
        @messages ||= contacts.collect {|contact|
          contact.media.keys.inject([]) { |ret, mk|
            m = Flapjack::Data::Message.for_contact(:contact => contact)
            m.notification = self
            m.medium  = mk
            m.address = contact.media[mk]
            ret << m
            ret
          }
        }.flatten
      end

      def contents
        @contents ||= {'event_id'          => event.id,
                       'state'             => event.state,
                       'summary'           => event.summary,
                       'time'              => event.time,
                       'notification_type' => type}
      end

    private

      def initialize(opts = {})
        raise "Event not passed" unless event = opts[:event]
        @event = event
        @type  = opts[:type]
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
flapjack-0.6.49 lib/flapjack/data/notification.rb
flapjack-0.6.48 lib/flapjack/data/notification.rb
flapjack-0.6.47 lib/flapjack/data/notification.rb
flapjack-0.6.46 lib/flapjack/data/notification.rb
flapjack-0.6.45 lib/flapjack/data/notification.rb
flapjack-0.6.44 lib/flapjack/data/notification.rb
flapjack-0.6.43 lib/flapjack/data/notification.rb
flapjack-0.6.42 lib/flapjack/data/notification.rb
flapjack-0.6.41 lib/flapjack/data/notification.rb
flapjack-0.6.40 lib/flapjack/data/notification.rb