em-campfire 1.0.0 → 1.1.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/README.md +2 -2
- data/lib/em-campfire/connection.rb +1 -1
- data/lib/em-campfire/version.rb +1 -1
- data/lib/em-campfire.rb +5 -1
- data/spec/lib/connection_spec.rb +17 -8
- data/spec/lib/em-campfire_spec.rb +13 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -52,7 +52,8 @@ EM.run {
|
|
52
52
|
:api_key => "jhhekrlfjnksdjnliyherkjb",
|
53
53
|
:verbose => true,
|
54
54
|
:logger => Logger::Syslog.new('process_name', Syslog::LOG_PID | Syslog::LOG_CONS),
|
55
|
-
:cache => custom_cache_object
|
55
|
+
:cache => custom_cache_object,
|
56
|
+
:ignore_self => true
|
56
57
|
)
|
57
58
|
|
58
59
|
# more code
|
@@ -83,7 +84,6 @@ I've tested it in Ruby >= 1.9.3.
|
|
83
84
|
|
84
85
|
## TODO
|
85
86
|
|
86
|
-
* I mock is\_me? in "should be able to ignore itself" in connection_spec.rb for convenience, work out a way to not do that
|
87
87
|
* See if http connection/cacheing/failure handling can be abstracted
|
88
88
|
* Allow user to pass success/error callbacks
|
89
89
|
* Re-try failed HTTP requests
|
@@ -12,12 +12,12 @@ module EventMachine
|
|
12
12
|
attr_accessor :on_message_block
|
13
13
|
|
14
14
|
def process_message(msg)
|
15
|
+
return if (msg[:type] == "TimestampMessage" && ignore_timestamps?)
|
15
16
|
logger.debug "Received message #{msg.inspect}"
|
16
17
|
if ignore_self && is_me?(msg[:user_id])
|
17
18
|
logger.debug "Ignoring message with user_id #{msg[:user_id]} as that is me and ignore_self is true"
|
18
19
|
else
|
19
20
|
if on_message_block
|
20
|
-
logger.debug "on_message callback exists, calling it with #{msg.inspect}"
|
21
21
|
on_message_block.call(msg)
|
22
22
|
else
|
23
23
|
logger.debug "on_message callback does not exist"
|
data/lib/em-campfire/version.rb
CHANGED
data/lib/em-campfire.rb
CHANGED
@@ -12,7 +12,7 @@ require "em-campfire/cache"
|
|
12
12
|
|
13
13
|
module EventMachine
|
14
14
|
class Campfire
|
15
|
-
attr_accessor :logger, :verbose, :subdomain, :api_key
|
15
|
+
attr_accessor :logger, :verbose, :subdomain, :api_key, :ignore_timestamps
|
16
16
|
|
17
17
|
include Connection
|
18
18
|
include Rooms
|
@@ -56,5 +56,9 @@ module EventMachine
|
|
56
56
|
@verbose = is_verbose
|
57
57
|
logger.level = Logger::DEBUG if is_verbose
|
58
58
|
end
|
59
|
+
|
60
|
+
def ignore_timestamps?
|
61
|
+
self.ignore_timestamps || false
|
62
|
+
end
|
59
63
|
end # Campfire
|
60
64
|
end # EventMachine
|
data/spec/lib/connection_spec.rb
CHANGED
@@ -13,25 +13,25 @@ end
|
|
13
13
|
|
14
14
|
describe EventMachine::Campfire::Connection do
|
15
15
|
before :each do
|
16
|
-
mock_logger(ConnectionTester)
|
17
16
|
@conn = ConnectionTester.new
|
18
17
|
end
|
19
18
|
|
20
|
-
it "should
|
21
|
-
|
22
|
-
|
19
|
+
it "should alert if on_message callback doesn't exist" do
|
20
|
+
mock_logger(ConnectionTester)
|
21
|
+
@conn.receive_message({:type=>"TextMessage"})
|
23
22
|
logger_output.should =~ /DEBUG.*on_message callback does not exist/
|
24
23
|
end
|
25
24
|
|
26
25
|
it "should process on_message an block if present" do
|
26
|
+
mock_logger(ConnectionTester)
|
27
27
|
ping = mock
|
28
|
-
ping.expects(:ping).with("
|
28
|
+
ping.expects(:ping).with({:type=>"TextMessage"})
|
29
29
|
@conn.on_message {|message| ping.ping(message) }
|
30
|
-
@conn.receive_message
|
31
|
-
logger_output.should =~ /DEBUG.*on_message callback exists, calling it with "foo"/
|
30
|
+
@conn.receive_message({:type=>"TextMessage"})
|
32
31
|
end
|
33
32
|
|
34
33
|
it "should be able to ignore itself" do
|
34
|
+
mock_logger(ConnectionTester)
|
35
35
|
@conn.ignore_self = true
|
36
36
|
@conn.cache.stubs(:get).with('user-data-me').returns({'id' => 789})
|
37
37
|
|
@@ -39,11 +39,12 @@ describe EventMachine::Campfire::Connection do
|
|
39
39
|
ping.expects(:ping).never
|
40
40
|
|
41
41
|
@conn.on_message { ping.ping }
|
42
|
-
EM.run_block { @conn.receive_message({:user_id => 789}) }
|
42
|
+
EM.run_block { @conn.receive_message({:user_id => 789, :type=>"TextMessage"}) }
|
43
43
|
logger_output.should =~ /Ignoring message with user_id 789 as that is me and ignore_self is true/
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should not ignore non-self messages" do
|
47
|
+
mock_logger(ConnectionTester)
|
47
48
|
stub_self_data_request
|
48
49
|
@conn.ignore_self = true
|
49
50
|
|
@@ -52,4 +53,12 @@ describe EventMachine::Campfire::Connection do
|
|
52
53
|
@conn.on_message { ping.ping }
|
53
54
|
EM.run_block { @conn.receive_message({:user_id => 2}) }
|
54
55
|
end
|
56
|
+
|
57
|
+
it "should be able to ignore timestamps" do
|
58
|
+
@conn.expects(:ignore_timestamps?).returns(true)
|
59
|
+
ping = mock
|
60
|
+
ping.expects(:ping).never
|
61
|
+
@conn.on_message {|message| ping.ping }
|
62
|
+
@conn.receive_message({:room_id=>410261, :created_at=>"2012/10/03 22:55:00 +0000", :body=>nil, :starred=>false, :id=>688112871, :user_id=>nil, :type=>"TimestampMessage"})
|
63
|
+
end
|
55
64
|
end
|
@@ -3,7 +3,6 @@ require "spec_helper"
|
|
3
3
|
describe EventMachine::Campfire do
|
4
4
|
|
5
5
|
before :each do
|
6
|
-
# stub_room_list_data_request
|
7
6
|
@self_data_request_stub = stub_self_data_request
|
8
7
|
end
|
9
8
|
|
@@ -81,7 +80,20 @@ describe EventMachine::Campfire do
|
|
81
80
|
@adaptor.cache.set("foo", "bar")
|
82
81
|
@adaptor.cache.get("foo").should eql("bar")
|
83
82
|
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#ignore_timestamps" do
|
86
|
+
before :each do
|
87
|
+
EM.run_block { @adaptor = a EM::Campfire }
|
88
|
+
end
|
84
89
|
|
90
|
+
it "should default to false" do
|
91
|
+
@adaptor.ignore_timestamps?.should eql(false)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should be overridable at initialization" do
|
95
|
+
EM.run_block { a(EM::Campfire, :ignore_timestamps => true).ignore_timestamps?.should be_true }
|
96
|
+
end
|
85
97
|
end
|
86
98
|
end
|
87
99
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-campfire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
segments:
|
187
187
|
- 0
|
188
|
-
hash:
|
188
|
+
hash: 734765957230943654
|
189
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
190
|
none: false
|
191
191
|
requirements:
|
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
segments:
|
196
196
|
- 0
|
197
|
-
hash:
|
197
|
+
hash: 734765957230943654
|
198
198
|
requirements: []
|
199
199
|
rubyforge_project:
|
200
200
|
rubygems_version: 1.8.24
|