flamethrower 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -1
- data/Gemfile.lock +10 -2
- data/README.rdoc +0 -2
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/flamethrower +12 -7
- data/flamethrower.gemspec +78 -65
- data/lib/flamethrower.rb +2 -1
- data/lib/flamethrower/campfire/connection.rb +30 -16
- data/lib/flamethrower/campfire/message.rb +11 -1
- data/lib/flamethrower/campfire/rest_api.rb +19 -15
- data/lib/flamethrower/campfire/room.rb +85 -50
- data/lib/flamethrower/dispatcher.rb +11 -7
- data/lib/flamethrower/irc/codes.rb +2 -0
- data/lib/flamethrower/irc/commands.rb +17 -0
- data/lib/flamethrower/server.rb +6 -2
- data/lib/flamethrower/server/event_server.rb +23 -12
- data/spec/fixtures/paste_message.json +1 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/unit/campfire/connection_spec.rb +35 -9
- data/spec/unit/campfire/message_spec.rb +5 -1
- data/spec/unit/campfire/room_spec.rb +69 -46
- data/spec/unit/dispatcher_spec.rb +32 -18
- data/spec/unit/irc/channel_spec.rb +7 -4
- data/spec/unit/server_spec.rb +30 -14
- metadata +81 -12
- data/.gitignore +0 -4
@@ -68,15 +68,25 @@ describe Flamethrower::Dispatcher do
|
|
68
68
|
|
69
69
|
context "setting the channel topic" do
|
70
70
|
it "sets the channel topic to the specified topic" do
|
71
|
-
|
71
|
+
stub_request(:put, "https://mydomain.campfirenow.com/room/347348.json").
|
72
|
+
with(:headers => {'Authorization'=>['mytoken', 'x'], 'Content-Type'=>'application/json'}).
|
73
|
+
to_return(:status => 200, :body => json_fixture("room_update"))
|
72
74
|
message = Flamethrower::Irc::Message.new("TOPIC #flamethrower :some awesome topic")
|
73
75
|
@dispatcher.server.should_receive(:send_topic).with(@channel)
|
74
|
-
@dispatcher.handle_message(message)
|
76
|
+
EM.run_block { @dispatcher.handle_message(message) }
|
75
77
|
@channel.topic.should == "some awesome topic"
|
76
78
|
end
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
82
|
+
describe "#who" do
|
83
|
+
it "responds with a who list" do
|
84
|
+
message = Flamethrower::Irc::Message.new("WHO #flamethrower\r\n")
|
85
|
+
@dispatcher.server.should_receive(:send_who).with(@channel)
|
86
|
+
@dispatcher.handle_message(message)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
80
90
|
describe "#mode" do
|
81
91
|
before do
|
82
92
|
@user = Flamethrower::Irc::User.new :username => "user", :nickname => "nick", :hostname => "host", :realname => "realname", :servername => "servername"
|
@@ -147,13 +157,23 @@ describe Flamethrower::Dispatcher do
|
|
147
157
|
|
148
158
|
describe "#part" do
|
149
159
|
it "stops the thread of the room being parted from" do
|
150
|
-
|
160
|
+
EventMachine.stub(:cancel_timer)
|
161
|
+
@room.instance_variable_set("@room_alive", true)
|
151
162
|
@room.should be_alive
|
152
163
|
message = Flamethrower::Irc::Message.new("PART #flamethrower")
|
153
164
|
@dispatcher.handle_message(message)
|
154
165
|
@room.should_not be_alive
|
155
166
|
end
|
156
167
|
|
168
|
+
it "sends a part message with your current user's name" do
|
169
|
+
EventMachine.stub(:cancel_timer)
|
170
|
+
user = Flamethrower::Irc::User.new :username => "user", :nickname => "nick", :hostname => "host", :realname => "realname", :servername => "servername"
|
171
|
+
@server.current_user = user
|
172
|
+
message = Flamethrower::Irc::Message.new("PART #flamethrower")
|
173
|
+
@server.should_receive(:send_message).with(":#{user.to_s} PART #flamethrower")
|
174
|
+
@dispatcher.handle_message(message)
|
175
|
+
end
|
176
|
+
|
157
177
|
it "responds with ERR_BADCHANNELKEY a channel that doesn't exist" do
|
158
178
|
user = Flamethrower::Irc::User.new :username => "user", :nickname => "nick", :hostname => "host", :realname => "realname", :servername => "servername"
|
159
179
|
@server.current_user = user
|
@@ -164,8 +184,14 @@ describe Flamethrower::Dispatcher do
|
|
164
184
|
end
|
165
185
|
|
166
186
|
describe "#quit" do
|
167
|
-
it "kills all the
|
168
|
-
|
187
|
+
it "kills all the eventmachine timers on quit" do
|
188
|
+
polling_timer = mock(:polling_timer)
|
189
|
+
periodic_timer = mock(:periodic_timer)
|
190
|
+
EventMachine.should_receive(:cancel_timer).with(polling_timer)
|
191
|
+
EventMachine.should_receive(:cancel_timer).with(periodic_timer)
|
192
|
+
@room.instance_variable_set("@room_alive", true)
|
193
|
+
@room.instance_variable_set("@polling_timer", polling_timer)
|
194
|
+
@room.instance_variable_set("@periodic_timer", periodic_timer)
|
169
195
|
@room.should be_alive
|
170
196
|
message = Flamethrower::Irc::Message.new("QUIT :leaving")
|
171
197
|
@dispatcher.handle_message(message)
|
@@ -175,17 +201,11 @@ describe Flamethrower::Dispatcher do
|
|
175
201
|
|
176
202
|
describe "#join" do
|
177
203
|
before do
|
204
|
+
@room.stub(:start)
|
178
205
|
@room.stub(:fetch_room_info)
|
179
206
|
@room.stub(:join)
|
180
207
|
end
|
181
208
|
|
182
|
-
it "responds with a topic and userlist if sent a join" do
|
183
|
-
message = Flamethrower::Irc::Message.new("JOIN #flamethrower\r\n")
|
184
|
-
@server.should_receive(:send_topic).with(@channel)
|
185
|
-
@server.should_receive(:send_userlist)
|
186
|
-
@dispatcher.handle_message(message)
|
187
|
-
end
|
188
|
-
|
189
209
|
it "adds the current user to the channel" do
|
190
210
|
user = Flamethrower::Irc::User.new :username => "user", :nickname => "nick", :hostname => "host", :realname => "realname", :servername => "servername"
|
191
211
|
@server.current_user = user
|
@@ -194,12 +214,6 @@ describe Flamethrower::Dispatcher do
|
|
194
214
|
@channel.users.should include(user)
|
195
215
|
end
|
196
216
|
|
197
|
-
it "fetches the room information on join" do
|
198
|
-
message = Flamethrower::Irc::Message.new("JOIN #flamethrower\r\n")
|
199
|
-
@room.should_receive(:fetch_room_info)
|
200
|
-
@dispatcher.handle_message(message)
|
201
|
-
end
|
202
|
-
|
203
217
|
it "responds with ERR_BADCHANNELKEY a channel that doesn't exist" do
|
204
218
|
user = Flamethrower::Irc::User.new :username => "user", :nickname => "nick", :hostname => "host", :realname => "realname", :servername => "servername"
|
205
219
|
@server.current_user = user
|
@@ -2,7 +2,9 @@ require File.join(File.dirname(__FILE__), "../../spec_helper")
|
|
2
2
|
|
3
3
|
describe Flamethrower::Irc::Channel do
|
4
4
|
before do
|
5
|
+
@server = Flamethrower::MockServer.new
|
5
6
|
@room = Flamethrower::Campfire::Room.new("mydomain", "mytoken", {'name' => "flamethrower"})
|
7
|
+
@room.server = @server
|
6
8
|
@channel = Flamethrower::Irc::Channel.new("#flamethrower", @room)
|
7
9
|
@campfire_user = Flamethrower::Campfire::User.new('name' => "bob", 'id' => 734581)
|
8
10
|
@irc_user = @campfire_user.to_irc
|
@@ -35,9 +37,10 @@ describe Flamethrower::Irc::Channel do
|
|
35
37
|
|
36
38
|
describe "#irc_messages" do
|
37
39
|
it "returns the irc messages to be sent to the client" do
|
38
|
-
|
40
|
+
@other_user = Flamethrower::Campfire::User.new('name' => "tom", 'id' => 7123)
|
41
|
+
message = Flamethrower::Campfire::Message.new('body' => 'Hello there', 'user' => @other_user, 'room' => @room, 'type' => 'TextMessage')
|
39
42
|
@room.inbound_messages << message
|
40
|
-
@channel.retrieve_irc_messages.map(&:to_s).should == [":#{@
|
43
|
+
@channel.retrieve_irc_messages.map(&:to_s).should == [":#{@other_user.to_irc.to_s} PRIVMSG #{@channel.name} :Hello there"]
|
41
44
|
end
|
42
45
|
|
43
46
|
it "doesn't send TimeStamp messages" do
|
@@ -51,10 +54,10 @@ describe Flamethrower::Irc::Channel do
|
|
51
54
|
@channel.retrieve_irc_messages.should be_empty
|
52
55
|
end
|
53
56
|
|
54
|
-
|
57
|
+
it "doesn't send the message if the source is the current user" do
|
55
58
|
message = Flamethrower::Campfire::Message.new('body' => 'Hello there', 'user' => @campfire_user, 'room' => @room, 'type' => 'TextMessage')
|
56
59
|
@room.inbound_messages << message
|
57
|
-
@
|
60
|
+
@server.current_user = @campfire_user.to_irc
|
58
61
|
@channel.retrieve_irc_messages.map(&:to_s).should be_empty
|
59
62
|
end
|
60
63
|
end
|
data/spec/unit/server_spec.rb
CHANGED
@@ -47,18 +47,28 @@ describe Flamethrower::Server do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
context "#after_connect" do
|
50
|
+
before do
|
51
|
+
stub_request(:get, "https://mydomain.campfirenow.com/rooms.json").
|
52
|
+
with(:headers => {'Authorization'=>['mytoken', 'x']}).
|
53
|
+
to_return(:status => 200, :body => json_fixture("rooms"))
|
54
|
+
end
|
55
|
+
|
50
56
|
it "sends motd" do
|
57
|
+
@server.stub(:populate_irc_channels)
|
58
|
+
@server.stub(:populate_my_user)
|
51
59
|
@server.should_receive(:send_motd)
|
52
60
|
@server.after_connect
|
53
61
|
end
|
54
62
|
|
55
63
|
it "populates the channel list" do
|
64
|
+
@server.stub(:populate_my_user)
|
56
65
|
@server.should_receive(:populate_irc_channels)
|
57
66
|
@server.after_connect
|
58
67
|
end
|
59
68
|
|
60
|
-
it "
|
61
|
-
@server.
|
69
|
+
it "populates the currently logged in user" do
|
70
|
+
@server.stub(:populate_irc_channels)
|
71
|
+
@server.should_receive(:populate_my_user)
|
62
72
|
@server.after_connect
|
63
73
|
end
|
64
74
|
end
|
@@ -106,16 +116,19 @@ describe Flamethrower::Server do
|
|
106
116
|
]
|
107
117
|
end
|
108
118
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
+
describe "#send_who" do
|
120
|
+
it "sends the campfire users in the userlist" do
|
121
|
+
room = Flamethrower::Campfire::Room.new('mydomain', 'mytoken')
|
122
|
+
channel = Flamethrower::Irc::Channel.new("#flamethrower", room)
|
123
|
+
user1 = Flamethrower::Campfire::User.new('id' => 1234, 'name' => 'Bob Jones')
|
124
|
+
user2 = Flamethrower::Campfire::User.new('id' => 4321, 'name' => 'Bill Myer')
|
125
|
+
room.users = [user1, user2]
|
126
|
+
@server.send_who(channel).should == [
|
127
|
+
":host 352 nick #flamethrower Bob_Jones campfirenow.com localhost Bob_Jones H :0 Bob_Jones",
|
128
|
+
":host 352 nick #flamethrower Bill_Myer campfirenow.com localhost Bill_Myer H :0 Bill_Myer",
|
129
|
+
":host 315 nick #flamethrower :/End of /WHO list"
|
130
|
+
]
|
131
|
+
end
|
119
132
|
end
|
120
133
|
|
121
134
|
describe "#send_channel_list" do
|
@@ -153,8 +166,11 @@ describe Flamethrower::Server do
|
|
153
166
|
|
154
167
|
describe "#populate_irc_channels" do
|
155
168
|
it "populates the server irc_channels from the associated campfire channels" do
|
156
|
-
|
157
|
-
|
169
|
+
stub_request(:get, "https://mydomain.campfirenow.com/rooms.json").
|
170
|
+
with(:headers => {'Authorization'=>['mytoken', 'x']}).
|
171
|
+
to_return(:status => 200, :body => json_fixture("rooms"))
|
172
|
+
|
173
|
+
EM.run_block { @server.populate_irc_channels }
|
158
174
|
@server.irc_channels.count.should == 1
|
159
175
|
@server.irc_channels.first.name.should == "#room_1"
|
160
176
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flamethrower
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Blake Smith
|
@@ -15,13 +15,69 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-17 00:00:00 -06:00
|
19
19
|
default_executable: flamethrower
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: eventmachine
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: twitter-stream
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: json
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: em-http-request
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: eventmachine
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
25
81
|
none: false
|
26
82
|
requirements:
|
27
83
|
- - ">="
|
@@ -33,11 +89,11 @@ dependencies:
|
|
33
89
|
- 10
|
34
90
|
version: 0.12.10
|
35
91
|
type: :runtime
|
36
|
-
version_requirements: *
|
92
|
+
version_requirements: *id005
|
37
93
|
- !ruby/object:Gem::Dependency
|
38
94
|
name: json
|
39
95
|
prerelease: false
|
40
|
-
requirement: &
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
41
97
|
none: false
|
42
98
|
requirements:
|
43
99
|
- - ">="
|
@@ -47,11 +103,25 @@ dependencies:
|
|
47
103
|
- 0
|
48
104
|
version: "0"
|
49
105
|
type: :runtime
|
50
|
-
version_requirements: *
|
106
|
+
version_requirements: *id006
|
107
|
+
- !ruby/object:Gem::Dependency
|
108
|
+
name: em-http-request
|
109
|
+
prerelease: false
|
110
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
type: :runtime
|
120
|
+
version_requirements: *id007
|
51
121
|
- !ruby/object:Gem::Dependency
|
52
122
|
name: twitter-stream
|
53
123
|
prerelease: false
|
54
|
-
requirement: &
|
124
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
55
125
|
none: false
|
56
126
|
requirements:
|
57
127
|
- - ">="
|
@@ -61,7 +131,7 @@ dependencies:
|
|
61
131
|
- 0
|
62
132
|
version: "0"
|
63
133
|
type: :runtime
|
64
|
-
version_requirements: *
|
134
|
+
version_requirements: *id008
|
65
135
|
description: Flamethrower gives you the power to use your awesome irc client to talk in your campfire rooms.
|
66
136
|
email: blakesmith0@gmail.com
|
67
137
|
executables:
|
@@ -71,7 +141,6 @@ extensions: []
|
|
71
141
|
extra_rdoc_files:
|
72
142
|
- README.rdoc
|
73
143
|
files:
|
74
|
-
- .gitignore
|
75
144
|
- .rspec
|
76
145
|
- Gemfile
|
77
146
|
- Gemfile.lock
|
@@ -127,8 +196,8 @@ homepage: http://github.com/blakesmith/flamethrower
|
|
127
196
|
licenses: []
|
128
197
|
|
129
198
|
post_install_message:
|
130
|
-
rdoc_options:
|
131
|
-
|
199
|
+
rdoc_options: []
|
200
|
+
|
132
201
|
require_paths:
|
133
202
|
- lib
|
134
203
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/.gitignore
DELETED