flamethrower 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
addressable (2.2.2)
|
5
|
+
crack (0.1.8)
|
4
6
|
diff-lcs (1.1.2)
|
7
|
+
em-http-request (0.2.15)
|
8
|
+
addressable (>= 2.0.0)
|
9
|
+
eventmachine (>= 0.12.9)
|
5
10
|
eventmachine (0.12.10)
|
6
|
-
fakeweb (1.3.0)
|
7
11
|
json (1.4.6)
|
8
12
|
roauth (0.0.3)
|
9
13
|
rspec (2.1.0)
|
@@ -17,13 +21,17 @@ GEM
|
|
17
21
|
twitter-stream (0.1.10)
|
18
22
|
eventmachine (>= 0.12.8)
|
19
23
|
roauth (>= 0.0.2)
|
24
|
+
webmock (1.6.2)
|
25
|
+
addressable (>= 2.2.2)
|
26
|
+
crack (>= 0.1.7)
|
20
27
|
|
21
28
|
PLATFORMS
|
22
29
|
ruby
|
23
30
|
|
24
31
|
DEPENDENCIES
|
32
|
+
em-http-request
|
25
33
|
eventmachine
|
26
|
-
fakeweb
|
27
34
|
json
|
28
35
|
rspec
|
29
36
|
twitter-stream
|
37
|
+
webmock
|
data/README.rdoc
CHANGED
@@ -25,8 +25,6 @@ Then start flamethrower like so:
|
|
25
25
|
|
26
26
|
=== A work in progress
|
27
27
|
|
28
|
-
TODO: Switch Net::HTTP sync calls to async EM::HttpRequest calls.
|
29
|
-
|
30
28
|
Flamethrower is a work in progress. Right now basic messaging works, but
|
31
29
|
it still needs a lot of love. If you find it useful and would like to see
|
32
30
|
it do something, please submit a patch (with tests please)!. Bug reports are
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/flamethrower
CHANGED
@@ -14,6 +14,7 @@ HELP
|
|
14
14
|
require 'rubygems'
|
15
15
|
require 'flamethrower'
|
16
16
|
require 'optparse'
|
17
|
+
require 'yaml'
|
17
18
|
|
18
19
|
options = {}
|
19
20
|
opts = OptionParser.new do |opts|
|
@@ -42,17 +43,21 @@ end
|
|
42
43
|
|
43
44
|
opts.parse!
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
require 'yaml'
|
49
|
-
yaml = YAML.load_file(options['config'])
|
46
|
+
load_options_from_file = lambda do |filename, verbose|
|
47
|
+
if File.exists?(filename)
|
48
|
+
yaml = YAML.load_file(filename)
|
50
49
|
yaml.each {|k, v| options[k] = v}
|
51
|
-
|
52
|
-
puts "Unable to
|
50
|
+
else
|
51
|
+
puts "Unable to load config file!" if verbose
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
55
|
+
if options['config']
|
56
|
+
load_options_from_file.call(options['config'], true)
|
57
|
+
else
|
58
|
+
load_options_from_file.call(File.join(ENV["HOME"], '.flamethrower', 'config.yml'), false)
|
59
|
+
end
|
60
|
+
|
56
61
|
FLAMETHROWER_LOGGER = Logger.new(options['logger'] || STDOUT)
|
57
62
|
|
58
63
|
server = Flamethrower::EventServer.new(options['host'], options['port'], options['domain'], options['token'])
|
data/flamethrower.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{flamethrower}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Blake Smith"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-17}
|
13
13
|
s.default_executable = %q{flamethrower}
|
14
14
|
s.description = %q{Flamethrower gives you the power to use your awesome irc client to talk in your campfire rooms.}
|
15
15
|
s.email = %q{blakesmith0@gmail.com}
|
@@ -18,75 +18,73 @@ Gem::Specification.new do |s|
|
|
18
18
|
"README.rdoc"
|
19
19
|
]
|
20
20
|
s.files = [
|
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
|
-
"spec/unit/server_spec.rb"
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"MIT-LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/flamethrower",
|
29
|
+
"flamethrower.gemspec",
|
30
|
+
"lib/flamethrower.rb",
|
31
|
+
"lib/flamethrower/campfire/connection.rb",
|
32
|
+
"lib/flamethrower/campfire/message.rb",
|
33
|
+
"lib/flamethrower/campfire/rest_api.rb",
|
34
|
+
"lib/flamethrower/campfire/room.rb",
|
35
|
+
"lib/flamethrower/campfire/user.rb",
|
36
|
+
"lib/flamethrower/dispatcher.rb",
|
37
|
+
"lib/flamethrower/irc/channel.rb",
|
38
|
+
"lib/flamethrower/irc/codes.rb",
|
39
|
+
"lib/flamethrower/irc/commands.rb",
|
40
|
+
"lib/flamethrower/irc/message.rb",
|
41
|
+
"lib/flamethrower/irc/user.rb",
|
42
|
+
"lib/flamethrower/server.rb",
|
43
|
+
"lib/flamethrower/server/event_server.rb",
|
44
|
+
"lib/flamethrower/server/mock_server.rb",
|
45
|
+
"spec/fixtures/enter_message.json",
|
46
|
+
"spec/fixtures/kick_message.json",
|
47
|
+
"spec/fixtures/leave_message.json",
|
48
|
+
"spec/fixtures/message.json",
|
49
|
+
"spec/fixtures/paste_message.json",
|
50
|
+
"spec/fixtures/paste_message_with_pound.json",
|
51
|
+
"spec/fixtures/room.json",
|
52
|
+
"spec/fixtures/room_update.json",
|
53
|
+
"spec/fixtures/rooms.json",
|
54
|
+
"spec/fixtures/speak_message.json",
|
55
|
+
"spec/fixtures/streaming_message.json",
|
56
|
+
"spec/fixtures/timestamp_message.json",
|
57
|
+
"spec/fixtures/upload_message.json",
|
58
|
+
"spec/fixtures/upload_url_sample",
|
59
|
+
"spec/fixtures/user.json",
|
60
|
+
"spec/spec_helper.rb",
|
61
|
+
"spec/unit/campfire/connection_spec.rb",
|
62
|
+
"spec/unit/campfire/message_spec.rb",
|
63
|
+
"spec/unit/campfire/room_spec.rb",
|
64
|
+
"spec/unit/campfire/user_spec.rb",
|
65
|
+
"spec/unit/dispatcher_spec.rb",
|
66
|
+
"spec/unit/irc/channel_spec.rb",
|
67
|
+
"spec/unit/irc/message_spec.rb",
|
68
|
+
"spec/unit/irc/user_spec.rb",
|
69
|
+
"spec/unit/server/event_server_spec.rb",
|
70
|
+
"spec/unit/server_spec.rb"
|
72
71
|
]
|
73
72
|
s.homepage = %q{http://github.com/blakesmith/flamethrower}
|
74
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
75
73
|
s.require_paths = ["lib"]
|
76
74
|
s.rubygems_version = %q{1.3.7}
|
77
75
|
s.summary = %q{Campfire IRC gateway}
|
78
76
|
s.test_files = [
|
79
77
|
"spec/spec_helper.rb",
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
78
|
+
"spec/unit/campfire/connection_spec.rb",
|
79
|
+
"spec/unit/campfire/message_spec.rb",
|
80
|
+
"spec/unit/campfire/room_spec.rb",
|
81
|
+
"spec/unit/campfire/user_spec.rb",
|
82
|
+
"spec/unit/dispatcher_spec.rb",
|
83
|
+
"spec/unit/irc/channel_spec.rb",
|
84
|
+
"spec/unit/irc/message_spec.rb",
|
85
|
+
"spec/unit/irc/user_spec.rb",
|
86
|
+
"spec/unit/server/event_server_spec.rb",
|
87
|
+
"spec/unit/server_spec.rb"
|
90
88
|
]
|
91
89
|
|
92
90
|
if s.respond_to? :specification_version then
|
@@ -94,17 +92,32 @@ Gem::Specification.new do |s|
|
|
94
92
|
s.specification_version = 3
|
95
93
|
|
96
94
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
95
|
+
s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
|
96
|
+
s.add_runtime_dependency(%q<twitter-stream>, [">= 0"])
|
97
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
98
|
+
s.add_runtime_dependency(%q<em-http-request>, [">= 0"])
|
97
99
|
s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
|
98
100
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
101
|
+
s.add_runtime_dependency(%q<em-http-request>, [">= 0"])
|
99
102
|
s.add_runtime_dependency(%q<twitter-stream>, [">= 0"])
|
100
103
|
else
|
104
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
105
|
+
s.add_dependency(%q<twitter-stream>, [">= 0"])
|
106
|
+
s.add_dependency(%q<json>, [">= 0"])
|
107
|
+
s.add_dependency(%q<em-http-request>, [">= 0"])
|
101
108
|
s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
|
102
109
|
s.add_dependency(%q<json>, [">= 0"])
|
110
|
+
s.add_dependency(%q<em-http-request>, [">= 0"])
|
103
111
|
s.add_dependency(%q<twitter-stream>, [">= 0"])
|
104
112
|
end
|
105
113
|
else
|
114
|
+
s.add_dependency(%q<eventmachine>, [">= 0"])
|
115
|
+
s.add_dependency(%q<twitter-stream>, [">= 0"])
|
116
|
+
s.add_dependency(%q<json>, [">= 0"])
|
117
|
+
s.add_dependency(%q<em-http-request>, [">= 0"])
|
106
118
|
s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
|
107
119
|
s.add_dependency(%q<json>, [">= 0"])
|
120
|
+
s.add_dependency(%q<em-http-request>, [">= 0"])
|
108
121
|
s.add_dependency(%q<twitter-stream>, [">= 0"])
|
109
122
|
end
|
110
123
|
end
|
data/lib/flamethrower.rb
CHANGED
@@ -11,28 +11,42 @@ module Flamethrower
|
|
11
11
|
@server = server
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
def fetch_my_user
|
15
|
+
http = campfire_get("/users/me.json")
|
16
|
+
http.callback do
|
17
|
+
case http.response_header.status
|
18
|
+
when 200
|
19
|
+
json = JSON.parse(http.response)
|
20
|
+
old_user = @server.current_user.nickname
|
21
|
+
new_user = Flamethrower::Campfire::User.new(json['user']).to_irc
|
22
|
+
@server.current_user = new_user
|
23
|
+
@server.send_rename(old_user, new_user.nickname)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def fetch_rooms
|
29
|
+
http = campfire_get("/rooms.json")
|
30
|
+
http.callback do
|
31
|
+
case http.response_header.status
|
32
|
+
when 200
|
33
|
+
rooms = Array.new
|
34
|
+
json = JSON.parse(http.response)
|
35
|
+
json['rooms'].each do |room|
|
36
|
+
rooms << Room.new(@domain, @token, room).tap do |r|
|
37
|
+
r.server = @server
|
25
38
|
end
|
26
|
-
else
|
27
|
-
::FLAMETHROWER_LOGGER.debug response.body
|
28
39
|
end
|
40
|
+
@server.irc_channels = rooms.map(&:to_irc)
|
41
|
+
@server.send_channel_list
|
42
|
+
else
|
43
|
+
::FLAMETHROWER_LOGGER.debug http.response
|
29
44
|
end
|
30
|
-
|
45
|
+
end
|
46
|
+
http.errback do
|
31
47
|
@server.send_message @server.reply(Flamethrower::Irc::Codes::RPL_MOTD, ":ERROR: Unable to fetch room list! Check your connection?")
|
32
|
-
[]
|
33
48
|
end
|
34
49
|
end
|
35
|
-
|
36
50
|
end
|
37
51
|
end
|
38
52
|
end
|
@@ -34,12 +34,22 @@ module Flamethrower
|
|
34
34
|
when "LeaveMessage"
|
35
35
|
irc_string = ":#{@user.to_irc.to_s} PART #{@room.to_irc.name}"
|
36
36
|
when "PasteMessage"
|
37
|
-
irc_string =
|
37
|
+
irc_string = format_paste_message
|
38
38
|
else
|
39
39
|
return
|
40
40
|
end
|
41
41
|
Flamethrower::Irc::Message.new(irc_string)
|
42
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def format_paste_message
|
47
|
+
lines = @body.split("\n")
|
48
|
+
message = lines.inject(Array.new) do |array, line|
|
49
|
+
array << ":#{@user.to_irc.to_s} PRIVMSG #{@room.to_irc.name} :#{line}"
|
50
|
+
end
|
51
|
+
message.join("\r\n")
|
52
|
+
end
|
43
53
|
end
|
44
54
|
end
|
45
55
|
end
|
@@ -3,36 +3,40 @@ module Flamethrower
|
|
3
3
|
module RestApi
|
4
4
|
|
5
5
|
def host
|
6
|
-
"
|
6
|
+
"https://#{@domain}.campfirenow.com"
|
7
7
|
end
|
8
8
|
|
9
9
|
private
|
10
10
|
def http
|
11
|
-
|
12
|
-
connection.use_ssl = true
|
13
|
-
end
|
11
|
+
EventMachine::HttpRequest.new(host)
|
14
12
|
end
|
15
13
|
|
16
14
|
def campfire_get(path)
|
17
|
-
get
|
18
|
-
|
19
|
-
|
15
|
+
action_log("get", path, nil)
|
16
|
+
full_path = host << path
|
17
|
+
EventMachine::HttpRequest.new(full_path).get :head => {'authorization' => [@token, 'x']}
|
20
18
|
end
|
21
19
|
|
22
20
|
def campfire_post(path, json=nil)
|
23
|
-
|
21
|
+
action_log("post", path, json)
|
22
|
+
full_path = host << path
|
23
|
+
params = {:head => {'Content-Type' => 'application/json', 'authorization' => [@token, 'x']}}
|
24
|
+
params[:body] = json if json
|
25
|
+
http = EventMachine::HttpRequest.new(full_path).post params
|
24
26
|
end
|
25
27
|
|
26
28
|
def campfire_put(path, json=nil)
|
27
|
-
|
29
|
+
action_log("put", path, json)
|
30
|
+
full_path = host << path
|
31
|
+
params = {:head => {'Content-Type' => 'application/json', 'authorization' => [@token, 'x']}}
|
32
|
+
params[:body] = json if json
|
33
|
+
EventMachine::HttpRequest.new(full_path).put params
|
28
34
|
end
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
action.
|
34
|
-
action.add_field "Content-Type", "application/json"
|
35
|
-
http.request(action)
|
36
|
+
private
|
37
|
+
|
38
|
+
def action_log(action, path, json)
|
39
|
+
::FLAMETHROWER_LOGGER.debug "Sending #{action.upcase} #{path} with #{json || 'no'} JSON"
|
36
40
|
end
|
37
41
|
|
38
42
|
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
module Flamethrower
|
2
2
|
module Campfire
|
3
3
|
class Room
|
4
|
+
POLL_SECONDS = 0.5
|
5
|
+
PERIODIC_UPDATE_SECONDS = 60 * 10
|
6
|
+
|
4
7
|
include Flamethrower::Campfire::RestApi
|
5
8
|
|
6
9
|
attr_reader :stream, :token
|
7
10
|
attr_writer :topic
|
8
11
|
attr_accessor :inbound_messages, :outbound_messages, :thread_messages, :number, :name, :users, :server
|
9
|
-
attr_accessor :failed_messages
|
12
|
+
attr_accessor :failed_messages, :joined
|
10
13
|
|
11
14
|
def initialize(domain, token, params = {})
|
12
15
|
@domain = domain
|
@@ -19,23 +22,40 @@ module Flamethrower
|
|
19
22
|
@name = params['name']
|
20
23
|
@topic = params['topic']
|
21
24
|
@users = []
|
22
|
-
@
|
25
|
+
@joined = false
|
26
|
+
@room_info_sent = false
|
27
|
+
@room_alive = false
|
23
28
|
end
|
24
29
|
|
25
30
|
def topic
|
26
31
|
@topic || "No topic"
|
27
32
|
end
|
28
33
|
|
29
|
-
def send_topic
|
30
|
-
|
31
|
-
|
34
|
+
def send_topic(topic)
|
35
|
+
http = campfire_put("/room/#{@number}.json", {:topic => topic}.to_json)
|
36
|
+
http.callback do
|
37
|
+
@topic = topic if http.response_header.status == 200
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def send_info
|
42
|
+
@server.send_topic(to_irc)
|
43
|
+
@server.send_userlist(to_irc)
|
32
44
|
end
|
33
45
|
|
34
46
|
def fetch_room_info
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
47
|
+
http = campfire_get("/room/#{@number}.json")
|
48
|
+
http.callback do
|
49
|
+
case http.response_header.status
|
50
|
+
when 200
|
51
|
+
@users = []
|
52
|
+
json = JSON.parse(http.response)
|
53
|
+
json['room']['users'].each do |user|
|
54
|
+
@users << Flamethrower::Campfire::User.new(user)
|
55
|
+
end
|
56
|
+
send_info unless @room_info_sent
|
57
|
+
@room_info_sent = true
|
58
|
+
end
|
39
59
|
end
|
40
60
|
end
|
41
61
|
|
@@ -44,40 +64,47 @@ module Flamethrower
|
|
44
64
|
@outbound_messages << Flamethrower::Campfire::Message.new(params)
|
45
65
|
end
|
46
66
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
67
|
+
def start
|
68
|
+
@room_alive = true
|
69
|
+
fetch_room_info
|
70
|
+
connect
|
71
|
+
@polling_timer = EventMachine.add_periodic_timer(POLL_SECONDS) { poll }
|
72
|
+
@periodic_timer = EventMachine.add_periodic_timer(PERIODIC_UPDATE_SECONDS) { fetch_room_info }
|
73
|
+
end
|
74
|
+
|
75
|
+
def stop
|
76
|
+
@room_alive = false
|
77
|
+
EventMachine.cancel_timer(@polling_timer)
|
78
|
+
EventMachine.cancel_timer(@periodic_timer)
|
79
|
+
end
|
80
|
+
|
81
|
+
def poll
|
82
|
+
unless dead?
|
83
|
+
fetch_messages
|
84
|
+
post_messages
|
85
|
+
requeue_failed_messages
|
86
|
+
fetch_users
|
87
|
+
messages_to_send = to_irc.retrieve_irc_messages
|
88
|
+
messages_to_send.each do |m|
|
89
|
+
::FLAMETHROWER_LOGGER.debug "Sending irc message #{m.to_s}"
|
90
|
+
@server.send_message(m.to_s)
|
63
91
|
end
|
64
92
|
end
|
65
93
|
end
|
66
94
|
|
67
95
|
def alive?
|
68
|
-
@
|
96
|
+
@room_alive
|
69
97
|
end
|
70
98
|
|
71
99
|
def dead?
|
72
|
-
!@
|
73
|
-
end
|
74
|
-
|
75
|
-
def kill_thread!
|
76
|
-
@thread_running = false
|
100
|
+
!@room_alive
|
77
101
|
end
|
78
102
|
|
79
103
|
def join
|
80
|
-
campfire_post("/room/#{@number}/join.json")
|
104
|
+
http = campfire_post("/room/#{@number}/join.json")
|
105
|
+
http.callback do
|
106
|
+
@joined = true if http.response_header.status == 200
|
107
|
+
end
|
81
108
|
end
|
82
109
|
|
83
110
|
def connect
|
@@ -89,8 +116,8 @@ module Flamethrower
|
|
89
116
|
|
90
117
|
def fetch_messages
|
91
118
|
@stream.each_item do |item|
|
119
|
+
::FLAMETHROWER_LOGGER.debug "Got json message #{item.inspect}"
|
92
120
|
params = JSON.parse(item)
|
93
|
-
::FLAMETHROWER_LOGGER.debug "Got json message #{params.inspect}"
|
94
121
|
params['user'] = @users.find {|u| u.number == params['user_id'] }
|
95
122
|
params['room'] = self
|
96
123
|
message = Flamethrower::Campfire::Message.new(params)
|
@@ -107,14 +134,16 @@ module Flamethrower
|
|
107
134
|
def fetch_users
|
108
135
|
until @users_to_fetch.empty?
|
109
136
|
message = @users_to_fetch.pop
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
137
|
+
http = campfire_get("/users/#{message.user_id}.json")
|
138
|
+
http.callback do
|
139
|
+
case http.response_header.status
|
140
|
+
when 200
|
141
|
+
json = JSON.parse(http.response)
|
142
|
+
user = Flamethrower::Campfire::User.new(json['user'])
|
143
|
+
message.user = user
|
144
|
+
@users << user
|
145
|
+
@inbound_messages << message
|
146
|
+
end
|
118
147
|
end
|
119
148
|
end
|
120
149
|
end
|
@@ -124,14 +153,16 @@ module Flamethrower
|
|
124
153
|
message = @outbound_messages.pop
|
125
154
|
json = {"message" => {"body" => message.body, "type" => message.message_type}}.to_json
|
126
155
|
::FLAMETHROWER_LOGGER.debug "Sending #{json} to campfire API"
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
156
|
+
http = campfire_post("/room/#{@number}/speak.json", json)
|
157
|
+
http.callback do
|
158
|
+
case http.response_header.status
|
159
|
+
when 201
|
160
|
+
message.mark_delivered!
|
161
|
+
else
|
162
|
+
::FLAMETHROWER_LOGGER.debug "Failed to post to campfire API with code: #{http.response_header.status} body: #{http.response}"
|
163
|
+
message.mark_failed!
|
164
|
+
@failed_messages << message
|
165
|
+
end
|
135
166
|
end
|
136
167
|
end
|
137
168
|
end
|
@@ -139,7 +170,11 @@ module Flamethrower
|
|
139
170
|
def retrieve_messages
|
140
171
|
Array.new.tap do |new_array|
|
141
172
|
until @inbound_messages.empty?
|
142
|
-
|
173
|
+
message = @inbound_messages.pop
|
174
|
+
next unless message
|
175
|
+
unless message.user.to_irc.nickname == @server.current_user.nickname
|
176
|
+
new_array << message
|
177
|
+
end
|
143
178
|
end
|
144
179
|
end
|
145
180
|
end
|