Permalink
Browse files

updating examples

  • Loading branch information...
1 parent 5bddeba commit 0b656d2948318dc2541f9aeada4c5d7d94d59e68 Emmanuel Oga committed Aug 16, 2010
Showing with 66 additions and 42 deletions.
  1. +2 −0 examples/authenticate.rb
  2. +37 −25 examples/recent_messages.rb
  3. +13 −6 examples/rooms.rb
  4. +14 −11 examples/update_room.rb
View
2 examples/authenticate.rb
@@ -15,6 +15,8 @@
conn.authenticate do |user|
puts "Token for user #{user.name} is #{user.token}"
+ puts "You can set an environment variable for using it on scripts:"
+ puts "export CAMPFIRE_TOKEN=#{user.token}"
EM.stop
View
62 examples/recent_messages.rb
@@ -1,41 +1,53 @@
require 'firering'
-Firering.subdomain = ENV["CAMPFIRE_SUBDOMAIN"]
-Firering.token = ENV["CAMPFIRE_TOKEN"]
+print "Enter subdomain: "; subdomain = gets.chomp
+print "Enter user: " ; login = gets.chomp
+print "Enter password: " ; password = gets.chomp
-EM.run do
- Firering.rooms do |rooms|
-
- rooms.each do |room|
- puts "Users in room #{room.name} (#{room.topic})"
+conn = Firering::Connection.new("http://#{subdomain}.campfirenow.com") do |c|
+ c.login = login
+ c.password = password
+end
- if room.users.empty?
- puts " empty (locked: #{room.locked?})"
- else
- room.users.each do |u|
- puts " #{ u.name }. Admin: #{ u.admin? }"
+EM.run do
+ conn.authenticate do
+ conn.rooms do |rooms|
+
+ rooms.each do |room|
+ puts "Users in room #{room.name} (#{room.topic})"
+
+ room.users do |users|
+ if users.empty?
+ puts " empty (locked: #{room.locked?})"
+ else
+ users.each do |u|
+ puts " #{ u.name }. Admin: #{ u.admin? }"
+ end
+ end
end
- end
- if room.locked?
- puts " can't get recent messages in a locked room'"
- else
- Firering.room_recent_messages(room.id) do |messages|
+ if room.locked?
+ puts " can't get recent messages in a locked room'"
+ else
+ room.recent_messages do |messages|
- puts "-" * 80
- puts "recent message on #{room.name}"
- puts "-" * 80
+ puts "-" * 80
+ puts "recent message on #{room.name}"
+ puts "-" * 80
- messages.slice(0, 4).each do |m|
- puts "\n (#{m.user_id})"
+ messages.slice(0, 4).each do |m|
+ m.user do |u|
+ puts "\n (#{u})"
- m.body.to_s.split("\n").each do |chunk|
- puts " > #{chunk}"
+ m.body.to_s.split("\n").each do |chunk|
+ puts " > #{chunk}"
+ end
+ end
end
end
end
- end
+ end
end
end
View
19 examples/rooms.rb
@@ -7,14 +7,21 @@
EM.run do
conn.rooms do |rooms|
rooms.each do |room|
- puts "Users in room #{room.name}"
- if room.users.empty?
- puts " empty (locked: #{room.locked?})"
- else
- room.users.each do |u|
- puts " #{ u.name }"
+
+ room.users do |users|
+ puts "Users in room #{room.name}"
+
+ if users.empty?
+ puts " empty (locked: #{room.locked?})"
+ else
+ users.each do |u|
+ puts " #{ u.name }"
+ end
end
+
+ puts
end
+
end
end
View
25 examples/update_room.rb
@@ -1,31 +1,34 @@
require 'firering'
-Firering.subdomain = ENV["CAMPFIRE_SUBDOMAIN"]
-Firering.token = ENV["CAMPFIRE_TOKEN"]
+conn = Firering::Connection.new("http://#{ENV["CAMPFIRE_SUBDOMAIN"]}.campfirenow.com") do |c|
+ c.token = ENV["CAMPFIRE_TOKEN"]
+end
ROOM = "test2"
EM.run do
- Firering.rooms do |rooms|
+ conn.rooms do |rooms|
rooms.each do |room|
+
if room.name == ROOM
- Firering.room_join(room.id) do
+ room.join do
- Firering.update_room(room.id, "topic" => "test test test") do |response|
- puts " * Updating topic: "
- puts response.response_header.status
+ room.update("topic" => "test test test") do |data, http|
+ print " * Updating topic. HTTP Status returned: "
+ puts http.response_header.status
end
- Firering.text(room.id, "hola") do
- puts "texted"
+ room.text("this is a test from the refactored gem") do
+ puts "sent text"
end
- Firering.paste(room.id, "hola\nmundo") do
- puts "pasted"
+ room.paste("this is a\npaste\nfrom the refactored gem") do
+ puts "sent paste"
end
end
end
+
end
end

0 comments on commit 0b656d2

Please sign in to comment.