em-campfire 1.2.3 → 1.2.4
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.
- checksums.yaml +4 -4
- data/lib/em-campfire/rooms.rb +29 -10
- data/lib/em-campfire/version.rb +1 -1
- data/spec/lib/em-campfire_spec.rb +15 -15
- data/spec/lib/rooms_spec.rb +7 -5
- data/spec/rooms_helper.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 03387cbabb71c147c753b0fc2173f288d8ccde49
|
|
4
|
+
data.tar.gz: 125625355cfed4fdf51fd03c60d2d8f0062724a7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9c70174af33d488f9d431e2d72557fa6fbaf5740af40848e4f1b06b7350075d4ddd94bcba65dd53cc3eaf82acf1acf21952a63775907982d7d2306b9a9e346a6
|
|
7
|
+
data.tar.gz: 9e2fe6b01ec3d682c19434a6818abc94b92bff3e0dee1c25eaa3f80d0ca87ccc978ef635669be402bb4f0a7f426cfe824b72f20cbea47ad01251e7843a5cf3e8
|
data/lib/em-campfire/rooms.rb
CHANGED
|
@@ -11,9 +11,11 @@ module EventMachine
|
|
|
11
11
|
http.errback { logger.error "Error joining room: #{room_id}" }
|
|
12
12
|
http.callback {
|
|
13
13
|
if http.response_header.status == 200
|
|
14
|
-
logger.info "Joined room #{room_id} successfully"
|
|
14
|
+
EM.defer {logger.info "Joined room #{room_id} successfully"}
|
|
15
15
|
joined_rooms[room_id] = true
|
|
16
|
-
|
|
16
|
+
if block_given?
|
|
17
|
+
EM.next_tick { yield(room_id) }
|
|
18
|
+
end
|
|
17
19
|
else
|
|
18
20
|
logger.error "Error joining room: #{room_id}"
|
|
19
21
|
end
|
|
@@ -26,12 +28,15 @@ module EventMachine
|
|
|
26
28
|
|
|
27
29
|
url = "https://streaming.campfirenow.com/room/#{room_id}/live.json"
|
|
28
30
|
# Timeout per https://github.com/igrigorik/em-http-request/wiki/Redirects-and-Timeouts
|
|
29
|
-
http = EventMachine::HttpRequest.new(url, :connect_timeout =>
|
|
31
|
+
http = EventMachine::HttpRequest.new(url, :connect_timeout => 30, :inactivity_timeout => 8).get :head => {'authorization' => [api_key, 'X'], 'user-agent' => user_agent}
|
|
30
32
|
http.errback {
|
|
31
33
|
logger.error "Couldn't stream room #{room_id} at url #{url}, error was #{http.error}"
|
|
32
|
-
|
|
34
|
+
EventMachine::Timer.new(5) {
|
|
35
|
+
EM.next_tick{stream(room_id)}
|
|
36
|
+
}
|
|
33
37
|
}
|
|
34
38
|
http.callback {
|
|
39
|
+
puts http.response_header.status
|
|
35
40
|
if http.response_header.status == 200
|
|
36
41
|
logger.info "Disconnected from #{url}"
|
|
37
42
|
else
|
|
@@ -40,12 +45,26 @@ module EventMachine
|
|
|
40
45
|
EM.next_tick {stream(room_id)}
|
|
41
46
|
}
|
|
42
47
|
http.stream do |chunk|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
if http.response_header.status == 401
|
|
49
|
+
http.close
|
|
50
|
+
|
|
51
|
+
join(room_id) {
|
|
52
|
+
EventMachine::Timer.new(5) {
|
|
53
|
+
EM.next_tick { stream(room_id) }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
elsif http.response_header.status == 200
|
|
57
|
+
logger.debug "Got keepalive" if chunk == " "
|
|
58
|
+
begin
|
|
59
|
+
json_parser << chunk
|
|
60
|
+
rescue Yajl::ParseError => e
|
|
61
|
+
logger.error "Couldn't parse json data for room 123, data was #{chunk}, error was: #{e}"
|
|
62
|
+
http.close
|
|
63
|
+
logger.error "Closed connection"
|
|
64
|
+
EM.next_tick {stream(room_id)}
|
|
65
|
+
end
|
|
66
|
+
else
|
|
67
|
+
raise RuntimeError, "Got status #{http.response_header.status} while connecting to #{url}"
|
|
49
68
|
end
|
|
50
69
|
end
|
|
51
70
|
end
|
data/lib/em-campfire/version.rb
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
describe EventMachine::Campfire do
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
before :each do
|
|
6
6
|
@self_data_request_stub = stub_self_data_request
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
describe "#initialize" do
|
|
10
10
|
it "should work with valid params" do
|
|
11
11
|
EM.run_block { a(EM::Campfire).should be_a(EM::Campfire) }
|
|
12
12
|
end
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
it "should raise when given an option it doesn't understand" do
|
|
15
15
|
lambda { EM::Campfire.new(valid_params.merge({:fred => "estaire"}))}.should raise_error(ArgumentError, ":fred is not a valid option")
|
|
16
16
|
end
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
it "should require essential parameters" do
|
|
19
19
|
lambda { EM::Campfire.new }.should raise_error(ArgumentError, "You must pass an API key")
|
|
20
20
|
lambda { EM::Campfire.new(:api_key => "foo") }.should raise_error(ArgumentError, "You must pass a subdomain")
|
|
@@ -25,37 +25,37 @@ describe EventMachine::Campfire do
|
|
|
25
25
|
@self_data_request_stub.should have_been_requested
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
describe "#verbose" do
|
|
30
30
|
it "should default to false" do
|
|
31
|
-
EM.run_block { a(EM::Campfire).verbose.should
|
|
31
|
+
EM.run_block { a(EM::Campfire).verbose.should be_falsey }
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
it "should be overridable at initialization" do
|
|
35
|
-
EM.run_block { a(EM::Campfire, :verbose => true).verbose.should
|
|
35
|
+
EM.run_block { a(EM::Campfire, :verbose => true).verbose.should be true }
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
describe "#logger" do
|
|
40
40
|
context "default logger" do
|
|
41
41
|
before { EM.run_block { @adaptor = a EM::Campfire } }
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
it { @adaptor.logger.should be_a(Logger) }
|
|
44
44
|
it { @adaptor.logger.level.should be == Logger::INFO }
|
|
45
45
|
end
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
context "default logger in verbose mode" do
|
|
48
48
|
before { EM.run_block { @adaptor = a EM::Campfire, :verbose => true } }
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
it { @adaptor.logger.level.should be == Logger::DEBUG }
|
|
51
51
|
end
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
context "overriding default" do
|
|
54
54
|
before do
|
|
55
55
|
@custom_logger = Logger.new("/dev/null")
|
|
56
56
|
EM.run_block { @adaptor = a EM::Campfire, :logger => @custom_logger }
|
|
57
57
|
end
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
it { @adaptor.logger.should be == @custom_logger }
|
|
60
60
|
end
|
|
61
61
|
end
|
|
@@ -92,7 +92,7 @@ describe EventMachine::Campfire do
|
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
it "should be overridable at initialization" do
|
|
95
|
-
EM.run_block { a(EM::Campfire, :ignore_timestamps => true).ignore_timestamps?.should
|
|
95
|
+
EM.run_block { a(EM::Campfire, :ignore_timestamps => true).ignore_timestamps?.should be true }
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
98
|
|
data/spec/lib/rooms_spec.rb
CHANGED
|
@@ -17,7 +17,7 @@ describe EventMachine::Campfire::Rooms do
|
|
|
17
17
|
it "should allow joining by id" do
|
|
18
18
|
join_stub = stub_join_room_request(123)
|
|
19
19
|
EM.run_block { @adaptor.join(123) }
|
|
20
|
-
logger_output.should =~ /INFO.*
|
|
20
|
+
logger_output.should =~ /INFO.*Joining room 123/
|
|
21
21
|
join_stub.should have_been_requested
|
|
22
22
|
end
|
|
23
23
|
|
|
@@ -30,11 +30,13 @@ describe EventMachine::Campfire::Rooms do
|
|
|
30
30
|
it "should call a passed block on success" do
|
|
31
31
|
join_stub = stub_join_room_request(123)
|
|
32
32
|
object = mock()
|
|
33
|
-
object.expects(:ping).with(
|
|
33
|
+
object.expects(:ping).with(123)
|
|
34
34
|
|
|
35
|
-
EM.
|
|
36
|
-
@adaptor.join(123) {|room_id| object.ping(
|
|
35
|
+
EM.run {
|
|
36
|
+
@adaptor.join(123) {|room_id| object.ping(room_id) }
|
|
37
|
+
EM.next_tick { EM.next_tick { EM.stop } }
|
|
37
38
|
}
|
|
39
|
+
|
|
38
40
|
end
|
|
39
41
|
end
|
|
40
42
|
|
|
@@ -67,7 +69,7 @@ describe EventMachine::Campfire::Rooms do
|
|
|
67
69
|
request = stub_timeout_stream_room_request(123)
|
|
68
70
|
|
|
69
71
|
EM.run_block {@adaptor.stream(123)}
|
|
70
|
-
request.should have_been_requested.twice
|
|
72
|
+
EM.next_tick{ EM.next_tick{ request.should have_been_requested.twice } }
|
|
71
73
|
logger_output.should =~ /ERROR.*Couldn't stream room 123 at url #{stream_url_for_room(123)}, error was WebMock timeout error/
|
|
72
74
|
end
|
|
73
75
|
|
data/spec/rooms_helper.rb
CHANGED
|
@@ -85,7 +85,7 @@ end
|
|
|
85
85
|
|
|
86
86
|
def stub_timeout_room_list_data_request
|
|
87
87
|
stub_request(:get, rooms_data_url).
|
|
88
|
-
with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X'], 'Content-Type'=>'application/json'
|
|
88
|
+
with(:headers => {'Authorization'=>['6124d98749365e3db2c9e5b27ca04db6', 'X'], 'Content-Type'=>'application/json', 'User-Agent' => valid_params[:user_agent]}).
|
|
89
89
|
to_timeout
|
|
90
90
|
end
|
|
91
91
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: em-campfire
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Will Jessop
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: eventmachine
|
|
@@ -173,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
173
173
|
version: '0'
|
|
174
174
|
requirements: []
|
|
175
175
|
rubyforge_project:
|
|
176
|
-
rubygems_version: 2.
|
|
176
|
+
rubygems_version: 2.4.6
|
|
177
177
|
signing_key:
|
|
178
178
|
specification_version: 4
|
|
179
179
|
summary: Eventmachine campfire API lib
|