Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsharp committed Dec 18, 2009
0 parents commit 087cc55
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gemspec
@@ -0,0 +1,7 @@
Gem::Specification.new do |s|
s.name = 'campfire-notifier'
s.version = '0.1.0'
s.summary = 'A simple gem to send a simple message to campfire.'
s.files = Dir['lib/**/*.rb']
end

Empty file added Gemfile
Empty file.
39 changes: 39 additions & 0 deletions README.rdoc
@@ -0,0 +1,39 @@
= Campfire Notifier

Most of the time when I want to use the Campfire API, I just want to send it
a simple message. So, I created a stupid simple way to send a message to
Campfire.

I've include a command line tool as well to make it really easy to use this
with low-ish level system tools (i.e. cron).

== Install

gem install campfire_notifier

== Settings

Put your campfire subdomain, the room id (not the name) to which you want to
send a message, and your API token, which you can find on your campfire user
edit page.

See here for more details: http://developer.37signals.com/campfire/index

== Requirements

Nothing! This baby uses gem bundler, so you shouldn't need to install
any other gems.

Still, just in case:
* HTTParty
* json_pure


== Potential Uses

* Deployment notifications
* CI Build notifications
* Git hooks
* Cron jobs
* Annoying your co-workers

6 changes: 6 additions & 0 deletions bin/campfire_notifier
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
require 'campfire_notifier'

CampfireNotifier.speak(ARGV[0]) unless ARGV[0].nil?
22 changes: 22 additions & 0 deletions lib/campfire_notifier.rb
@@ -0,0 +1,22 @@
require 'yaml'

require 'rubygems'
require 'httparty'
require 'json'

class CampfireNotifier
include HTTParty

def self.config
@config ||= YAML.load_file(File.expand_path(File.dirname(__FILE__)) + "/../settings.yml")
end

base_uri "http://#{config['subdomain']}.campfirenow.com"
headers 'Content-type' => 'application/json'
basic_auth config["token"], 'x'
format :json

def self.speak(message)
post "/room/#{config['room_id']}/speak.json", :body => { :message => { :body => message, :type => 'Textmessage' } }.to_json
end
end
3 changes: 3 additions & 0 deletions settings.yml
@@ -0,0 +1,3 @@
token: b916b9434bb4158b461b8a4f8f3342f7d2f2fd67
room_id: 244651
subdomain: optimis
33 changes: 33 additions & 0 deletions spec/campfire_notifier_spec.rb
@@ -0,0 +1,33 @@
require 'spec_helper'

describe CampfireNotifier, ".config" do
before :each do
@config = CampfireNotifier.config
end

it "should load some configuration settings" do
@config.should be_instance_of Hash
end

it "should set the subdomain option" do
@config['subdomain'].should_not be_blank
end

it "should set the room name" do
@config['room_id'].should_not be_blank
end

it "should set the token" do
@config['token'].should_not be_blank
end
end

describe CampfireNotifier, ".speak" do
before :each do
CampfireNotifier.stub(:speak).and_return("hello")
end

it "should submit a request to the campfire api" do
CampfireNotifier.should respond_to :speak
end
end
1 change: 1 addition & 0 deletions spec/fixtures/rooms.json
@@ -0,0 +1 @@
{"rooms":[{"name":"General","created_at":"2009/10/12 14:30:16 +0000","updated_at":"2009/10/17 08:49:16 +0000","topic":"","id":111111,"membership_limit":12}]}
4 changes: 4 additions & 0 deletions spec/spec.opts
@@ -0,0 +1,4 @@
--colour
--format
s
--diff
18 changes: 18 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,18 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')
$:.unshift(File.dirname(__FILE__))


require 'rubygems'
require 'spec'
require 'spec/autorun'

require 'fakeweb'

require 'campfire_notifier'


fixtures = File.dirname(File.expand_path(__FILE__)) + "/fixtures"

FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:get, "http://example.campfirenow.com/rooms.json", :body => File.read("#{fixtures}/rooms.json"))

0 comments on commit 087cc55

Please sign in to comment.