Class: Rowl::Notification
- Inherits:
-
Object
- Object
- Rowl::Notification
- Defined in:
- lib/rowl.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Notification
constructor
A new instance of Notification.
- #payload ⇒ Object
- #send_notification ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Notification
Returns a new instance of Notification.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rowl.rb', line 102 def initialize(opts={}) opts = { :priority => 0, :sticky => false, :host => "localhost" }.merge(opts) @application = opts[:application] @password = opts[:password] @host = opts[:host] @notification = opts[:notification] @title = opts[:title] @description = opts[:description] @priority = opts[:priority] @sticky = opts[:sticky] send_notification end |
Instance Method Details
#payload ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/rowl.rb', line 126 def payload flags = 0 data = [] packet = [ GROWL_PROTOCOL_VERSION, GROWL_TYPE_NOTIFICATION, ] flags = 0 flags |= ((0x7 & @priority) << 1) # 3 bits for priority flags |= 1 if @sticky # 1 bit for sticky packet << flags packet << @notification.length packet << @title.length packet << @description.length packet << @application.length data << @notification data << @title data << @description data << @application packet << data.join packet = packet.pack(NOTIFICATION_FORMAT) if @password checksum = Digest::MD5.digest(packet+@password) else checksum = Digest::MD5.digest(packet) end packet << checksum @datagram = packet end |
#send_notification ⇒ Object
121 122 123 124 |
# File 'lib/rowl.rb', line 121 def send_notification socket = UDPSocket.open socket.send(payload, 0, @host, 9887) end |