Class: GNTP
- Inherits:
-
Object
- Object
- GNTP
- Defined in:
- lib/ruby_gntp.rb
Constant Summary collapse
- RUBY_GNTP_NAME =
'ruby_gntp'- RUBY_GNTP_VERSION =
'0.1.3'
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#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) ⇒ 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) ⇒ 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.
46 47 48 49 50 51 |
# File 'lib/ruby_gntp.rb', line 46 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.
40 41 42 |
# File 'lib/ruby_gntp.rb', line 40 def app_name @app_name end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
41 42 43 |
# File 'lib/ruby_gntp.rb', line 41 def end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
40 41 42 |
# File 'lib/ruby_gntp.rb', line 40 def password @password end |
#target_host ⇒ Object (readonly)
Returns the value of attribute target_host.
40 41 42 |
# File 'lib/ruby_gntp.rb', line 40 def target_host @target_host end |
#target_port ⇒ Object (readonly)
Returns the value of attribute target_port.
40 41 42 |
# File 'lib/ruby_gntp.rb', line 40 def target_port @target_port end |
Class Method Details
.notify(params) ⇒ Object
instant notification
124 125 126 127 128 129 130 131 132 |
# File 'lib/ruby_gntp.rb', line 124 def self.notify(params) growl = GNTP.new(params[:app_name]) notification = params notification[:name] = params[:app_name] || "Ruby/GNTP notification" growl.register(:notifications => [ :name => notification[:name] ]) growl.notify(notification) end |
Instance Method Details
#notify(params) ⇒ Object
notify
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ruby_gntp.rb', line 95 def notify(params) name = params[:name] raise TooFewParametersError, "Notification need 'name', 'title' parameters" unless name || title title = params[:title] text = params[:text] icon = params[:icon] || get_notification_icon(name) sticky = params[:sticky] @binaries = [] = notify_header(app_name, name, title, text, sticky, icon) << output_origin_headers @binaries.each {|binary| << output_binary(binary) } << "\r\n" unless (ret = send_and_recieve()) raise "Notify failed" end end |
#register(params) ⇒ Object
register
56 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 |
# File 'lib/ruby_gntp.rb', line 56 def register(params) @notifications = params[:notifications] raise TooFewParametersError, "Need least one 'notification' for register" unless @notifications @app_icon = params[:app_icon] @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-Enabled: #{enabled ? 'True' : 'False'}\r\n" << "Notification-Display-Name: #{disp_name}\r\n" << "#{handle_icon(icon, 'Notification')}\r\n" if icon end @binaries.each {|binary| << output_binary(binary) } << "\r\n" unless (ret = send_and_recieve()) raise "Register failed" end end |