Class: Pair::Notification::OSXDispatcher

Inherits:
Dispatcher
  • Object
show all
Defined in:
lib/pair/notification/o_s_x_dispatcher.rb

Constant Summary collapse

NOTIFICATIONS =
[{:name => "Session Events", :enabled => true}]

Instance Attribute Summary collapse

Attributes inherited from Dispatcher

#enabled, #logger

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OSXDispatcher

Returns a new instance of OSXDispatcher.



10
11
12
13
14
15
16
17
18
# File 'lib/pair/notification/o_s_x_dispatcher.rb', line 10

def initialize(options = {})
  @app_icon = options.delete(:app_icon)
  super

  register_growl if Pair.config.growl_enabled?

rescue Errno::ECONNREFUSED => except
  raise Pair::Notification::GNTPError.new("Growl notification transfer protocol is not enabled, either start growl or disable growl via pair config")
end

Instance Attribute Details

#app_iconObject (readonly)

Returns the value of attribute app_icon.



6
7
8
# File 'lib/pair/notification/o_s_x_dispatcher.rb', line 6

def app_icon
  @app_icon
end

#growlObject (readonly)

Returns the value of attribute growl.



6
7
8
# File 'lib/pair/notification/o_s_x_dispatcher.rb', line 6

def growl
  @growl
end

Instance Method Details

#gntp_notify(options) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pair/notification/o_s_x_dispatcher.rb', line 42

def gntp_notify(options)
  if enabled
    if block_given?
      yield @growl
    end

    if options[:text]
      options = {
        :name => "Session Events", :title => "",
        :icon => @app_icon, :sticky => false
      }.merge(options)

      @growl.notify(options)
    end
  end
end

#register_growlObject



20
21
22
23
# File 'lib/pair/notification/o_s_x_dispatcher.rb', line 20

def register_growl
  @growl = GNTP.new(Pair::APPLICATION_NAME)
  @growl.register application_hash
end

#session_join(user, session) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/pair/notification/o_s_x_dispatcher.rb', line 25

def session_join(user, session)
  gntp_notify({
    :name => "Session Events", :title => "Pair Message",
    :text => "#{user} joined session \"#{session}\"",
    :icon => Pair::ICON_SESSION_JOIN, :sticky => true
  })
end

#session_part(user, session) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/pair/notification/o_s_x_dispatcher.rb', line 33

def session_part(user, session)
  gntp_notify({
    :name => "Session Events", :title => "Pair Message",
    :text => "#{user} parted session \"#{session}\"",
    :icon => Pair::ICON_SESSION_JOIN, :sticky => true
  })
end