pixeltrix-prowler 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/INSTALL ADDED
@@ -0,0 +1,43 @@
1
+ Prowler
2
+ =======
3
+
4
+ This is a plugin for integrating apps with the Prowl iPhone application.
5
+
6
+ INSTALLATION
7
+
8
+ From your project's RAILS_ROOT, run:
9
+
10
+ script/plugin install git://github.com/pixeltrix/prowler.git
11
+
12
+ CONFIGURATION
13
+
14
+ You should have something like this in config/initializers/prowler.rb.
15
+
16
+ Prowler.configure do |config|
17
+ config.username = 'username'
18
+ config.password = 'password'
19
+ config.application = 'www.example.com'
20
+ end
21
+
22
+ You can test that Prowler is working in your production environment by using
23
+ this rake task (from RAILS_ROOT):
24
+
25
+ rake prowler:test
26
+
27
+ If everything is configured properly the task will send a request to
28
+ prowl.weks.net which will be appear on your iPhone after a short delay.
29
+
30
+ USAGE
31
+
32
+ To use Prowler within your application just call the notify method, e.g.
33
+
34
+ Prowler.notify "Event", "Description"
35
+
36
+ ABOUT
37
+
38
+ Prowler relies upon the Prowl iPhone application which is advertised as
39
+ a Growl notification forwarder from your Mac. However they provide an API
40
+ which can be called by a generic script which allows you to use the
41
+ application as a general push notification application for your iPhone.
42
+
43
+ For more about the Prowl application see: http://prowl.weks.net/
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 Jordan Brock
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,43 @@
1
+ Prowler
2
+ =======
3
+
4
+ This is a plugin for integrating apps with the Prowl iPhone application.
5
+
6
+ INSTALLATION
7
+
8
+ From your project's RAILS_ROOT, run:
9
+
10
+ script/plugin install git://github.com/pixeltrix/prowler.git
11
+
12
+ CONFIGURATION
13
+
14
+ You should have something like this in config/initializers/prowler.rb.
15
+
16
+ Prowler.configure do |config|
17
+ config.username = 'username'
18
+ config.password = 'password'
19
+ config.application = 'www.example.com'
20
+ end
21
+
22
+ You can test that Prowler is working in your production environment by using
23
+ this rake task (from RAILS_ROOT):
24
+
25
+ rake prowler:test
26
+
27
+ If everything is configured properly the task will send a request to
28
+ prowl.weks.net which will be appear on your iPhone after a short delay.
29
+
30
+ USAGE
31
+
32
+ To use Prowler within your application just call the notify method, e.g.
33
+
34
+ Prowler.notify "Event", "Description"
35
+
36
+ ABOUT
37
+
38
+ Prowler relies upon the Prowl iPhone application which is advertised as
39
+ a Growl notification forwarder from your Mac. However they provide an API
40
+ which can be called by a generic script which allows you to use the
41
+ application as a general push notification application for your iPhone.
42
+
43
+ For more about the Prowl application see: http://prowl.weks.net/
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the prowler plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the prowler plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'Prowler'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ puts IO.read(File.join(File.dirname(__FILE__), 'INSTALL'))
data/lib/prowler.rb ADDED
@@ -0,0 +1,92 @@
1
+ require 'logger'
2
+ require 'net/http'
3
+ require 'net/https'
4
+
5
+ module Prowler
6
+ class << self
7
+ attr_accessor :host, :port, :secure
8
+ attr_accessor :username, :password
9
+ attr_accessor :application, :send_notifications
10
+
11
+ # The host to connect to.
12
+ def host
13
+ @host ||= 'prowl.weks.net'
14
+ end
15
+
16
+ # The port on which the service runs.
17
+ def port
18
+ @port || (secure ? 443 : 80)
19
+ end
20
+
21
+ # Whether the service is running over SSL.
22
+ def secure
23
+ @secure.nil? ? true : !!@secure
24
+ end
25
+
26
+ # Call this method to configure your account details in an initializer.
27
+ def configure
28
+ yield self
29
+ end
30
+
31
+ # Whether to send notifications
32
+ def send_notifications
33
+ @send_notifications.nil? ? true : !!@send_notifications
34
+ end
35
+ alias :send_notifications? :send_notifications
36
+
37
+ # Reset configuration
38
+ def reset_configuration
39
+ @host = @port = @secure = @application = @username = @password = nil
40
+ end
41
+
42
+ # Whether the library has been configured
43
+ def configured?
44
+ !(@application.nil? || @username.nil? || @password.nil?)
45
+ end
46
+
47
+ def path(*params) #:nodoc:
48
+ sprintf("/api/add_notification.php?application=%s&event=%s&description=%s", *params)
49
+ end
50
+
51
+ # Returns the default logger or a logger that prints to STDOUT.
52
+ def logger
53
+ ActiveRecord::Base.logger
54
+ rescue
55
+ @logger ||= Logger.new(STDERR)
56
+ end
57
+
58
+ # Send a notification to your iPhone:
59
+ # * event: The title of notification you want to send.
60
+ # * message: The text of the notification message you want to send.
61
+ def notify(event, message)
62
+ raise RuntimeError, "Prowler needs to be configured first before using it" unless configured?
63
+
64
+ http = Net::HTTP.new(host, port)
65
+ http.use_ssl = secure
66
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
67
+ http.start do
68
+ headers = {
69
+ 'User-Agent' => 'ProwlScript/1.0'
70
+ }
71
+ http.read_timeout = 5 # seconds
72
+ http.open_timeout = 2 # seconds
73
+ request = Net::HTTP::Get.new(path(URI.escape(application), URI.escape(event), URI.escape(message)), headers)
74
+ request.basic_auth(username, password)
75
+ response = begin
76
+ http.request(request) if send_notifications?
77
+ rescue TimeoutError => e
78
+ logger.error "Timeout while contacting the Prowl server."
79
+ nil
80
+ end
81
+ case response
82
+ when Net::HTTPSuccess then
83
+ logger.info "Prowl Success: #{response.class}"
84
+ when NilClass then
85
+ # Do nothing
86
+ else
87
+ logger.error "Prowl Failure: #{response.class}\n#{response.body if response.respond_to? :body}"
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
data/prowler.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'prowler'
4
+ s.version = "1.0.0"
5
+ s.summary = 'Provides access to the Prowl API.'
6
+ s.description = <<-EOF
7
+ A simple wrapper class that provides basic access to the Prowl API.
8
+ EOF
9
+ s.author = 'Andrew White'
10
+ s.email = 'andyw@pixeltrix.co.uk'
11
+ s.homepage = 'http://github.com/pixeltrix/prowler/'
12
+ s.has_rdoc = true
13
+
14
+ s.requirements << 'none'
15
+ s.require_path = 'lib'
16
+
17
+ s.files = [
18
+ 'prowler.gemspec',
19
+ 'INSTALL',
20
+ 'install.rb',
21
+ 'lib/prowler.rb',
22
+ 'MIT-LICENSE',
23
+ 'Rakefile',
24
+ 'README',
25
+ 'tasks/prowler.rake',
26
+ 'test/prowler_test.rb',
27
+ ]
28
+
29
+ s.test_file = 'test/prowler_test.rb'
30
+ end
@@ -0,0 +1,6 @@
1
+ namespace :prowler do
2
+ desc "Verify your plugin installation by sending a test notification to the Prowl iPhone application"
3
+ task :test => :environment do
4
+ Prowler.notify "Test Message", "Testing, testing, testing ..."
5
+ end
6
+ end
@@ -0,0 +1,97 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require 'shoulda'
5
+ require File.join(File.dirname(__FILE__), "..", "lib", "prowler")
6
+
7
+ class ProwlerTest < Test::Unit::TestCase
8
+ context "Prowler configuration" do
9
+ setup do
10
+ Prowler.reset_configuration
11
+ Prowler.send_notifications = false
12
+ end
13
+
14
+ should "be done with a block" do
15
+ Prowler.configure do |config|
16
+ config.host = "prowler"
17
+ config.port = 666
18
+ config.secure = false
19
+ config.application = "application"
20
+ config.username = "username"
21
+ config.password = "password"
22
+ end
23
+
24
+ assert_equal "prowler", Prowler.host
25
+ assert_equal 666, Prowler.port
26
+ assert_equal false, Prowler.secure
27
+ assert_equal "application", Prowler.application
28
+ assert_equal "username", Prowler.username
29
+ assert_equal "password", Prowler.password
30
+ end
31
+
32
+ should "set a default host" do
33
+ assert_equal "prowl.weks.net", Prowler.host
34
+ end
35
+
36
+ should "set a default port" do
37
+ assert_equal 443, Prowler.port
38
+ end
39
+
40
+ should "default to secure" do
41
+ assert_equal true, Prowler.secure
42
+ end
43
+
44
+ should "not set a default application" do
45
+ assert_equal nil, Prowler.application
46
+ end
47
+
48
+ should "not set a default username" do
49
+ assert_equal nil, Prowler.username
50
+ end
51
+
52
+ should "not set a default password" do
53
+ assert_equal nil, Prowler.password
54
+ end
55
+
56
+ should "raise an exception if not configured" do
57
+ assert_raises RuntimeError do
58
+ Prowler.notify "Event", "Description"
59
+ end
60
+ end
61
+ end
62
+
63
+ context "Sending a notification" do
64
+ setup do
65
+ Prowler.reset_configuration
66
+ Prowler.configure do |config|
67
+ config.application = "Application Name"
68
+ config.username = "username"
69
+ config.password = "password"
70
+ end
71
+ Prowler.send_notifications = false
72
+ end
73
+
74
+ should "encode the url parameters" do
75
+ expectation = Prowler.expects(:path)
76
+ expectation.with("Application%20Name", "Event%20Name", "Message%20Text")
77
+ expectation.returns("/api/add_notification.php?application=Application%20Name&event=Event%20Name&description=Message%20Text")
78
+ Prowler.notify("Event Name", "Message Text")
79
+ end
80
+
81
+ should "not verify SSL certificates" do
82
+ Net::HTTP.any_instance.expects(:use_ssl=).with(true)
83
+ Net::HTTP.any_instance.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
84
+ Prowler.notify("Event Name", "Message Text")
85
+ end
86
+
87
+ should "use HTTP Basic Authentication" do
88
+ Net::HTTP::Get.any_instance.expects(:basic_auth).with(Prowler.username, Prowler.password)
89
+ Prowler.notify("Event Name", "Message Text")
90
+ end
91
+
92
+ should "not send notifications if send_notifications is false" do
93
+ Net::HTTP.any_instance.expects(:request).never
94
+ Prowler.notify("Event Name", "Message Text")
95
+ end
96
+ end
97
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pixeltrix-prowler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew White
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A simple wrapper class that provides basic access to the Prowl API.
17
+ email: andyw@pixeltrix.co.uk
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - prowler.gemspec
26
+ - INSTALL
27
+ - install.rb
28
+ - lib/prowler.rb
29
+ - MIT-LICENSE
30
+ - Rakefile
31
+ - README
32
+ - tasks/prowler.rake
33
+ - test/prowler_test.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/pixeltrix/prowler/
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements:
54
+ - none
55
+ rubyforge_project:
56
+ rubygems_version: 1.2.0
57
+ signing_key:
58
+ specification_version: 2
59
+ summary: Provides access to the Prowl API.
60
+ test_files:
61
+ - test/prowler_test.rb