Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Commit

Permalink
allowing delivery of notifo messages to a single user
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Warren committed Sep 23, 2011
1 parent 9ca458c commit 12b7a0a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
13 changes: 8 additions & 5 deletions lib/ceiling_cat/plugins/notifo.rb
Expand Up @@ -6,17 +6,20 @@ class NotifoNotConfiguredError < CeilingCatError; end
module Plugin
class Notifo < CeilingCat::Plugin::Base
def self.commands
[{:command => "notifo", :description => "Send a message with Notifo - '!notifo Hey, get in here!'.", :method => "deliver"},
[{:command => "notifo", :description => "Send a message with Notifo - '!notifo user: Hey, get in here!'. 'user:' is optional, and will go to everyone if not passed.", :method => "deliver"},
{:command => "add notifo users", :description => "Add users to get Notifos - '!add notifo users username1 username2'.", :method => "add_users"},
{:command => "remove notifo users", :description => "Add users to get Notifos - '!remove notifo users username1 username2'.", :method => "remove_users"},
{:command => "list notifo users", :description => "List users who get Notifos - '!list notifo users'.", :method => "list_users"}]
end

def deliver(message=nil,opts={})
message ||= body_without_nick_or_command("notifo")
users = Array(opts[:users]) || Array(store["notifo_users"])
def deliver(message=nil)
body_parts = body_without_nick_or_command("notifo").scan(/^((\w+):)?(.+)$/)[0]
message ||= body_parts[2].strip
user = body_parts[1]

users = user ? Array(user.strip) : Array(store["notifo_users"])
users.each do |user|
CeilingCat::Plugin::Notifo.deliver(message,user)
CeilingCat::Plugin::Notifo.deliver(user,message)
end
end

Expand Down
44 changes: 41 additions & 3 deletions spec/ceiling_cat/plugins/notifo_spec.rb
Expand Up @@ -23,7 +23,7 @@
end

it "should send a notifo message" do
FakeWeb.register_uri(:post, "https://username:api_secret@api.notifo.com/v1/send_notification")
FakeWeb.register_uri(:post, "https://username:api_secret@api.notifo.com/v1/send_notification", :body => '')
CeilingCat::Plugin::Notifo.set_credentials("username","api_secret")
CeilingCat::Plugin::Notifo.deliver("cdw","This is a test")
end
Expand Down Expand Up @@ -150,10 +150,48 @@

describe "calling the 'notifo' command" do
it "should send a message via notifo" do
message = "you should get in here"
message = "you should get in here."
event = CeilingCat::Event.new(@room,"!notifo #{message}", @registered_user)
@room.should_not_receive(:say)
CeilingCat::Plugin::Notifo.any_instance.should_receive(:deliver)
CeilingCat::Plugin::Notifo.should_receive(:deliver).with("ceiling_cat","you should get in here.")
HTTParty.stub(:post)
CeilingCat::Plugin::Notifo.new(event).handle
end
end

describe "calling the 'notifo' command with multiple users" do
before(:each) do
CeilingCat::Plugin::Notifo.add_users("zencoder")
end

it "should send a message to everyone via notifo" do
message = "you should get in here."
event = CeilingCat::Event.new(@room,"!notifo #{message}", @registered_user)

@room.should_not_receive(:say)
CeilingCat::Plugin::Notifo.should_receive(:deliver).with("ceiling_cat","you should get in here.")
CeilingCat::Plugin::Notifo.should_receive(:deliver).with("zencoder","you should get in here.")
HTTParty.stub(:post)
CeilingCat::Plugin::Notifo.new(event).handle
end

it "should send a message to a single user via notifo" do
message = "ceiling_cat: you should get in here."
event = CeilingCat::Event.new(@room,"!notifo #{message}", @registered_user)

@room.should_not_receive(:say)
CeilingCat::Plugin::Notifo.should_receive(:deliver).with("ceiling_cat","you should get in here.")
CeilingCat::Plugin::Notifo.should_not_receive(:deliver).with("zencoder","you should get in here.")
HTTParty.stub(:post)
CeilingCat::Plugin::Notifo.new(event).handle
end

it "should send a message containing a url to a single user via notifo" do
message = "ceiling_cat: you should check out http://example.com."
event = CeilingCat::Event.new(@room,"!notifo #{message}", @registered_user)

@room.should_not_receive(:say)
CeilingCat::Plugin::Notifo.should_receive(:deliver).with("ceiling_cat","you should check out http://example.com.")
HTTParty.stub(:post)
CeilingCat::Plugin::Notifo.new(event).handle
end
Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -10,3 +10,8 @@
def fixture(name)
File.read(File.dirname(__FILE__) + "/fixtures/#{name}")
end

RSpec.configure do |c|
c.filter_run :focus => true
c.run_all_when_everything_filtered = true
end

0 comments on commit 12b7a0a

Please sign in to comment.