-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcampfire.rb
More file actions
94 lines (73 loc) · 1.48 KB
/
campfire.rb
File metadata and controls
94 lines (73 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'rubygems'
require 'httparty'
require 'json'
class Campfire
include HTTParty
base_uri 'https://37s.campfirenow.com'
basic_auth 'find_your_auth_key_on_member_slash_edit', 'x'
headers 'Content-Type' => 'application/json'
def self.rooms
Campfire.get('/rooms.json')["rooms"]
end
def self.room(room_id)
Room.new(room_id)
end
def self.user(id)
Campfire.get("/users/#{id}.json")["user"]
end
end
class Room
attr_reader :room_id
def initialize(room_id)
@room_id = room_id
end
def join
post 'join'
end
def leave
post 'leave'
end
def lock
post 'lock'
end
def unlock
post 'unlock'
end
def message(message)
send_message message
end
def paste(paste)
send_message paste, 'PasteMessage'
end
def play_sound(sound)
send_message sound, 'SoundMessage'
end
def transcript
get('transcript')['messages']
end
private
def send_message(message, type = 'Textmessage')
post 'speak', :body => {:message => {:body => message, :type => type}}.to_json
end
def get(action, options = {})
Campfire.get room_url_for(action), options
end
def post(action, options = {})
Campfire.post room_url_for(action), options
end
def room_url_for(action)
"/room/#{room_id}/#{action}.json"
end
end
# Usage:
#
# room = Campfire.room(1)
# room.join
# room.lock
#
# room.message 'This is a top secret'
# room.paste "FROM THE\n\nAP-AYE"
# room.play_sound 'rimshot'
#
# room.unlock
# room.leave