diff --git a/.gemspec b/.gemspec new file mode 100644 index 0000000..00d57ba --- /dev/null +++ b/.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 + diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..e69de29 diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 0000000..8fefef2 --- /dev/null +++ b/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 + diff --git a/bin/campfire_notifier b/bin/campfire_notifier new file mode 100755 index 0000000..839abf7 --- /dev/null +++ b/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? diff --git a/lib/campfire_notifier.rb b/lib/campfire_notifier.rb new file mode 100644 index 0000000..a1ddc17 --- /dev/null +++ b/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 diff --git a/settings.yml b/settings.yml new file mode 100644 index 0000000..128731e --- /dev/null +++ b/settings.yml @@ -0,0 +1,3 @@ +token: b916b9434bb4158b461b8a4f8f3342f7d2f2fd67 +room_id: 244651 +subdomain: optimis diff --git a/spec/campfire_notifier_spec.rb b/spec/campfire_notifier_spec.rb new file mode 100644 index 0000000..0bc88c5 --- /dev/null +++ b/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 diff --git a/spec/fixtures/rooms.json b/spec/fixtures/rooms.json new file mode 100644 index 0000000..b0774fd --- /dev/null +++ b/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}]} diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..a023fa3 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,4 @@ +--colour +--format +s +--diff diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..9cef9b2 --- /dev/null +++ b/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")) +