Skip to content

Commit

Permalink
Merge pull request #73 from rkadyb/master
Browse files Browse the repository at this point in the history
add a 'closed' event
  • Loading branch information
dblock committed Mar 29, 2016
2 parents fcfe9b2 + 992d7c4 commit 9a1245a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.7.1 (Next)

* Your contribution here.
* [#73](https://github.com/dblock/slack-ruby-client/issues/73): Add a `closed` event - [@rkadyb](https://github.com/rkadyb).
* [#69](https://github.com/dblock/slack-ruby-client/issues/69): Add attachments support for `Slack::Web::Api::Endpoints::Chat.chat_update` - [@nicka](https://github.com/nicka).

### 0.7.0 (3/6/2016)
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ client.on :message do |data|
end
end

client.on :close do |_data|
puts "Client is about to disconnect"
end

client.on :closed do |_data|
puts "Client has disconnected successfully!"
end

client.start!
```

Expand Down
6 changes: 5 additions & 1 deletion examples/hi_real_time/hi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@
end

client.on :close do |_data|
puts 'Connection closed, exiting.'
puts 'Connection closing, exiting.'
EM.stop
end

client.on :closed do |_data|
puts 'Connection has been disconnected.'
end

client.start!
1 change: 1 addition & 0 deletions lib/slack/real_time/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def run_loop(socket)
logger.debug("#{self.class}##{__method__}") { event.class.name }
callback(event, :close)
close(event)
callback(event, :closed)
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/integration/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,24 @@ def stop_server

start_server
end

it 'gets close, followed by closed' do
client.on :hello do
expect(client.started?).to be true
client.stop!
end

client.on :close do |data|
logger.debug "client.on :close, data=#{data}"
expect(client.started?).to be true
@close_called = true
end

client.on :closed do |data|
logger.debug "client.on :closed, data=#{data}"
expect(@close_called).to be true
end

start_server
end
end

0 comments on commit 9a1245a

Please sign in to comment.