Skip to content
Browse files

added room_id to the room initializer so that both id and name could …

…be used to find a room
  • Loading branch information...
1 parent 683a91e commit 991280f40dcfec2b90ea160b86f9a891d42a6eec @mvandenbeuken mvandenbeuken committed Jul 9, 2012
Showing with 20 additions and 58 deletions.
  1. +1 −0 .gitignore
  2. +12 −57 bin/campy
  3. +1 −1 lib/campy/room.rb
  4. +6 −0 spec/campy/room_spec.rb
View
1 .gitignore
@@ -15,5 +15,6 @@ spec/reports
test/tmp
test/version_tmp
tmp
+.rbenv-version
.rvmrc
.rbx/
View
69 bin/campy
@@ -1,61 +1,16 @@
#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'campy' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
-$:.unshift File.join(File.dirname(__FILE__), %w{.. lib})
-require 'campy'
-require 'yaml'
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+ Pathname.new(__FILE__).realpath)
-def usage
- <<-USAGE.gsub(/^ {4}/, '')
+require 'rubygems'
+require 'bundler/setup'
- Usage
-
- campy <action> <message>
-
- Actions
-
- help - Display CLI help (this output)
- speak - Speak a message into the campfire room
- paste - Paste a message into the campfire room
- play - Play a sound into the campfire room
-
- USAGE
-end
-
-def options
- yaml_file = File.expand_path(ENV['CAMPFIRE_YAML_FILE'] || '~/.campfire.yml')
- if !File.exists?(yaml_file)
- abort "File '#{yaml_file}' does not exist with campfire configuration."
- end
- YAML.load_file(yaml_file)
-end
-
-def actions
- %w{speak paste play}
-end
-
-def action
- @action ||= begin
- abort usage if ARGV.empty?
- ARGV.shift
- end
-end
-
-def message
- @message ||= begin
- if ARGV.empty?
- ARGF.read.chomp
- else
- ARGV.shift
- end
- end
-end
-
-case action
-when *actions
- Campy::Room.new(options).send(action, message)
-when "help"
- puts usage
- exit
-else
- abort usage
-end
+load Gem.bin_path('campy', 'campy')
View
2 lib/campy/room.rb
@@ -31,7 +31,7 @@ class ConnectionError < RuntimeError ; end
def initialize(options = {})
options = { :ssl => true }.merge(options)
- [:account, :room, :token, :ssl].each do |option|
+ [:account, :room_id, :room, :token, :ssl].each do |option|
instance_variable_set "@#{option}", options[option]
end
end
View
6 spec/campy/room_spec.rb
@@ -98,6 +98,12 @@ def fixture(name)
describe "#room_id" do
let(:subject) { Campy::Room.new(opts) }
+ it "returns the room_id set in the initializer if it is provided" do
+ room_with_id = Campy::Room.new(opts.merge(:room_id => 654321))
+
+ room_with_id.room_id.must_equal 654321
+ end
+
it "fetches the room id from the API" do
stub_rooms!

0 comments on commit 991280f

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