Skip to content

Commit

Permalink
Added Slack::RealTime::Client.config#websocket_proxy.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jul 30, 2015
1 parent 21eb106 commit b1bfda2
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-07-30 10:21:38 +0200 using RuboCop version 0.32.1.
# on 2015-07-30 11:21:36 +0200 using RuboCop version 0.32.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
Metrics/AbcSize:
Max: 20
Max: 21

# Offense count: 101
# Offense count: 102
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 153

# Offense count: 3
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 18
Max: 19

# Offense count: 32
Style/Documentation:
Expand Down
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
### 0.1.1 (Next)

* [#2](https://github.com/dblock/slack-ruby-client/pull/2): `Slack::RealTime::Socket` now pings frames every 30s, as recommended by Slack - [@samdoiron](https://github.com/samdoiron).
* Ping frequency is now configurable with `Slack::RealTime::Client.websocket_ping` - [@dblock](https://github.com/dblock).
* [#3](https://github.com/dblock/slack-ruby-client/issues/3): RealTime client WebSocket frame ping frequency is now configurable with `Slack::RealTime::Client.websocket_ping` - [@dblock](https://github.com/dblock).
* [#3](https://github.com/dblock/slack-ruby-client/issues/3): RealTime client WebSocket proxy is now configurable with `Slack::RealTime::Client.websocket_proxy` - [@dblock](https://github.com/dblock).
* [#3](https://github.com/dblock/slack-ruby-client/issues/3): Added global `Slack::Web::Client` and `Slack::RealTime::Client` configuration options via `Slack::Web::Client.configure` and `Slack::RealTime::Client.configure` - [@dblock](https://github.com/dblock).
* Exposed `Slack::RealTime::Client.url`, `team`, `self`, `users`, `channels`, `groups`, `ims` and `bots` - [@dblock](https://github.com/dblock).
* Added global `Slack::RealTime::Client` configuration options via `Slack::RaalTime::Client.configure` - [@dblock](https://github.com/dblock).
* Exposed global `Slack::Web::Client` configuration options via `Slack::Web::Client.configure` - [@dblock](https://github.com/dblock).
* Fix: set `Slack::Web::Client` connection options for `ca_path`, `ca_file`, and `proxy` - [@dblock](https://github.com/dblock).
* Default user-agent for `Slack::Web::Client` now includes a slash, eg. _Slack Ruby Client/0.1.1_ - [@dblock](https://github.com/dblock).
* Fix: set `Slack::Web::Client` connection options for `ca_path`, `ca_file`, and `proxy` - [@dblock](https://github.com/dblock).

* Your contribution here.

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ client = Slack::RealTime::Client.new(websocket_ping: 42)

The following settings are supported.

setting | description
---------------|--------------------------------------------------------------------------------------
websocket_ping | The number of seconds that indicates how often the WebSocket should send ping frames.
setting | description
----------------|-----------------------------------------------------------------------------------------------------
websocket_ping | The number of seconds that indicates how often the WebSocket should send ping frames, default is 30.
websocket_proxy | Connect via proxy, include `:origin` and `:headers`.

Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start), configure Web client options via `Slack::Web::Client.configure` as described above.

Expand Down
1 change: 1 addition & 0 deletions lib/slack/real_time/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def start!

socket_options = {}
socket_options[:ping] = websocket_ping if websocket_ping
socket_options[:proxy] = websocket_proxy if websocket_proxy
@socket = Slack::RealTime::Socket.new(@options['url'], socket_options)

@socket.connect! do |ws|
Expand Down
3 changes: 2 additions & 1 deletion lib/slack/real_time/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Config
extend self

ATTRIBUTES = [
:websocket_ping
:websocket_ping,
:websocket_proxy
]

attr_accessor(*Config::ATTRIBUTES)
Expand Down
32 changes: 32 additions & 0 deletions spec/slack/real_time/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
it 'sets ping' do
expect(client.websocket_ping).to eq 30
end
it "doesn't set proxy" do
expect(client.websocket_proxy).to be nil
end
Slack::RealTime::Config::ATTRIBUTES.each do |key|
it "sets #{key}" do
expect(client.send(key)).to eq Slack::RealTime::Config.send(key)
Expand Down Expand Up @@ -122,5 +125,34 @@
end
end
end
context 'proxy' do
before do
Slack::RealTime::Client.configure do |config|
config.websocket_proxy = {
origin: 'http://username:[email protected]',
headers: { 'User-Agent' => 'ruby' }
}
end
end
describe '#initialize' do
it 'sets proxy' do
expect(client.websocket_proxy).to eq(
origin: 'http://username:[email protected]',
headers: { 'User-Agent' => 'ruby' }
)
end
it 'creates a connection with custom proxy' do
expect(Faye::WebSocket::Client).to receive(:new).with(
url,
nil,
ping: 30,
proxy: {
origin: 'http://username:[email protected]',
headers: { 'User-Agent' => 'ruby' }
}).and_return(ws)
client.start!
end
end
end
end
end

0 comments on commit b1bfda2

Please sign in to comment.