Skip to content
Browse files

finished post request notifier, added it to readme & spec

  • Loading branch information...
1 parent 8d43866 commit a72588f91f275ed1abc1a6a368315bdc616ea250 @deanperry deanperry committed
Showing with 146 additions and 1 deletion.
  1. +14 −0 README.md
  2. +1 −1 spec/cli/utility_spec.rb
  3. +120 −0 spec/notifier/post_request_spec.rb
  4. +11 −0 templates/cli/utility/notifier/post_request
View
14 README.md
@@ -118,6 +118,7 @@ Below you find a list of components that Backup currently supports. If you'd lik
- Prowl
- Hipchat
- Pushover
+- POST Request
[Notifiers Wiki Page](https://github.com/meskyanichi/backup/wiki/Notifiers)
@@ -220,6 +221,15 @@ Backup::Model.new(:sample_backup, 'A sample backup configuration') do
tweet.on_failure = true
end
+ notify_by PostRequest do |post|
+ post.on_success = true
+ post.on_warning = true
+ post.on_failure = true
+
+ post.host = "http://my-backup-notifier.com"
+ post.token = "123-abc-123-abc"
+ end
+
end
```
@@ -432,6 +442,10 @@ View the [issue log](https://github.com/meskyanichi/backup/issues) and post them
<td><a href="https://github.com/SteveNewson" target="_blank">Steve Newson ( SteveNewson )</a></td>
<td>Pushover Notifier</td>
</tr>
+ <tr>
+ <td><a href="https://github.com/DeanPerry" target="_blank">Dean Perry ( DeanPerry )</a></td>
+ <td>POST Request Notifier</td>
+ </tr>
</table>
View
2 spec/cli/utility_spec.rb
@@ -222,7 +222,7 @@
[--syncers=SYNCERS] # (cloud_files, rsync_local, rsync_pull, rsync_push, s3)
[--encryptors=ENCRYPTORS] # (gpg, openssl)
[--compressors=COMPRESSORS] # (bzip2, custom, gzip, lzma, pbzip2)
- [--notifiers=NOTIFIERS] # (campfire, hipchat, mail, prowl, pushover, twitter)
+ [--notifiers=NOTIFIERS] # (campfire, hipchat, mail, post_request, prowl, pushover, twitter)
[--archives]
[--splitter] # use `--no-splitter` to disable
# Default: true
View
120 spec/notifier/post_request_spec.rb
@@ -0,0 +1,120 @@
+# encoding: utf-8
+
+require File.expand_path('../../spec_helper.rb', __FILE__)
+
+describe Backup::Notifier::PostRequest do
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
+ let(:notifier) do
+ Backup::Notifier::PostRequest.new(model) do |notifier|
+ notifier.host = 'http://host.com'
+ notifier.token = 'token'
+ end
+ end
+
+ it 'should be a subclass of Notifier::Base' do
+ Backup::Notifier::PostRequest.
+ superclass.should == Backup::Notifier::Base
+ end
+
+ describe '#initialize' do
+ after { Backup::Notifier::PostRequest.clear_defaults! }
+
+ it 'should load pre-configured defaults through Base' do
+ Backup::Notifier::PostRequest.any_instance.expects(:load_defaults!)
+ notifier
+ end
+
+ it 'should pass the model reference to Base' do
+ notifier.instance_variable_get(:@model).should == model
+ end
+
+ context 'when no pre-configured defaults have been set' do
+ it 'should use the values given' do
+ notifier.host.should == 'http://host.com'
+ notifier.token.should == 'token'
+
+ notifier.on_success.should == true
+ notifier.on_warning.should == true
+ notifier.on_failure.should == true
+ end
+
+ it 'should use default values if none are given' do
+ notifier = Backup::Notifier::PostRequest.new(model)
+ notifier.token.should be_nil
+ notifier.host.should be_nil
+
+ notifier.on_success.should == true
+ notifier.on_warning.should == true
+ notifier.on_failure.should == true
+ end
+ end # context 'when no pre-configured defaults have been set'
+
+ context 'when pre-configured defaults have been set' do
+ before do
+ Backup::Notifier::PostRequest.defaults do |n|
+ n.token = 'the_token'
+ n.host = 'http://anotherhost.com'
+ n.on_failure = false
+ end
+ end
+
+ it 'should use pre-configured defaults' do
+ notifier = Backup::Notifier::PostRequest.new(model)
+
+ notifier.token.should == 'the_token'
+ notifier.host.should == 'http://anotherhost.com'
+
+ notifier.on_success.should == true
+ notifier.on_warning.should == true
+ notifier.on_failure.should == false
+ end
+
+ it 'should override pre-configured defaults' do
+ notifier = Backup::Notifier::PostRequest.new(model) do |n|
+ n.token = 'new_token'
+ n.host = 'http://testhost.com'
+ n.on_success = false
+ n.on_failure = true
+ end
+
+ notifier.token.should == 'new_token'
+ notifier.host.should == 'http://testhost.com'
+
+ notifier.on_success.should == false
+ notifier.on_warning.should == true
+ notifier.on_failure.should == true
+ end
+ end # context 'when pre-configured defaults have been set'
+ end # describe '#initialize'
+
+ # Can't really test this area without a working host
+ #
+ # describe '#notify!' do
+ # context 'when status is :success' do
+ # it 'should send Success message' do
+ # notifier.expects(:send_message).with(
+ # '[Backup::Success] test label (test_trigger)'
+ # )
+ # notifier.send(:notify!, :success)
+ # end
+ # end
+
+ # context 'when status is :warning' do
+ # it 'should send Warning message' do
+ # notifier.expects(:send_message).with(
+ # '[Backup::Warning] test label (test_trigger)'
+ # )
+ # notifier.send(:notify!, :warning)
+ # end
+ # end
+
+ # context 'when status is :failure' do
+ # it 'should send Failure message' do
+ # notifier.expects(:send_message).with(
+ # '[Backup::Failure] test label (test_trigger)'
+ # )
+ # notifier.send(:notify!, :failure)
+ # end
+ # end
+ # end # describe '#notify!'
+end
View
11 templates/cli/utility/notifier/post_request
@@ -0,0 +1,11 @@
+ ##
+ # Post Request [Notifier]
+ #
+ notify_by PostRequest do |post|
+ post.on_success = true
+ post.on_warning = true
+ post.on_failure = true
+
+ post.host = "http://host.com"
+ post.token = "TOKEN" # This is optional
+ end

0 comments on commit a72588f

Please sign in to comment.
Something went wrong with that request. Please try again.