lib/ruby-growl.rb in ruby-growl-4.0 vs lib/ruby-growl.rb in ruby-growl-4.1
- old
+ new
@@ -40,11 +40,11 @@
class Growl
##
# ruby-growl version
- VERSION = '4.0'
+ VERSION = '4.1'
##
# Growl error base class
class Error < RuntimeError
@@ -102,11 +102,11 @@
end
notify_type = options[:notify_type]
g = new options[:host], options[:name]
- g.add_notification notify_type
+ g.add_notification notify_type, options[:name], options[:icon]
g.password = options[:password]
g.notify(notify_type, options[:title], message, options[:priority],
options[:sticky])
end
@@ -117,18 +117,19 @@
def self.process_args argv
require 'optparse'
options = {
host: nil,
+ icon: nil,
+ list: false,
message: nil,
name: "ruby-growl",
notify_type: "ruby-growl Notification",
password: nil,
priority: 0,
sticky: false,
title: "",
- list: false,
}
opts = OptionParser.new do |o|
o.program_name = File.basename $0
o.version = Growl::VERSION
@@ -151,10 +152,14 @@
o.on("-H", "--host HOSTNAME", "Send notifications to HOSTNAME") do |val|
options[:host] = val
end
+ o.on("-i", "--icon [ICON]", "Icon url") do |val|
+ options[:icon] = URI(val)
+ end
+
o.on("-n", "--name [NAME]", "Sending application name",
"(Defaults to \"ruby-growl\")") do |val|
options[:name] = val
end
@@ -277,44 +282,43 @@
##
# Sends a notification of type +name+ with the given +title+, +message+,
# +priority+ and +sticky+ settings.
- def notify name, title, message, priority = 0, sticky = false
+ def notify name, title, message, priority = 0, sticky = false, icon = nil
case @growl_type
when 'GNTP' then
- notify_gntp name, title, message, priority, sticky
+ notify_gntp name, title, message, priority, sticky, icon
when 'UDP' then
notify_udp name, title, message, priority, sticky
else
raise Growl::Error, "bug, unknown growl type #{@growl_type.inspect}"
end
self
end
- def notify_gntp name, title, message, priority, sticky # :nodoc:
+ def notify_gntp name, title, message, priority, sticky, icon = nil # :nodoc:
growl = Growl::GNTP.new @host, @application_name
growl.password = @password
- @notifications.each do |name, details|
- growl.add_notification name, *details
+ @notifications.each do |notification_name, details|
+ growl.add_notification notification_name, *details
end
growl.register
growl.notify name, title, message, priority, sticky
end
def notify_udp name, title, message, priority, sticky # :nodoc:
all_notifications = @notifications.keys
- default_notifications = @notifications.select do |name, (_, _, enabled)|
- enabled
- end.map do |name,|
- name
- end
-
- notification = all_notifications.first
+ default_notifications =
+ @notifications.select do |notification_name, (_, _, enabled)|
+ enabled
+ end.map do |notification_name,|
+ notification_name
+ end
growl = Growl::UDP.new(@host, @application_name, all_notifications,
default_notifications, @password)
growl.notify name, title, message, priority, sticky