prowler 1.1.1

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.
@@ -0,0 +1,46 @@
1
+ *1.1.1 (August 4th, 2009)
2
+
3
+ * Add support for verifying server certificate
4
+
5
+ * Add support for passing multiple API keys
6
+
7
+
8
+ *1.1.0 (July 10th, 2009)
9
+
10
+ * Add support for Delayed::Job background processing
11
+
12
+ * Update documentation for instance level configuration
13
+
14
+ * Add support for instance level configuration
15
+
16
+ * Add support for provider key
17
+
18
+ * Clean up implementation
19
+
20
+ * Remove unnecessary configuration
21
+
22
+ * Remove deprecated API
23
+
24
+
25
+ *1.0.3 (July 9th, 2009)
26
+
27
+ * Add verify method for configured API key
28
+
29
+ * Use POST to send notifications
30
+
31
+
32
+ *1.0.2 (July 8th, 2009)
33
+
34
+ * Switch to new API using apikey and deprecate old API
35
+
36
+
37
+ *1.0.1 (July 7th, 2009)
38
+
39
+ * Update RDoc documentation
40
+
41
+ * Use Jeweler for gem management
42
+
43
+
44
+ *1.0.0 (July 7th, 2009)
45
+
46
+ * First release
data/INSTALL ADDED
@@ -0,0 +1,59 @@
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.api_key = 'ffffffffffffffffffffffffffffffffffffffff'
18
+ config.application = 'www.example.com'
19
+ end
20
+
21
+ You can test that Prowler is working in your production environment by using
22
+ this rake task (from RAILS_ROOT):
23
+
24
+ rake prowler:test
25
+
26
+ If everything is configured properly the task will send a request to
27
+ prowl.weks.net which will be appear on your iPhone after a short delay.
28
+
29
+ USAGE
30
+
31
+ To use Prowler within your application just call the notify method, e.g.
32
+
33
+ Prowler.notify "Event", "Description", Prowler::Priority::NORMAL
34
+
35
+ If you need to send to multiple accounts from within a single application you
36
+ can create an instance of the Prowler class to override the global settings, e.g.
37
+
38
+ prowler = Prowler.new('apikey', 'application')
39
+ prowler.notify "Event", "Description", Prowler::Priority::NORMAL
40
+
41
+ If performance is a concern then there is built in support for Delayed::Job.
42
+ This can done either on a global basis, e.g.
43
+
44
+ Prowler.configure do |config|
45
+ config.delayed = true
46
+ end
47
+
48
+ or on a individual message basis, e.g.
49
+
50
+ Prowler.notify "Event", "Description", Prowler::Priority::NORMAL, true
51
+
52
+ ABOUT
53
+
54
+ Prowler relies upon the Prowl iPhone application which is advertised as
55
+ a Growl notification forwarder from your Mac. However they provide an API
56
+ which can be called by a generic script which allows you to use the
57
+ application as a general push notification application for your iPhone.
58
+
59
+ For more about the Prowl application see: http://prowl.weks.net/
@@ -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,59 @@
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.api_key = 'ffffffffffffffffffffffffffffffffffffffff'
18
+ config.application = 'www.example.com'
19
+ end
20
+
21
+ You can test that Prowler is working in your production environment by using
22
+ this rake task (from RAILS_ROOT):
23
+
24
+ rake prowler:test
25
+
26
+ If everything is configured properly the task will send a request to
27
+ prowl.weks.net which will be appear on your iPhone after a short delay.
28
+
29
+ USAGE
30
+
31
+ To use Prowler within your application just call the notify method, e.g.
32
+
33
+ Prowler.notify "Event", "Description", Prowler::Priority::NORMAL
34
+
35
+ If you need to send to multiple accounts from within a single application you
36
+ can create an instance of the Prowler class to override the global settings, e.g.
37
+
38
+ prowler = Prowler.new('apikey', 'application')
39
+ prowler.notify "Event", "Description", Prowler::Priority::NORMAL
40
+
41
+ If performance is a concern then there is built in support for Delayed::Job.
42
+ This can done either on a global basis, e.g.
43
+
44
+ Prowler.configure do |config|
45
+ config.delayed = true
46
+ end
47
+
48
+ or on a individual message basis, e.g.
49
+
50
+ Prowler.notify "Event", "Description", Prowler::Priority::NORMAL, true
51
+
52
+ ABOUT
53
+
54
+ Prowler relies upon the Prowl iPhone application which is advertised as
55
+ a Growl notification forwarder from your Mac. However they provide an API
56
+ which can be called by a generic script which allows you to use the
57
+ application as a general push notification application for your iPhone.
58
+
59
+ For more about the Prowl application see: http://prowl.weks.net/
@@ -0,0 +1,37 @@
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
23
+
24
+ begin
25
+ require 'jeweler'
26
+ Jeweler::Tasks.new do |gemspec|
27
+ gemspec.name = "prowler"
28
+ gemspec.summary = "Provides access to the Prowl API."
29
+ gemspec.email = "andyw@pixeltrix.co.uk"
30
+ gemspec.homepage = "http://github.com/pixeltrix/prowler/"
31
+ gemspec.description = "A simple wrapper class that provides basic access to the Prowl API."
32
+ gemspec.authors = ["Andrew White"]
33
+ end
34
+ Jeweler::GemcutterTasks.new
35
+ rescue LoadError
36
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
37
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.1
@@ -0,0 +1 @@
1
+ puts IO.read(File.join(File.dirname(__FILE__), 'INSTALL'))
@@ -0,0 +1,296 @@
1
+ # Prowler is a plugin for integrating apps with the Prowl iPhone application.
2
+ #
3
+ # === Installation
4
+ #
5
+ # From your project's RAILS_ROOT, run:
6
+ #
7
+ # script/plugin install git://github.com/pixeltrix/prowler.git
8
+ #
9
+ # === Configuration
10
+ #
11
+ # You should have something like this in config/initializers/prowler.rb.
12
+ #
13
+ # Prowler.configure do |config|
14
+ # config.api_key = 'ffffffffffffffffffffffffffffffffffffffff'
15
+ # config.application = 'www.example.com'
16
+ # end
17
+ #
18
+ # You can test that Prowler is working in your production environment by using
19
+ # this rake task (from RAILS_ROOT):
20
+ #
21
+ # rake prowler:test
22
+ #
23
+ # If everything is configured properly the task will send a request to
24
+ # prowl.weks.net which will be appear on your iPhone after a short delay.
25
+ #
26
+ # === Usage
27
+ #
28
+ # To use Prowler within your application just call the notify method, e.g.
29
+ #
30
+ # Prowler.notify "Event", "Description", Prowler::Priority::NORMAL
31
+ #
32
+ # If you need to send to multiple accounts from within a single application you
33
+ # can create an instance of the Prowler class to override the global settings, e.g.
34
+ #
35
+ # prowler = Prowler.new('apikey', 'application')
36
+ # prowler.notify "Event", "Description", Prowler::Priority::NORMAL
37
+ #
38
+ # If performance is a concern then there is built in support for Delayed::Job.
39
+ # This can done either on a global basis, e.g.
40
+ #
41
+ # Prowler.configure do |config|
42
+ # config.delayed = true
43
+ # end
44
+ #
45
+ # or on a individual message basis, e.g.
46
+ #
47
+ # Prowler.notify "Event", "Description", Prowler::Priority::NORMAL, true
48
+ #
49
+ # === About
50
+ #
51
+ # Prowler relies upon the Prowl iPhone application which is advertised as
52
+ # a Growl notification forwarder from your Mac. However they provide an API
53
+ # which can be called by a generic script which allows you to use the
54
+ # application as a general push notification application for your iPhone.
55
+ #
56
+ # For more about the Prowl application see: http://prowl.weks.net/
57
+
58
+ require 'logger'
59
+ require 'net/https'
60
+ require 'uri'
61
+
62
+ class Prowler
63
+
64
+ SERVICE_URL = "https://prowl.weks.net/publicapi"
65
+ USER_AGENT = "Prowler/1.1.1"
66
+ MULTIPLE_APIKEY_COMMANDS = %w(add)
67
+
68
+ module Priority
69
+ VERY_LOW = -2
70
+ MODERATE = -1
71
+ NORMAL = 0
72
+ HIGH = 1
73
+ EMERGENCY = 2
74
+ end
75
+
76
+ class ConfigurationError < StandardError; end
77
+
78
+ class DelayedJob
79
+ attr_accessor :api_key, :provider_key, :application
80
+ attr_accessor :event, :message, :priority
81
+
82
+ def initialize #:nodoc:
83
+ yield self if block_given?
84
+ end
85
+
86
+ # Send notification
87
+ def perform
88
+ prowler = Prowler.new(api_key, application, provider_key)
89
+ prowler.notify(event, message, priority, false)
90
+ end
91
+ end
92
+
93
+ class << self
94
+ attr_accessor :api_key, :provider_key
95
+ attr_accessor :application, :send_notifications
96
+ attr_accessor :read_timeout, :open_timeout #:nodoc:
97
+ attr_accessor :delayed, :verify_certificate, :root_certificates
98
+
99
+ # Call this method to configure your account details in an initializer.
100
+ def configure
101
+ yield self
102
+ end
103
+
104
+ def send_notifications #:nodoc:
105
+ @send_notifications.nil? ? true : !!@send_notifications
106
+ end
107
+
108
+ def delayed #:nodoc:
109
+ @delayed.nil? ? false : !!@delayed
110
+ end
111
+
112
+ # Reset configuration
113
+ def reset_configuration
114
+ @application = @api_key = @provider_key = nil
115
+ @delayed = @verify_certificate = @root_certificates = nil
116
+ end
117
+
118
+ # Whether the library has been configured
119
+ def configured?
120
+ !@application.nil? && !@api_key.nil?
121
+ end
122
+
123
+ # Whether to verify the server's SSL certificate
124
+ def verify_certificate?
125
+ @verify_certificate ||= false
126
+ end
127
+
128
+ # Location of the root certificates file.
129
+ # Default: RAILS_ROOT/config/cacert.pem
130
+ def root_certificates
131
+ @root_certificates ||= File.join(RAILS_ROOT, "config", "cacert.pem")
132
+ end
133
+
134
+ # Returns the default logger or a logger that prints to STDOUT.
135
+ def logger
136
+ ActiveRecord::Base.logger
137
+ rescue
138
+ @logger ||= Logger.new(STDERR)
139
+ end
140
+
141
+ def read_timeout #:nodoc:
142
+ @read_timeout ||= 5
143
+ end
144
+
145
+ def open_timeout #:nodoc:
146
+ @open_timeout ||= 2
147
+ end
148
+
149
+ # Send a notification to your iPhone:
150
+ # * event: The title of notification you want to send.
151
+ # * message: The text of the notification message you want to send.
152
+ # * priority: The priority of the notification - see Prowler::Priority. (Optional)
153
+ # * delayed: Whether to use Delayed::Job to send notifications. (Optional)
154
+ def notify(event, message, priority = Priority::NORMAL, delayed = self.delayed)
155
+ raise ConfigurationError, "You must provide an API key to send notifications" if api_key.nil?
156
+ raise ConfigurationError, "You must provide an application name to send notifications" if application.nil?
157
+ if delayed
158
+ enqueue_delayed_job(self, event, message, priority)
159
+ else
160
+ perform(
161
+ :add, api_key, provider_key,
162
+ {
163
+ :application => application,
164
+ :event => event,
165
+ :description => message,
166
+ :priority => priority
167
+ }
168
+ )
169
+ end
170
+ end
171
+
172
+ # Verify the configured API key is valid
173
+ def verify
174
+ raise ConfigurationError, "You must provide an API key to verify" if api_key.nil?
175
+ perform(:verify, api_key, provider_key, {}, :get)
176
+ end
177
+
178
+ def perform(command, api_key, provider_key, data = {}, method = :post) #:nodoc:
179
+ params = { :apikey => format_api_key(command, api_key), :provider_key => provider_key }.merge(data).delete_if { |k,v| v.nil? }
180
+ case method
181
+ when :post
182
+ perform_post(command, params)
183
+ else
184
+ perform_get(command, params)
185
+ end
186
+ end
187
+
188
+ def enqueue_delayed_job(config, event, message, priority) #:nodoc:
189
+ record = Delayed::Job.enqueue(DelayedJob.new do |job|
190
+ job.api_key = config.api_key
191
+ job.provider_key = config.provider_key
192
+ job.application = config.application
193
+ job.event = event
194
+ job.message = message
195
+ job.priority = priority
196
+ end)
197
+ !record.new_record?
198
+ end
199
+
200
+ private
201
+ def headers(extra_headers = {}) #:nodoc:
202
+ { 'User-Agent' => USER_AGENT }.merge(extra_headers)
203
+ end
204
+
205
+ def perform_get(command, params) #:nodoc:
206
+ url = URI.parse("#{SERVICE_URL}/#{command}?#{params.map{ |k,v| %(#{URI.encode(k.to_s)}=#{URI.encode(v.to_s)}) }.join('&')}")
207
+ request = Net::HTTP::Get.new("#{url.path}?#{url.query}", headers)
208
+ perform_request(url, request)
209
+ end
210
+
211
+ def perform_post(command, params) #:nodoc:
212
+ url = URI.parse("#{SERVICE_URL}/#{command}")
213
+ request = Net::HTTP::Post.new(url.path, headers)
214
+ request.form_data = params
215
+ perform_request(url, request)
216
+ end
217
+
218
+ def perform_request(url, request) #:nodoc:
219
+ http = Net::HTTP.new(url.host, url.port)
220
+ http.use_ssl = true
221
+ if verify_certificate?
222
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
223
+ http.ca_file = root_certificates
224
+ else
225
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
226
+ end
227
+ http.read_timeout = read_timeout
228
+ http.open_timeout = open_timeout
229
+ http.start do
230
+ begin
231
+ return true unless send_notifications
232
+ response = http.request(request)
233
+ case response
234
+ when Net::HTTPSuccess then
235
+ logger.info "Prowl Success: #{response.class}"
236
+ true
237
+ else
238
+ logger.error "Prowl Failure: #{response.class}\n#{response.body if response.respond_to? :body}"
239
+ false
240
+ end
241
+ rescue TimeoutError => e
242
+ logger.error "Timeout while contacting the Prowl server."
243
+ false
244
+ end
245
+ end
246
+ end
247
+
248
+ def format_api_key(command, api_key)
249
+ if api_key.is_a?(Array)
250
+ MULTIPLE_APIKEY_COMMANDS.include?(command.to_s) ? api_key.join(",") : api_key.first.to_s
251
+ else
252
+ api_key.to_s
253
+ end
254
+ end
255
+ end
256
+
257
+ attr_accessor :api_key, :provider_key #:nodoc:
258
+ attr_accessor :application, :send_notifications #:nodoc:
259
+
260
+ # Create an instance for sending to different accounts within a single Rails application
261
+ # * api_key: Your API key.
262
+ # * application: The name of your application.
263
+ # * provider_key: Key to override the rate limit of 1000 requests per hour. (Optional)
264
+ def initialize(api_key, application, provider_key = nil)
265
+ @api_key, @application, @provider_key = api_key, application, provider_key
266
+ end
267
+
268
+ # Send a notification to your iPhone:
269
+ # * event: The title of notification you want to send.
270
+ # * message: The text of the notification message you want to send.
271
+ # * priority: The priority of the notification - see Prowler::Priority. (Optional)
272
+ # * delayed: Whether to use Delayed::Job to send notifications. (Optional)
273
+ def notify(event, message, priority = Priority::NORMAL, delayed = self.class.delayed)
274
+ raise ConfigurationError, "You must provide an API key to send notifications" if api_key.nil?
275
+ raise ConfigurationError, "You must provide an application name to send notifications" if application.nil?
276
+ if delayed
277
+ self.class.enqueue_delayed_job(self, event, message, priority)
278
+ else
279
+ self.class.perform(
280
+ :add, api_key, provider_key,
281
+ {
282
+ :application => application,
283
+ :event => event,
284
+ :description => message,
285
+ :priority => priority
286
+ }
287
+ )
288
+ end
289
+ end
290
+
291
+ # Verify the configured API key is valid
292
+ def verify
293
+ raise ConfigurationError, "You must provide an API key to verify" if api_key.nil?
294
+ self.class.perform(:verify, api_key, provider_key, {}, :get)
295
+ end
296
+ end
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{prowler}
8
+ s.version = "1.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andrew White"]
12
+ s.date = %q{2009-10-05}
13
+ s.description = %q{A simple wrapper class that provides basic access to the Prowl API.}
14
+ s.email = %q{andyw@pixeltrix.co.uk}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ "CHANGELOG",
20
+ "INSTALL",
21
+ "MIT-LICENSE",
22
+ "README",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "install.rb",
26
+ "lib/prowler.rb",
27
+ "prowler.gemspec",
28
+ "tasks/prowler.rake",
29
+ "test/config/cacert.pem",
30
+ "test/prowler_test.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/pixeltrix/prowler/}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Provides access to the Prowl API.}
37
+ s.test_files = [
38
+ "test/prowler_test.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ else
47
+ end
48
+ else
49
+ end
50
+ 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,17 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJVUzEQMA4GA1UE
3
+ ChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5
4
+ MB4XDTk4MDgyMjE2NDE1MVoXDTE4MDgyMjE2NDE1MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoT
5
+ B0VxdWlmYXgxLTArBgNVBAsTJEVxdWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0eTCB
6
+ nzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2RFGiYCh7+2gRvE4RiIcPR
7
+ fM6fBeC4AfBONOziipUEZKzxa1NfBbPLZ4C/QgKO/t0BCezhABRP/PvwDN1Dulsr4R+AcJkVV5MW
8
+ 8Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kCAwEAAaOCAQkwggEFMHAG
9
+ A1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UE
10
+ CxMkRXF1aWZheCBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoG
11
+ A1UdEAQTMBGBDzIwMTgwODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvS
12
+ spXXR9gjIBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQFMAMB
13
+ Af8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUAA4GBAFjOKer89961
14
+ zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y7qj/WsjTVbJmcVfewCHrPSqnI0kB
15
+ BIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee95
16
+ 70+sB3c4
17
+ -----END CERTIFICATE-----
@@ -0,0 +1,165 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require 'shoulda'
5
+ require File.join(File.dirname(__FILE__), "..", "lib", "prowler")
6
+
7
+ RAILS_ROOT = File.dirname(__FILE__)
8
+
9
+ class ProwlerTest < Test::Unit::TestCase
10
+ context "Prowler configuration" do
11
+ setup do
12
+ Prowler.reset_configuration
13
+ Prowler.send_notifications = false
14
+ end
15
+
16
+ should "be done with a block" do
17
+ Prowler.configure do |config|
18
+ config.api_key = "apikey"
19
+ config.application = "application"
20
+ end
21
+
22
+ assert_equal "apikey", Prowler.api_key
23
+ assert_equal "application", Prowler.application
24
+ end
25
+
26
+ should "not set a default application" do
27
+ assert_equal nil, Prowler.application
28
+ end
29
+
30
+ should "not set a default API key" do
31
+ assert_equal nil, Prowler.api_key
32
+ end
33
+
34
+ should "override class configuration when using an instance" do
35
+ prowler = Prowler.new("apikey2", "application2")
36
+ assert_equal "apikey2", prowler.api_key
37
+ assert_equal "application2", prowler.application
38
+ end
39
+ end
40
+
41
+ context "Sending a notification" do
42
+ setup do
43
+ Prowler.reset_configuration
44
+ Prowler.configure do |config|
45
+ config.api_key = "apikey"
46
+ config.application = "Application Name"
47
+ end
48
+ Prowler.send_notifications = false
49
+ end
50
+
51
+ should "raise an exception if API key not configured" do
52
+ Prowler.reset_configuration
53
+ assert_raises Prowler::ConfigurationError do
54
+ Prowler.notify("Event", "Description", Prowler::Priority::NORMAL)
55
+ end
56
+
57
+ prowler = Prowler.new(nil, nil)
58
+ assert_raises Prowler::ConfigurationError do
59
+ prowler.notify("Event", "Description", Prowler::Priority::NORMAL)
60
+ end
61
+ end
62
+
63
+ should "raise an exception if application not configured" do
64
+ Prowler.reset_configuration
65
+ Prowler.configure do |config|
66
+ config.api_key = "apikey"
67
+ end
68
+ assert_raises Prowler::ConfigurationError do
69
+ Prowler.notify("Event", "Description", Prowler::Priority::NORMAL)
70
+ end
71
+
72
+ prowler = Prowler.new("apikey", nil)
73
+ assert_raises Prowler::ConfigurationError do
74
+ prowler.notify("Event", "Description", Prowler::Priority::NORMAL)
75
+ end
76
+ end
77
+
78
+ should "not verify SSL certificates by default" do
79
+ Net::HTTP.any_instance.expects(:use_ssl=).with(true)
80
+ Net::HTTP.any_instance.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
81
+ Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
82
+ end
83
+
84
+ should "verify SSL certificates if verification is turned on" do
85
+ Prowler.configure do |config|
86
+ config.verify_certificate = true
87
+ end
88
+ Net::HTTP.any_instance.expects(:use_ssl=).with(true)
89
+ Net::HTTP.any_instance.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
90
+ Net::HTTP.any_instance.expects(:ca_file=).with(File.join(RAILS_ROOT, "config", "cacert.pem"))
91
+ Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
92
+ end
93
+
94
+ should "not send notifications if send_notifications is false" do
95
+ Net::HTTP.any_instance.expects(:request).never
96
+ Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
97
+ end
98
+
99
+ should "send multiple API keys if configured" do
100
+ Prowler.configure do |config|
101
+ config.api_key = %w(apikey1 apikey2)
102
+ end
103
+ Net::HTTP::Post.any_instance.expects(:form_data=).with({
104
+ :apikey => "apikey1,apikey2",
105
+ :application => "Application Name",
106
+ :event => "Event Name",
107
+ :description => "Message Text",
108
+ :priority => Prowler::Priority::NORMAL
109
+ })
110
+ Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
111
+ end
112
+ end
113
+
114
+ context "Verifying an API key" do
115
+ setup do
116
+ Prowler.reset_configuration
117
+ Prowler.configure do |config|
118
+ config.api_key = "apikey"
119
+ config.application = "Application Name"
120
+ end
121
+ Prowler.send_notifications = false
122
+ end
123
+
124
+ should "raise an exception if API key not configured" do
125
+ Prowler.reset_configuration
126
+ assert_raises Prowler::ConfigurationError do
127
+ Prowler.verify
128
+ end
129
+
130
+ prowler = Prowler.new(nil, nil)
131
+ assert_raises Prowler::ConfigurationError do
132
+ prowler.verify
133
+ end
134
+ end
135
+
136
+ should "only verify the first API key" do
137
+ Prowler.configure do |config|
138
+ config.api_key = %w(apikey1 apikey2)
139
+ end
140
+ Net::HTTP::Get.expects(:new).with("/publicapi/verify?apikey=apikey1", { 'User-Agent' => Prowler::USER_AGENT }).once
141
+ Prowler.verify
142
+ end
143
+
144
+ should "not verify SSL certificates by default" do
145
+ Net::HTTP.any_instance.expects(:use_ssl=).with(true)
146
+ Net::HTTP.any_instance.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
147
+ Prowler.verify
148
+ end
149
+
150
+ should "verify SSL certificates if verification is turned on" do
151
+ Prowler.configure do |config|
152
+ config.verify_certificate = true
153
+ end
154
+ Net::HTTP.any_instance.expects(:use_ssl=).with(true)
155
+ Net::HTTP.any_instance.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
156
+ Net::HTTP.any_instance.expects(:ca_file=).with(File.join(RAILS_ROOT, "config", "cacert.pem"))
157
+ Prowler.verify
158
+ end
159
+
160
+ should "not send notifications if send_notifications is false" do
161
+ Net::HTTP.any_instance.expects(:request).never
162
+ Prowler.verify
163
+ end
164
+ end
165
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prowler
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew White
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-05 00:00:00 +01: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
+ - README
24
+ files:
25
+ - CHANGELOG
26
+ - INSTALL
27
+ - MIT-LICENSE
28
+ - README
29
+ - Rakefile
30
+ - VERSION
31
+ - install.rb
32
+ - lib/prowler.rb
33
+ - prowler.gemspec
34
+ - tasks/prowler.rake
35
+ - test/config/cacert.pem
36
+ - test/prowler_test.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/pixeltrix/prowler/
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Provides access to the Prowl API.
65
+ test_files:
66
+ - test/prowler_test.rb