Class: GNTP
- Inherits:
-
Object
- Object
- GNTP
- Defined in:
- lib/ruby_gntp.rb
Constant Summary collapse
- RUBY_GNTP_NAME =
'ruby_gntp'
- RUBY_GNTP_VERSION =
'0.3.4'
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#target_host ⇒ Object
readonly
Returns the value of attribute target_host.
-
#target_port ⇒ Object
readonly
Returns the value of attribute target_port.
Class Method Summary collapse
-
.notify(params, &callback) ⇒ Object
instant notification.
Instance Method Summary collapse
-
#initialize(app_name = 'Ruby/GNTP', host = 'localhost', password = '', port = 23053) ⇒ GNTP
constructor
A new instance of GNTP.
-
#notify(params, &callback) ⇒ Object
notify.
-
#register(params) ⇒ Object
register.
Constructor Details
#initialize(app_name = 'Ruby/GNTP', host = 'localhost', password = '', port = 23053) ⇒ GNTP
Returns a new instance of GNTP.
47 48 49 50 51 52 |
# File 'lib/ruby_gntp.rb', line 47 def initialize(app_name = 'Ruby/GNTP', host = 'localhost', password = '', port = 23053) @app_name = app_name @target_host = host @target_port = port @password = password end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
41 42 43 |
# File 'lib/ruby_gntp.rb', line 41 def app_name @app_name end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
42 43 44 |
# File 'lib/ruby_gntp.rb', line 42 def @message end |
#target_host ⇒ Object (readonly)
Returns the value of attribute target_host.
41 42 43 |
# File 'lib/ruby_gntp.rb', line 41 def target_host @target_host end |
#target_port ⇒ Object (readonly)
Returns the value of attribute target_port.
41 42 43 |
# File 'lib/ruby_gntp.rb', line 41 def target_port @target_port end |
Class Method Details
.notify(params, &callback) ⇒ Object
instant notification
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ruby_gntp.rb', line 133 def self.notify(params, &callback) host = params[:host] passwd = params[:passwd] growl = GNTP.new(params[:app_name], host, passwd) notification = params notification[:name] = params[:app_name] || "Ruby/GNTP notification" growl.register(:notifications => [ :name => notification[:name] ]) growl.notify(notification, &callback) end |
Instance Method Details
#notify(params, &callback) ⇒ Object
notify
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ruby_gntp.rb', line 98 def notify(params, &callback) name = params[:name] title = params[:title] text = params[:text] icon = params[:icon] || get_notification_icon(name) sticky = params[:sticky] callback_context = params[:callback_context] callback_context_type = params[:callback_context_type] raise TooFewParametersError, "Notification need 'name', 'title' parameters" unless name || title @binaries = [] = notify_header(app_name, name, title, text, sticky, icon) << output_origin_headers if callback || callback_context << "Notification-Callback-Context: #{callback_context || '(none)'}\r\n" << "Notification-Callback-Context-Type: #{callback_context_type || '(none)'}\r\n" end @binaries.each {|binary| << output_binary(binary) } << "\r\n" unless (ret = send_and_recieve(, callback)) raise "Notify failed" end end |
#register(params) ⇒ Object
register
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ruby_gntp.rb', line 57 def register(params) @notifications = params[:notifications] @app_icon = params[:app_icon] raise TooFewParametersError, "Need least one 'notification' for register" unless @notifications @binaries = [] = register_header(@app_name, @app_icon) << output_origin_headers << "Notifications-Count: #{@notifications.size}\r\n" << "\r\n" @notifications.each do |notification| name = notification[:name] disp_name = notification[:disp_name] || name enabled = notification[:enabled] || true icon = notification[:icon] << "Notification-Name: #{name}\r\n" << "Notification-Display-Name: #{disp_name}\r\n" << "Notification-Enabled: #{enabled ? 'True' : 'False'}\r\n" << "#{handle_icon(icon, 'Notification')}\r\n" if icon << "\r\n" end @binaries.each {|binary| << output_binary(binary) << "\r\n" } unless (ret = send_and_recieve()) raise "Register failed" end end |