pixeltrix-prowler 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ *1.0.2 (July 8th, 2009)
2
+
3
+ * Switch to new API using apikey and deprecate old API
4
+
5
+
6
+ *1.0.1 (July 7th, 2009)
7
+
8
+ * Update RDoc documentation
9
+
10
+ * Use Jeweler for gem management
11
+
12
+
13
+ *1.0.0 (July 7th, 2009)
14
+
15
+ * First release
data/INSTALL CHANGED
@@ -14,8 +14,7 @@ CONFIGURATION
14
14
  You should have something like this in config/initializers/prowler.rb.
15
15
 
16
16
  Prowler.configure do |config|
17
- config.username = 'username'
18
- config.password = 'password'
17
+ config.api_key = 'ffffffffffffffffffffffffffffffffffffffff'
19
18
  config.application = 'www.example.com'
20
19
  end
21
20
 
@@ -31,7 +30,7 @@ USAGE
31
30
 
32
31
  To use Prowler within your application just call the notify method, e.g.
33
32
 
34
- Prowler.notify "Event", "Description"
33
+ Prowler.notify "Event", "Description", Prowler::Priority::NORMAL
35
34
 
36
35
  ABOUT
37
36
 
data/README CHANGED
@@ -14,8 +14,7 @@ CONFIGURATION
14
14
  You should have something like this in config/initializers/prowler.rb.
15
15
 
16
16
  Prowler.configure do |config|
17
- config.username = 'username'
18
- config.password = 'password'
17
+ config.api_key = 'ffffffffffffffffffffffffffffffffffffffff'
19
18
  config.application = 'www.example.com'
20
19
  end
21
20
 
@@ -31,7 +30,7 @@ USAGE
31
30
 
32
31
  To use Prowler within your application just call the notify method, e.g.
33
32
 
34
- Prowler.notify "Event", "Description"
33
+ Prowler.notify "Event", "Description", Prowler::Priority::NORMAL
35
34
 
36
35
  ABOUT
37
36
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -11,8 +11,7 @@
11
11
  # You should have something like this in config/initializers/prowler.rb.
12
12
  #
13
13
  # Prowler.configure do |config|
14
- # config.username = 'username'
15
- # config.password = 'password'
14
+ # config.api_key = 'ffffffffffffffffffffffffffffffffffffffff'
16
15
  # config.application = 'www.example.com'
17
16
  # end
18
17
  #
@@ -28,7 +27,7 @@
28
27
  #
29
28
  # To use Prowler within your application just call the notify method, e.g.
30
29
  #
31
- # Prowler.notify "Event", "Description"
30
+ # Prowler.notify "Event", "Description", Prowler::Priority::NORMAL
32
31
  #
33
32
  # === About
34
33
  #
@@ -44,9 +43,18 @@ require 'net/http'
44
43
  require 'net/https'
45
44
 
46
45
  module Prowler
46
+
47
+ module Priority
48
+ VERY_LOW = -2
49
+ MODERATE = -1
50
+ NORMAL = 0
51
+ HIGH = 1
52
+ EMERGENCY = 2
53
+ end
54
+
47
55
  class << self
48
56
  attr_accessor :host, :port, :secure
49
- attr_accessor :username, :password
57
+ attr_accessor :api_key, :username, :password
50
58
  attr_accessor :application, :send_notifications
51
59
 
52
60
  # The host to connect to.
@@ -69,6 +77,11 @@ module Prowler
69
77
  yield self
70
78
  end
71
79
 
80
+ def username=(value) #:nodoc:
81
+ logger.warn "The username/password API has been deprecated please switch to using an API key."
82
+ @username = value
83
+ end
84
+
72
85
  # Whether to send notifications
73
86
  def send_notifications
74
87
  @send_notifications.nil? ? true : !!@send_notifications
@@ -77,15 +90,19 @@ module Prowler
77
90
 
78
91
  # Reset configuration
79
92
  def reset_configuration
80
- @host = @port = @secure = @application = @username = @password = nil
93
+ @host = @port = @secure = @application = @username = @password = @api_key = nil
81
94
  end
82
95
 
83
96
  # Whether the library has been configured
84
97
  def configured?
85
- !(@application.nil? || @username.nil? || @password.nil?)
98
+ !@application.nil? && (!@api_key.nil? || !(@username.nil? || @password.nil?))
86
99
  end
87
100
 
88
101
  def path(*params) #:nodoc:
102
+ sprintf("/publicapi/add?apikey=%s&priority=%d&application=%s&event=%s&description=%s", *params)
103
+ end
104
+
105
+ def deprecated_path(*params) #:nodoc:
89
106
  sprintf("/api/add_notification.php?application=%s&event=%s&description=%s", *params)
90
107
  end
91
108
 
@@ -97,9 +114,10 @@ module Prowler
97
114
  end
98
115
 
99
116
  # Send a notification to your iPhone:
100
- # * event: The title of notification you want to send.
101
- # * message: The text of the notification message you want to send.
102
- def notify(event, message)
117
+ # * event: The title of notification you want to send.
118
+ # * message: The text of the notification message you want to send.
119
+ # * priority: The priority of the notification - see Prowler::Priority. (Optional)
120
+ def notify(event, message, priority = Priority::NORMAL)
103
121
  raise RuntimeError, "Prowler needs to be configured first before using it" unless configured?
104
122
 
105
123
  http = Net::HTTP.new(host, port)
@@ -111,8 +129,12 @@ module Prowler
111
129
  }
112
130
  http.read_timeout = 5 # seconds
113
131
  http.open_timeout = 2 # seconds
114
- request = Net::HTTP::Get.new(path(URI.escape(application), URI.escape(event), URI.escape(message)), headers)
115
- request.basic_auth(username, password)
132
+ if api_key
133
+ request = Net::HTTP::Get.new(path(api_key, priority, URI.escape(application), URI.escape(event), URI.escape(message)), headers)
134
+ else
135
+ request = Net::HTTP::Get.new(deprecated_path(URI.escape(application), URI.escape(event), URI.escape(message)), headers)
136
+ request.basic_auth(username, password)
137
+ end
116
138
  response = begin
117
139
  http.request(request) if send_notifications?
118
140
  rescue TimeoutError => e
@@ -2,18 +2,19 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{prowler}
5
- s.version = "1.0.1"
5
+ s.version = "1.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Andrew White"]
9
- s.date = %q{2009-07-07}
9
+ s.date = %q{2009-07-08}
10
10
  s.description = %q{A simple wrapper class that provides basic access to the Prowl API.}
11
11
  s.email = %q{andyw@pixeltrix.co.uk}
12
12
  s.extra_rdoc_files = [
13
13
  "README"
14
14
  ]
15
15
  s.files = [
16
- "INSTALL",
16
+ "CHANGELOG",
17
+ "INSTALL",
17
18
  "MIT-LICENSE",
18
19
  "README",
19
20
  "Rakefile",
@@ -16,17 +16,15 @@ class ProwlerTest < Test::Unit::TestCase
16
16
  config.host = "prowler"
17
17
  config.port = 666
18
18
  config.secure = false
19
+ config.api_key = "apikey"
19
20
  config.application = "application"
20
- config.username = "username"
21
- config.password = "password"
22
21
  end
23
22
 
24
23
  assert_equal "prowler", Prowler.host
25
24
  assert_equal 666, Prowler.port
26
25
  assert_equal false, Prowler.secure
26
+ assert_equal "apikey", Prowler.api_key
27
27
  assert_equal "application", Prowler.application
28
- assert_equal "username", Prowler.username
29
- assert_equal "password", Prowler.password
30
28
  end
31
29
 
32
30
  should "set a default host" do
@@ -45,6 +43,43 @@ class ProwlerTest < Test::Unit::TestCase
45
43
  assert_equal nil, Prowler.application
46
44
  end
47
45
 
46
+ should "not set a default API key" do
47
+ assert_equal nil, Prowler.api_key
48
+ end
49
+
50
+ should "raise an exception if not configured" do
51
+ assert_raises RuntimeError do
52
+ Prowler.notify("Event", "Description", Prowler::Priority::NORMAL)
53
+ end
54
+ end
55
+ end
56
+
57
+ context "Prowler deprecated configuration" do
58
+ setup do
59
+ Logger.any_instance.stubs(:warn)
60
+ Prowler.reset_configuration
61
+ Prowler.send_notifications = false
62
+ end
63
+
64
+ should "be done with a block" do
65
+ Prowler.configure do |config|
66
+ config.host = "prowler"
67
+ config.port = 666
68
+ config.secure = false
69
+ config.application = "application"
70
+ config.username = "username"
71
+ config.password = "password"
72
+ end
73
+
74
+ assert_equal "username", Prowler.username
75
+ assert_equal "password", Prowler.password
76
+ end
77
+
78
+ should "log a warning when using the deprecated API" do
79
+ Logger.any_instance.expects(:warn).with("The username/password API has been deprecated please switch to using an API key.")
80
+ Prowler.configure { |config| config.username = "username" }
81
+ end
82
+
48
83
  should "not set a default username" do
49
84
  assert_equal nil, Prowler.username
50
85
  end
@@ -55,7 +90,7 @@ class ProwlerTest < Test::Unit::TestCase
55
90
 
56
91
  should "raise an exception if not configured" do
57
92
  assert_raises RuntimeError do
58
- Prowler.notify "Event", "Description"
93
+ Prowler.notify("Event", "Description", Prowler::Priority::NORMAL)
59
94
  end
60
95
  end
61
96
  end
@@ -64,34 +99,28 @@ class ProwlerTest < Test::Unit::TestCase
64
99
  setup do
65
100
  Prowler.reset_configuration
66
101
  Prowler.configure do |config|
102
+ config.api_key = "apikey"
67
103
  config.application = "Application Name"
68
- config.username = "username"
69
- config.password = "password"
70
104
  end
71
105
  Prowler.send_notifications = false
72
106
  end
73
107
 
74
108
  should "encode the url parameters" do
75
109
  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")
110
+ expectation.with("apikey", 0, "Application%20Name", "Event%20Name", "Message%20Text")
111
+ expectation.returns("/publicapi/add?apikey=apikey&priority=0application=Application%20Name&event=Event%20Name&description=Message%20Text")
112
+ Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
79
113
  end
80
114
 
81
115
  should "not verify SSL certificates" do
82
116
  Net::HTTP.any_instance.expects(:use_ssl=).with(true)
83
117
  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")
118
+ Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
90
119
  end
91
120
 
92
121
  should "not send notifications if send_notifications is false" do
93
122
  Net::HTTP.any_instance.expects(:request).never
94
- Prowler.notify("Event Name", "Message Text")
123
+ Prowler.notify("Event Name", "Message Text", Prowler::Priority::NORMAL)
95
124
  end
96
125
  end
97
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixeltrix-prowler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew White
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-07 00:00:00 -07:00
12
+ date: 2009-07-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,6 +22,7 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README
24
24
  files:
25
+ - CHANGELOG
25
26
  - INSTALL
26
27
  - MIT-LICENSE
27
28
  - README