flamethrower 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +3 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +10 -0
  4. data/Gemfile.lock +29 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +36 -0
  7. data/Rakefile +28 -0
  8. data/VERSION +1 -0
  9. data/bin/flamethrower +59 -0
  10. data/flamethrower.gemspec +106 -0
  11. data/lib/flamethrower.rb +25 -0
  12. data/lib/flamethrower/campfire/connection.rb +38 -0
  13. data/lib/flamethrower/campfire/message.rb +42 -0
  14. data/lib/flamethrower/campfire/rest_api.rb +40 -0
  15. data/lib/flamethrower/campfire/room.rb +142 -0
  16. data/lib/flamethrower/campfire/user.rb +17 -0
  17. data/lib/flamethrower/dispatcher.rb +102 -0
  18. data/lib/flamethrower/irc/channel.rb +55 -0
  19. data/lib/flamethrower/irc/codes.rb +17 -0
  20. data/lib/flamethrower/irc/commands.rb +57 -0
  21. data/lib/flamethrower/irc/message.rb +41 -0
  22. data/lib/flamethrower/irc/user.rb +33 -0
  23. data/lib/flamethrower/server.rb +43 -0
  24. data/lib/flamethrower/server/event_server.rb +28 -0
  25. data/lib/flamethrower/server/mock_server.rb +13 -0
  26. data/spec/fixtures/enter_message.json +1 -0
  27. data/spec/fixtures/kick_message.json +1 -0
  28. data/spec/fixtures/leave_message.json +1 -0
  29. data/spec/fixtures/message.json +1 -0
  30. data/spec/fixtures/paste_message.json +1 -0
  31. data/spec/fixtures/room.json +1 -0
  32. data/spec/fixtures/room_update.json +1 -0
  33. data/spec/fixtures/rooms.json +1 -0
  34. data/spec/fixtures/speak_message.json +1 -0
  35. data/spec/fixtures/streaming_message.json +1 -0
  36. data/spec/spec_helper.rb +13 -0
  37. data/spec/unit/campfire/connection_spec.rb +37 -0
  38. data/spec/unit/campfire/message_spec.rb +85 -0
  39. data/spec/unit/campfire/room_spec.rb +296 -0
  40. data/spec/unit/campfire/user_spec.rb +32 -0
  41. data/spec/unit/dispatcher_spec.rb +255 -0
  42. data/spec/unit/irc/channel_spec.rb +56 -0
  43. data/spec/unit/irc/message_spec.rb +32 -0
  44. data/spec/unit/irc/user_spec.rb +63 -0
  45. data/spec/unit/server/event_server_spec.rb +16 -0
  46. data/spec/unit/server_spec.rb +164 -0
  47. metadata +165 -0
@@ -0,0 +1,164 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper")
2
+
3
+ describe Flamethrower::Server do
4
+ before do
5
+ @server = Flamethrower::MockServer.new
6
+ @server.stub!(:send_data)
7
+ @user = Flamethrower::Irc::User.new :username => 'user', :nickname => 'nick', :hostname => 'host', :realname => 'realname'
8
+ @server.current_user = @user
9
+ end
10
+
11
+ describe "#send_message" do
12
+ it "sends the message to the client" do
13
+ message = "message"
14
+ @server.should_receive(:send_message).with("message")
15
+ @server.send_message(message)
16
+ end
17
+
18
+ it "should send the data across the wire" do
19
+ message = "message"
20
+ @server.should_receive(:send_data).with("message\r\n")
21
+ @server.send_message(message)
22
+ end
23
+ end
24
+
25
+ describe "#send_messages" do
26
+ it "sends a list of messages to the client" do
27
+ @server.should_receive(:send_message).exactly(2).times
28
+ @server.send_messages("one", "two")
29
+ end
30
+
31
+ it "yields to the block to allow more messages" do
32
+ @server.should_receive(:send_message).exactly(3).times
33
+ @server.send_messages("one", "two") do |messages|
34
+ messages << "three"
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "#receive_data" do
40
+ it "calls the dispatcher with a new Message" do
41
+ incoming = "COMMAND params"
42
+ msg = Flamethrower::Irc::Message.new(incoming)
43
+ Flamethrower::Irc::Message.should_receive(:new).with(incoming).and_return(msg)
44
+ @server.dispatcher.should_receive(:handle_message).with(msg)
45
+ @server.receive_data(incoming)
46
+ end
47
+ end
48
+
49
+ context "#after_connect" do
50
+ it "sends motd" do
51
+ @server.should_receive(:send_motd)
52
+ @server.after_connect
53
+ end
54
+
55
+ it "populates the channel list" do
56
+ @server.should_receive(:populate_irc_channels)
57
+ @server.after_connect
58
+ end
59
+
60
+ it "sends the channel list" do
61
+ @server.should_receive(:send_channel_list)
62
+ @server.after_connect
63
+ end
64
+ end
65
+
66
+ describe "irc_channels" do
67
+ it "stores the list of irc_channels on the server" do
68
+ channel = Flamethrower::Irc::Channel.new("#flamethrower")
69
+ @server.irc_channels << channel
70
+ @server.irc_channels.should include(channel)
71
+ end
72
+ end
73
+
74
+ describe "IRCcommands" do
75
+ it "should have the correct MOTD format" do
76
+ @server.send_motd.should == [
77
+ ":host 375 nick :MOTD",
78
+ ":host 372 nick :Welcome to Flamethrower",
79
+ ":host 372 nick :Fetching channel list from campfire..."
80
+ ]
81
+ end
82
+
83
+ it "should send the channel mode" do
84
+ channel = Flamethrower::Irc::Channel.new("#flamethrower")
85
+ @server.send_channel_mode(channel).should == ":host 324 nick #flamethrower +t"
86
+ end
87
+
88
+ it "should send the current user mode" do
89
+ @server.send_user_mode.should == ":host 221 nick +i"
90
+ end
91
+
92
+ it "should have the correct TOPIC format" do
93
+ room = Flamethrower::Campfire::Room.new("mydomain", "mytoken", "id" => 347348, "name" => "room 1")
94
+ channel = Flamethrower::Irc::Channel.new("#flamethrower", room)
95
+ channel.topic = "A topic"
96
+ @server.send_topic(channel).should == ":host 332 nick #flamethrower :A topic"
97
+ end
98
+
99
+ it "should have the correct USERLIST format" do
100
+ room = Flamethrower::Campfire::Room.new('mydomain', 'mytoken')
101
+ channel = Flamethrower::Irc::Channel.new("#flamethrower", room)
102
+ channel.users << Flamethrower::Irc::User.new(:nickname => 'bob', :username => 'bob')
103
+ @server.send_userlist(channel).should == [
104
+ ":host 353 nick = #flamethrower :@nick bob",
105
+ ":host 366 nick #flamethrower :/End of /NAMES list"
106
+ ]
107
+ end
108
+
109
+ it "sends the campfire users in the userlist" do
110
+ room = Flamethrower::Campfire::Room.new('mydomain', 'mytoken')
111
+ channel = Flamethrower::Irc::Channel.new("#flamethrower", room)
112
+ user1 = Flamethrower::Campfire::User.new('id' => 1234, 'name' => 'Bob Jones')
113
+ user2 = Flamethrower::Campfire::User.new('id' => 4321, 'name' => 'Bill Myer')
114
+ room.users = [user1, user2]
115
+ @server.send_userlist(channel).should == [
116
+ ":host 353 nick = #flamethrower :@nick Bob_Jones Bill_Myer",
117
+ ":host 366 nick #flamethrower :/End of /NAMES list"
118
+ ]
119
+ end
120
+
121
+ describe "#send_channel_list" do
122
+ it "sends the right motd message with the channel list" do
123
+ room = Flamethrower::Campfire::Room.new("mydomain", "mytoken", "id" => 347348, "name" => "room 1")
124
+ room2 = Flamethrower::Campfire::Room.new("mydomain", "mytoken", "id" => 347349, "name" => "room 2")
125
+ channel = Flamethrower::Irc::Channel.new("#flamethrower", room)
126
+ channel.topic = "Flamethrower topic"
127
+ channel2 = Flamethrower::Irc::Channel.new("#room_1", room2)
128
+ channel2.topic = "Room 1 topic"
129
+ @server.irc_channels = [channel, channel2]
130
+ @server.send_channel_list.should == [
131
+ ":host 372 nick :Active channels:",
132
+ ":host 372 nick :#flamethrower - Flamethrower topic",
133
+ ":host 372 nick :#room_1 - Room 1 topic",
134
+ ":host 376 nick :End of channel list /MOTD"
135
+ ]
136
+ end
137
+
138
+ it "shows 'No topic' in the channel list if there's no room topic" do
139
+ room = Flamethrower::Campfire::Room.new("mydomain", "mytoken", "id" => 347348, "name" => "room 1")
140
+ room2 = Flamethrower::Campfire::Room.new("mydomain", "mytoken", "id" => 347349, "name" => "room 2")
141
+ channel = Flamethrower::Irc::Channel.new("#flamethrower", room)
142
+ channel2 = Flamethrower::Irc::Channel.new("#room_1", room2)
143
+ channel.topic = channel2.topic = ""
144
+ @server.irc_channels = [channel, channel2]
145
+ @server.send_channel_list.should == [
146
+ ":host 372 nick :Active channels:",
147
+ ":host 372 nick :#flamethrower - No topic",
148
+ ":host 372 nick :#room_1 - No topic",
149
+ ":host 376 nick :End of channel list /MOTD"
150
+ ]
151
+ end
152
+ end
153
+
154
+ describe "#populate_irc_channels" do
155
+ it "populates the server irc_channels from the associated campfire channels" do
156
+ FakeWeb.register_uri(:get, "https://mytoken:x@mydomain.campfirenow.com/rooms.json", :body => json_fixture("rooms"), :status => ["200", "OK"])
157
+ @server.populate_irc_channels
158
+ @server.irc_channels.count.should == 1
159
+ @server.irc_channels.first.name.should == "#room_1"
160
+ end
161
+ end
162
+ end
163
+
164
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flamethrower
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Blake Smith
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-22 00:00:00 -06:00
19
+ default_executable: flamethrower
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: eventmachine
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 59
30
+ segments:
31
+ - 0
32
+ - 12
33
+ - 10
34
+ version: 0.12.10
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: twitter-stream
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ description: Flamethrower gives you the power to use your awesome irc client to talk in your campfire rooms.
66
+ email: blakesmith0@gmail.com
67
+ executables:
68
+ - flamethrower
69
+ extensions: []
70
+
71
+ extra_rdoc_files:
72
+ - README.rdoc
73
+ files:
74
+ - .gitignore
75
+ - .rspec
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - MIT-LICENSE
79
+ - README.rdoc
80
+ - Rakefile
81
+ - VERSION
82
+ - bin/flamethrower
83
+ - flamethrower.gemspec
84
+ - lib/flamethrower.rb
85
+ - lib/flamethrower/campfire/connection.rb
86
+ - lib/flamethrower/campfire/message.rb
87
+ - lib/flamethrower/campfire/rest_api.rb
88
+ - lib/flamethrower/campfire/room.rb
89
+ - lib/flamethrower/campfire/user.rb
90
+ - lib/flamethrower/dispatcher.rb
91
+ - lib/flamethrower/irc/channel.rb
92
+ - lib/flamethrower/irc/codes.rb
93
+ - lib/flamethrower/irc/commands.rb
94
+ - lib/flamethrower/irc/message.rb
95
+ - lib/flamethrower/irc/user.rb
96
+ - lib/flamethrower/server.rb
97
+ - lib/flamethrower/server/event_server.rb
98
+ - lib/flamethrower/server/mock_server.rb
99
+ - spec/fixtures/enter_message.json
100
+ - spec/fixtures/kick_message.json
101
+ - spec/fixtures/leave_message.json
102
+ - spec/fixtures/message.json
103
+ - spec/fixtures/paste_message.json
104
+ - spec/fixtures/room.json
105
+ - spec/fixtures/room_update.json
106
+ - spec/fixtures/rooms.json
107
+ - spec/fixtures/speak_message.json
108
+ - spec/fixtures/streaming_message.json
109
+ - spec/spec_helper.rb
110
+ - spec/unit/campfire/connection_spec.rb
111
+ - spec/unit/campfire/message_spec.rb
112
+ - spec/unit/campfire/room_spec.rb
113
+ - spec/unit/campfire/user_spec.rb
114
+ - spec/unit/dispatcher_spec.rb
115
+ - spec/unit/irc/channel_spec.rb
116
+ - spec/unit/irc/message_spec.rb
117
+ - spec/unit/irc/user_spec.rb
118
+ - spec/unit/server/event_server_spec.rb
119
+ - spec/unit/server_spec.rb
120
+ has_rdoc: true
121
+ homepage: http://github.com/blakesmith/flamethrower
122
+ licenses: []
123
+
124
+ post_install_message:
125
+ rdoc_options:
126
+ - --charset=UTF-8
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.3.7
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Campfire IRC gateway
154
+ test_files:
155
+ - spec/spec_helper.rb
156
+ - spec/unit/campfire/connection_spec.rb
157
+ - spec/unit/campfire/message_spec.rb
158
+ - spec/unit/campfire/room_spec.rb
159
+ - spec/unit/campfire/user_spec.rb
160
+ - spec/unit/dispatcher_spec.rb
161
+ - spec/unit/irc/channel_spec.rb
162
+ - spec/unit/irc/message_spec.rb
163
+ - spec/unit/irc/user_spec.rb
164
+ - spec/unit/server/event_server_spec.rb
165
+ - spec/unit/server_spec.rb