Prowl
-
Comments:
- here.
Prowl is awesome. Growl notifications can be forwarded to your iPhone.
But you can get notifications from anywhere. A Perl script is included, but that didn’t work on my server. So I wrote one in Ruby:
1 #! /usr/bin/ruby
2
3 # A ruby class for sending notifications to Prowl.
4
5 require 'uri'
6 require 'net/http'
7 require 'net/https'
8
9 class String
10 def urlencode
11 gsub( /[^a-zA-Z0-9\-_\.!~*'()]/n ) {|x| sprintf('%%%02x', x[0]) }
12 end
13 end
14
15 class Hash
16 def urlencode
17 collect { |k,v| "#{k.to_s.urlencode}=#{v.to_s.urlencode}" }.join('&')
18 end
19 end
20
21 class Prowler
22 def initialize user, pass
23 @url = URI.parse('https://prowl.weks.net/api/add_notification.php')
24 @username = user
25 @password = pass
26
27 @http = Net::HTTP.new(@url.host, @url.port)
28 @http.use_ssl = true
29 end
30
31 def send_notification app, evt, desc
32
33
34 options = {
35 'application' => app,
36 'event' => evt,
37 'description' => desc
38 }
39
40 req = Net::HTTP::Get.new("#{@url.path}?#{options.urlencode}")
41 req.basic_auth @username, @password
42 @http.request(req)
43 end
44
45 end
46
47 # How to use?
48 # p = Prowler.new('username', 'password')
49 # p.send_notification('App','Event','Desc')