Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add priority option #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ Ruby library for GNTP(Growl Notification Transport Protocol)

Sorry, document is not avilable now.

Priority level mappings

2 Emergency
1 High
0 Normal
-1 Moderate
-2 Very Low

Usage example:

require 'rubygems'
Expand All @@ -20,6 +28,7 @@ growl.notify({
:text => "Congraturation! You are successful install ruby_gntp.",
:icon => "http://www.hatena.ne.jp/users/sn/snaka72/profile.gif",
:sticky=> true,
:priority => 2
})

# -- Instant notification
Expand All @@ -28,6 +37,7 @@ GNTP.notify({
:title => "Instant notification",
:text => "Instant notification available now.",
:icon => "http://www.hatena.ne.jp/users/sn/snaka72/profile.gif",
:priority => 2
})


6 changes: 4 additions & 2 deletions lib/ruby_gntp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ def notify(params, &callback)
text = params[:text]
icon = params[:icon] || get_notification_icon(name)
sticky = params[:sticky]
priority = params[:priority]
callback_context = params[:callback_context]
callback_context_type = params[:callback_context_type]

raise TooFewParametersError, "Notification need 'name', 'title' parameters" unless name || title

@binaries = []

message = notify_header(app_name, name, title, text, sticky, icon)
message = notify_header(app_name, name, title, text, sticky, icon, priority)
message << output_origin_headers
if callback || callback_context
message << "Notification-Callback-Context: #{callback_context || '(none)'}\r\n"
Expand Down Expand Up @@ -204,14 +205,15 @@ def register_header(app_name, app_icon)
#
# outputs the notification header
#
def notify_header(app_name, name, title, text, sticky, icon)
def notify_header(app_name, name, title, text, sticky, icon, priority)
message = "#{get_gntp_header_start('NOTIFY')}\r\n"
message << "Application-Name: #{@app_name}\r\n"
message << "Notification-Name: #{name}\r\n"
message << "Notification-Title: #{title}\r\n"
message << "Notification-Text: #{text}\r\n" if text
message << "Notification-Sticky: #{sticky}\r\n" if sticky
message << "#{handle_icon(icon, 'Notification')}\r\n" if icon
message << "Notification-Priority: #{priority}\r\n" if priority
message
end

Expand Down
2 changes: 1 addition & 1 deletion ruby_gntp.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'lib/ruby_gntp'
require './lib/ruby_gntp'

Gem::Specification.new do |s|
s.name = GNTP::RUBY_GNTP_NAME
Expand Down