From 125025e078e32cbc9c577df83187ca80501e3982 Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Date: Fri, 7 Dec 2012 16:39:46 -0200 Subject: [PATCH] Send status through Notifier class. --- lib/nsca/client/notifier.rb | 17 +++++++++++++++++ spec/nsca/client/notifier_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lib/nsca/client/notifier.rb create mode 100644 spec/nsca/client/notifier_spec.rb diff --git a/lib/nsca/client/notifier.rb b/lib/nsca/client/notifier.rb new file mode 100644 index 0000000..824bfac --- /dev/null +++ b/lib/nsca/client/notifier.rb @@ -0,0 +1,17 @@ +require 'send_nsca' + +module NSCA + module Client + class Notifier + def initialize(message) + @message = message + end + + def send_nsca + connection = SendNsca::NscaConnection.new(@message.to_h) + connection.send_nsca + true + end + end + end +end diff --git a/spec/nsca/client/notifier_spec.rb b/spec/nsca/client/notifier_spec.rb new file mode 100644 index 0000000..f983770 --- /dev/null +++ b/spec/nsca/client/notifier_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe NSCA::Client::Notifier do + let(:server) { NSCA::Client::RemoteServer.new(:host => '172.0.0.1') } + let(:host) { NSCA::Client::Host.new(:hostname => 'dummy') } + let(:service) { NSCA::Client::Service.new(:name => 'TestMessage', :host => host) } + let(:message) { NSCA::Client::Message.new(:ok, 'OK', service, server) } + + context "send message successfully" do + before do + SendNsca::NscaConnection.any_instance.should_receive(:send_nsca) + end + + let(:notifier) { NSCA::Client::Notifier.new(message) } + + subject { notifier.send_nsca } + + it { should be_true } + end +end