slack-ruby-client 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +20 -10
- data/.travis.yml +16 -10
- data/CHANGELOG.md +7 -0
- data/README.md +16 -5
- data/UPGRADING.md +16 -0
- data/lib/slack-ruby-client.rb +2 -0
- data/lib/slack/real_time/client.rb +11 -1
- data/lib/slack/real_time/concurrency/celluloid.rb +3 -3
- data/lib/slack/real_time/config.rb +2 -0
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/error.rb +1 -8
- data/lib/slack/web/api/errors/slack_error.rb +16 -0
- data/lib/slack/web/api/errors/too_many_requests_error.rb +23 -0
- data/lib/slack/web/api/mixins/ids.id.rb +1 -1
- data/lib/slack/web/faraday/connection.rb +1 -1
- data/lib/slack/web/faraday/response/raise_error.rb +7 -3
- data/spec/fixtures/slack/web/429_error.yml +2 -0
- data/spec/fixtures/slack/web/rtm_connect.yml +70 -0
- data/spec/fixtures/slack/web/rtm_start.yml +1 -1
- data/spec/slack/real_time/client_spec.rb +239 -108
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +26 -5
- data/spec/slack/real_time/event_handlers/team_spec.rb +6 -4
- data/spec/slack/real_time/rtm_connect_spec.rb +13 -0
- data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +8 -3
- data/spec/slack/web/api/errors/slack_error_spec.rb +14 -0
- data/spec/slack/web/api/mixins/channels_spec.rb +1 -1
- data/spec/slack/web/api/mixins/groups_spec.rb +1 -1
- data/spec/slack/web/api/mixins/users_spec.rb +1 -1
- data/spec/support/real_time/connected_client.rb +6 -1
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c27d0774e9e56d2188bf8e9aea953b86821a9156
|
4
|
+
data.tar.gz: d4ca8180bcc3d643e5dcc0b326975086831df51f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0395ba1c14c66f1f3360c71a9bb294fd33ed88775de08c933e6cb7c23aa47485a864e151a3dd41354debd266cd9d9fa1ba80d0c5260afb5f62b60c46c1784a4c'
|
7
|
+
data.tar.gz: bbe81ee65b8358950dc946791bb72c8e8e3c84ce6ac52fe73a9a66c2f70073394153d604fce446b3eff3590b94ff87a4236a5d447522c8e0e10af4dd54daeddd
|
data/.rubocop_todo.yml
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2017-04-30 12:02:22 -0400 using RuboCop version 0.35.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 3
|
10
10
|
Lint/HandleExceptions:
|
11
11
|
Exclude:
|
12
12
|
- 'lib/slack-ruby-client.rb'
|
13
|
-
- 'lib/slack/real_time/concurrency/celluloid.rb'
|
14
13
|
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
|
15
14
|
- 'spec/slack/real_time/concurrency/eventmachine_spec.rb'
|
16
15
|
|
@@ -21,20 +20,20 @@ Lint/UnusedBlockArgument:
|
|
21
20
|
Exclude:
|
22
21
|
- 'lib/slack/messages/formatting.rb'
|
23
22
|
|
24
|
-
# Offense count:
|
23
|
+
# Offense count: 14
|
25
24
|
Metrics/AbcSize:
|
26
25
|
Max: 44
|
27
26
|
|
28
27
|
# Offense count: 2
|
29
28
|
# Configuration parameters: CountComments.
|
30
29
|
Metrics/ClassLength:
|
31
|
-
Max:
|
30
|
+
Max: 165
|
32
31
|
|
33
|
-
# Offense count:
|
32
|
+
# Offense count: 3
|
34
33
|
Metrics/CyclomaticComplexity:
|
35
34
|
Max: 9
|
36
35
|
|
37
|
-
# Offense count:
|
36
|
+
# Offense count: 720
|
38
37
|
# Configuration parameters: AllowURI, URISchemes.
|
39
38
|
Metrics/LineLength:
|
40
39
|
Max: 288
|
@@ -48,7 +47,7 @@ Metrics/MethodLength:
|
|
48
47
|
Metrics/PerceivedComplexity:
|
49
48
|
Max: 11
|
50
49
|
|
51
|
-
# Offense count:
|
50
|
+
# Offense count: 59
|
52
51
|
# Configuration parameters: Exclude.
|
53
52
|
Style/Documentation:
|
54
53
|
Enabled: false
|
@@ -59,12 +58,12 @@ Style/FileName:
|
|
59
58
|
Exclude:
|
60
59
|
- 'lib/slack-ruby-client.rb'
|
61
60
|
|
62
|
-
# Offense count:
|
61
|
+
# Offense count: 116
|
63
62
|
# Configuration parameters: AllowedVariables.
|
64
63
|
Style/GlobalVars:
|
65
64
|
Enabled: false
|
66
65
|
|
67
|
-
# Offense count:
|
66
|
+
# Offense count: 21
|
68
67
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
69
68
|
Style/MethodName:
|
70
69
|
Enabled: false
|
@@ -76,6 +75,17 @@ Style/ModuleFunction:
|
|
76
75
|
- 'lib/slack/real_time/config.rb'
|
77
76
|
- 'lib/slack/web/config.rb'
|
78
77
|
|
78
|
+
# Offense count: 1
|
79
|
+
Style/MultilineTernaryOperator:
|
80
|
+
Exclude:
|
81
|
+
- 'spec/support/real_time/connected_client.rb'
|
82
|
+
|
83
|
+
# Offense count: 1
|
84
|
+
# Cop supports --auto-correct.
|
85
|
+
Style/RescueModifier:
|
86
|
+
Exclude:
|
87
|
+
- 'lib/slack/real_time/concurrency/celluloid.rb'
|
88
|
+
|
79
89
|
# Offense count: 2
|
80
90
|
# Cop supports --auto-correct.
|
81
91
|
Style/SpecialGlobalVars:
|
data/.travis.yml
CHANGED
@@ -2,22 +2,28 @@ language: ruby
|
|
2
2
|
|
3
3
|
cache: bundler
|
4
4
|
|
5
|
+
rvm:
|
6
|
+
- 2.2
|
7
|
+
- 2.1
|
8
|
+
- 2.0
|
9
|
+
- rbx-2
|
10
|
+
- jruby-19mode
|
11
|
+
- ruby-head
|
12
|
+
- jruby-head
|
13
|
+
|
5
14
|
matrix:
|
6
15
|
include:
|
7
|
-
- rvm: 2.
|
16
|
+
- rvm: 2.4.1
|
8
17
|
script:
|
9
18
|
- bundle exec danger
|
10
|
-
- rvm: 2.
|
19
|
+
- rvm: 2.4.1
|
11
20
|
env: CONCURRENCY=celluloid-io
|
12
|
-
- rvm: 2.
|
21
|
+
- rvm: 2.4.1
|
22
|
+
env: CONCURRENCY=faye-websocket
|
23
|
+
- rvm: 2.3.4
|
24
|
+
env: CONCURRENCY=celluloid-io
|
25
|
+
- rvm: 2.3.4
|
13
26
|
env: CONCURRENCY=faye-websocket
|
14
|
-
- rvm: 2.2
|
15
|
-
- rvm: 2.1
|
16
|
-
- rvm: 2.0
|
17
|
-
- rvm: rbx-2
|
18
|
-
- rvm: jruby-19mode
|
19
|
-
- rvm: ruby-head
|
20
|
-
- rvm: jruby-head
|
21
27
|
allow_failures:
|
22
28
|
- rvm: ruby-head
|
23
29
|
- rvm: jruby-head
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
### 0.9.0 (8/6/2017)
|
2
|
+
|
3
|
+
* [#146](https://github.com/slack-ruby/slack-ruby-client/issues/146): Fix: `undefined method running?` and `ThreadError: Target thread must not be current thread` with `Celluloid::IO` - [@dblock](https://github.com/dblock).
|
4
|
+
* [#145](https://github.com/slack-ruby/slack-ruby-client/pull/145): Automatically select `rtm_connect` vs. `rtm_start` - [@dblock](https://github.com/dblock).
|
5
|
+
* [#154](https://github.com/slack-ruby/slack-ruby-client/pull/154): Raise a dedicated error class with 429 responses - [@greggroth](https://github.com/greggroth).
|
6
|
+
* [#154](https://github.com/slack-ruby/slack-ruby-client/pull/154): Namespace error classes under `Slack::Web::Api::Errors` module - [@greggroth](https://github.com/greggroth).
|
7
|
+
|
1
8
|
### 0.8.1 (4/28/2017)
|
2
9
|
|
3
10
|
* Added `exclude_members` option to `channels_list` Web API - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ A Ruby client for the Slack [Web](https://api.slack.com/web) and [RealTime Messa
|
|
18
18
|
|
19
19
|
## Stable Release
|
20
20
|
|
21
|
-
You're reading the documentation for the **stable** release of slack-ruby-client, 0.
|
21
|
+
You're reading the documentation for the **stable** release of slack-ruby-client, 0.9.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
|
22
22
|
|
23
23
|
## Installation
|
24
24
|
|
@@ -244,11 +244,11 @@ Tracking with a local store can be disabled with `Slack::RealTime::Client.new(st
|
|
244
244
|
|
245
245
|
#### Slack::RealTime::Stores::Store
|
246
246
|
|
247
|
-
The default store that tracks all changes.
|
247
|
+
The default store that tracks all changes. By default the client will be connected using `rtm_start`.
|
248
248
|
|
249
249
|
#### Slack::RealTime::Stores::Starter
|
250
250
|
|
251
|
-
A smaller store that only stores and tracks information about the bot user, but not channels, users, groups, ims or bots.
|
251
|
+
A smaller store that only stores and tracks information about the bot user, but not channels, users, groups, ims or bots. By default the client will be connected using `rtm_connect`.
|
252
252
|
|
253
253
|
### Configuring Slack::RealTime::Client
|
254
254
|
|
@@ -272,15 +272,26 @@ token | Slack API token.
|
|
272
272
|
websocket_ping | The number of seconds that indicates how often the WebSocket should send ping frames, default is 30.
|
273
273
|
websocket_proxy | Connect via proxy, include `:origin` and `:headers`.
|
274
274
|
store_class | Local store class name, default is an in-memory `Slack::RealTime::Stores::Store`.
|
275
|
-
|
275
|
+
start_method | Optional start method, either `:rtm_start` or `:rtm_connect`.
|
276
|
+
start_options | Options to pass into `rtm.start` or `rtm.connect`, default is `{ request: { timeout: 180 } }`.
|
276
277
|
logger | Optional `Logger` instance that logs RealTime requests and socket data.
|
277
278
|
|
278
|
-
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start). While `token` and `logger` options are passed down from the RealTime client, you may also configure Web client options via `Slack::Web::Client.configure` as described above.
|
279
|
+
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start) or [rtm.connect](https://api.slack.com/methods/rtm.connect). While `token` and `logger` options are passed down from the RealTime client, you may also configure Web client options via `Slack::Web::Client.configure` as described above.
|
279
280
|
|
280
281
|
See a fully working example in [examples/hi_real_time](examples/hi_real_time/hi.rb).
|
281
282
|
|
282
283
|
![](examples/hi_real_time/hi.gif)
|
283
284
|
|
285
|
+
### Connection Methods
|
286
|
+
|
287
|
+
The RealTime client uses either [rtm.start](https://api.slack.com/methods/rtm.start) or [rtm.connect](https://api.slack.com/methods/rtm.connect) to open a connection. The former retrieves a lot of team information while the latter only serves connection purposes and is preferred. You should let the library choose the right method for you based on the `store_class` used and override this behavior with `start_method` when necessary.
|
288
|
+
|
289
|
+
```ruby
|
290
|
+
Slack::RealTime::Client.config do |config|
|
291
|
+
config.start_method = :rtm_start
|
292
|
+
end
|
293
|
+
```
|
294
|
+
|
284
295
|
### Combining RealTime and Web Clients
|
285
296
|
|
286
297
|
Since the Web client is used to obtain the RealTime client's WebSocket URL, you can continue using the Web client in combination with the RealTime client.
|
data/UPGRADING.md
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
Upgrading Slack-Ruby-Client
|
2
2
|
===========================
|
3
3
|
|
4
|
+
### Upgrading to >= 0.9.0
|
5
|
+
|
6
|
+
#### Changes in How the RTM Client Connects
|
7
|
+
|
8
|
+
The RealTime client now automatically chooses either [rtm.start](https://api.slack.com/methods/rtm.start) or [rtm.connect](https://api.slack.com/methods/rtm.connect) to open a connection. The former retrieves a lot of team information while the latter only serves connection purposes and is newer and preferred, while the latter is required to use the full `Slack::RealTime::Stores::Store` storage class.
|
9
|
+
|
10
|
+
Prior versions always used `rtm.start`, to restore this behavior, configure `start_method`.
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
Slack::RealTime::Client.config do |config|
|
14
|
+
config.start_method = :rtm_start
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
See [#145](https://github.com/slack-ruby/slack-ruby-client/pull/145) for more information.
|
19
|
+
|
4
20
|
### Upgrading to >= 0.8.0
|
5
21
|
|
6
22
|
The default timeout for `rtm.start` has been increased from 60 to 180 seconds via `Slack::RealTime::Client.config.start_options[:request][:timeout]`. If you're explicitly setting `start_options` in your application, preserve the value by merging settings instead of replacing the entire `start_options` value.
|
data/lib/slack-ruby-client.rb
CHANGED
@@ -18,6 +18,8 @@ rescue LoadError
|
|
18
18
|
# ignore, only used in users_search
|
19
19
|
end
|
20
20
|
require_relative 'slack/web/config'
|
21
|
+
require_relative 'slack/web/api/errors/slack_error'
|
22
|
+
require_relative 'slack/web/api/errors/too_many_requests_error'
|
21
23
|
require_relative 'slack/web/api/error'
|
22
24
|
require_relative 'slack/web/faraday/response/raise_error'
|
23
25
|
require_relative 'slack/web/faraday/connection'
|
@@ -107,13 +107,23 @@ module Slack
|
|
107
107
|
# @return [Slack::RealTime::Socket]
|
108
108
|
def build_socket
|
109
109
|
fail ClientAlreadyStartedError if started?
|
110
|
-
start = web_client.
|
110
|
+
start = web_client.send(rtm_start_method, start_options)
|
111
111
|
data = Slack::Messages::Message.new(start)
|
112
112
|
@url = data.url
|
113
113
|
@store = @store_class.new(data) if @store_class
|
114
114
|
socket_class.new(@url, socket_options)
|
115
115
|
end
|
116
116
|
|
117
|
+
def rtm_start_method
|
118
|
+
if start_method
|
119
|
+
start_method
|
120
|
+
elsif @store_class == Slack::RealTime::Stores::Store
|
121
|
+
:rtm_start
|
122
|
+
else
|
123
|
+
:rtm_connect
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
117
127
|
def socket_options
|
118
128
|
socket_options = {}
|
119
129
|
socket_options[:ping] = websocket_ping if websocket_ping
|
@@ -38,7 +38,7 @@ module Slack
|
|
38
38
|
logger.debug("#{self.class}##{__method__}") { e }
|
39
39
|
driver.emit(:close, WebSocket::Driver::CloseEvent.new(1001, 'server closed connection')) unless @closing
|
40
40
|
ensure
|
41
|
-
current_actor.terminate if current_actor.alive?
|
41
|
+
current_actor.terminate if current_actor.alive? rescue nil
|
42
42
|
end
|
43
43
|
|
44
44
|
def close
|
@@ -90,8 +90,8 @@ module Slack
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def build_socket
|
93
|
-
socket = TCPSocket.new(addr, port)
|
94
|
-
socket = SSLSocket.new(socket, build_ssl_context) if secure?
|
93
|
+
socket = ::Celluloid::IO::TCPSocket.new(addr, port)
|
94
|
+
socket = ::Celluloid::IO::SSLSocket.new(socket, build_ssl_context) if secure?
|
95
95
|
socket
|
96
96
|
end
|
97
97
|
|
@@ -10,6 +10,7 @@ module Slack
|
|
10
10
|
:websocket_ping,
|
11
11
|
:websocket_proxy,
|
12
12
|
:concurrency,
|
13
|
+
:start_method,
|
13
14
|
:start_options,
|
14
15
|
:store_class,
|
15
16
|
:logger
|
@@ -22,6 +23,7 @@ module Slack
|
|
22
23
|
self.websocket_proxy = nil
|
23
24
|
self.token = nil
|
24
25
|
self.concurrency = method(:detect_concurrency)
|
26
|
+
self.start_method = nil
|
25
27
|
self.start_options = { request: { timeout: 180 } }
|
26
28
|
self.store_class = Slack::RealTime::Store
|
27
29
|
self.logger = nil
|
data/lib/slack/version.rb
CHANGED
data/lib/slack/web/api/error.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Slack
|
2
|
+
module Web
|
3
|
+
module Api
|
4
|
+
module Errors
|
5
|
+
class TooManyRequestsError < ::Faraday::Error
|
6
|
+
attr_reader :response
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
|
12
|
+
def message
|
13
|
+
"Retry after #{retry_after} seconds"
|
14
|
+
end
|
15
|
+
|
16
|
+
def retry_after
|
17
|
+
response.headers['retry-after'].to_i
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -21,10 +21,10 @@ module Slack
|
|
21
21
|
::Faraday::Connection.new(endpoint, options) do |connection|
|
22
22
|
connection.use ::Faraday::Request::Multipart
|
23
23
|
connection.use ::Faraday::Request::UrlEncoded
|
24
|
+
connection.use ::Faraday::Response::RaiseError
|
24
25
|
connection.use ::Slack::Web::Faraday::Response::RaiseError
|
25
26
|
connection.use ::FaradayMiddleware::Mashify, mash_class: Slack::Messages::Message
|
26
27
|
connection.use ::FaradayMiddleware::ParseJson
|
27
|
-
connection.use ::Faraday::Response::RaiseError
|
28
28
|
connection.response :logger, logger if logger
|
29
29
|
connection.adapter ::Faraday.default_adapter
|
30
30
|
end
|
@@ -4,9 +4,13 @@ module Slack
|
|
4
4
|
module Response
|
5
5
|
class RaiseError < ::Faraday::Response::Middleware
|
6
6
|
def on_complete(env)
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
if env.status == 429
|
8
|
+
fail Slack::Web::Api::Errors::TooManyRequestsError, env.response
|
9
|
+
elsif (body = env.body) && body['ok']
|
10
|
+
return
|
11
|
+
else
|
12
|
+
fail Slack::Web::Api::Errors::SlackError.new(body['error'], env.response)
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://slack.com/api/rtm.connect
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: token=token
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json; charset=utf-8
|
12
|
+
User-Agent:
|
13
|
+
- Slack Ruby Client/0.8.2
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
Content-Length:
|
26
|
+
- '303'
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Access-Control-Allow-Origin:
|
30
|
+
- "*"
|
31
|
+
Cache-Control:
|
32
|
+
- private, no-cache, no-store, must-revalidate
|
33
|
+
Date:
|
34
|
+
- Fri, 28 Apr 2017 21:28:13 GMT
|
35
|
+
Expires:
|
36
|
+
- Mon, 26 Jul 1997 05:00:00 GMT
|
37
|
+
Pragma:
|
38
|
+
- no-cache
|
39
|
+
Referrer-Policy:
|
40
|
+
- no-referrer
|
41
|
+
Server:
|
42
|
+
- Apache
|
43
|
+
Strict-Transport-Security:
|
44
|
+
- max-age=31536000; includeSubDomains; preload
|
45
|
+
Vary:
|
46
|
+
- Accept-Encoding
|
47
|
+
X-Accepted-Oauth-Scopes:
|
48
|
+
- rtm:stream,client
|
49
|
+
X-Content-Type-Options:
|
50
|
+
- nosniff
|
51
|
+
X-Oauth-Scopes:
|
52
|
+
- identify,read,post,client,apps
|
53
|
+
X-Slack-Backend:
|
54
|
+
- h
|
55
|
+
X-Slack-Req-Id:
|
56
|
+
- 5126a5af-f201-4e61-8615-85ed74719049
|
57
|
+
X-Xss-Protection:
|
58
|
+
- '0'
|
59
|
+
X-Cache:
|
60
|
+
- Miss from cloudfront
|
61
|
+
Via:
|
62
|
+
- 1.1 bcaa616eaffeeb31e6c9015320755821.cloudfront.net (CloudFront)
|
63
|
+
X-Amz-Cf-Id:
|
64
|
+
- Hogs0uicEVP-FBGmgEZfEJz0EJHJwCny92KhIHz2j6YNYAJL0oVTJw==
|
65
|
+
body:
|
66
|
+
encoding: ASCII-8BIT
|
67
|
+
string: '{"ok":true,"url":"wss:\/\/mpmulti-w5tz.slack-msgs.com\/websocket\/uid","team":{"id":"T04KB5WQH","name":"dblock","domain":"dblockdotorg"},"self":{"id":"U07518DTL","name":"testbot"}}'
|
68
|
+
http_version:
|
69
|
+
recorded_at: Fri, 28 Apr 2017 21:28:14 GMT
|
70
|
+
recorded_with: VCR 3.0.3
|
@@ -101,4 +101,4 @@ http_interactions:
|
|
101
101
|
Explorer","icons":{"image_36":"https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-01-21\/19073538231_edf8d896148b6bfef790_36.png","image_48":"https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-01-21\/19073538231_edf8d896148b6bfef790_48.png","image_72":"https:\/\/s3-us-west-2.amazonaws.com\/slack-files2\/avatars\/2016-01-21\/19073538231_edf8d896148b6bfef790_72.png"}}],"url":"wss:\/\/ms173.slack-msgs.com\/websocket\/lqcUiAvrKTP-uuid="}'
|
102
102
|
http_version:
|
103
103
|
recorded_at: Sun, 31 Jan 2016 22:42:57 GMT
|
104
|
-
recorded_with: VCR 3.0.
|
104
|
+
recorded_with: VCR 3.0.3
|
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.describe Slack::RealTime::Client
|
3
|
+
RSpec.describe Slack::RealTime::Client do
|
4
4
|
let(:ws) { double(Slack::RealTime::Concurrency::Mock::WebSocket, on: true) }
|
5
|
-
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
|
6
5
|
before do
|
7
6
|
@token = ENV.delete('SLACK_API_TOKEN')
|
8
7
|
Slack::Config.reset
|
@@ -43,110 +42,182 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
43
42
|
end
|
44
43
|
end
|
45
44
|
end
|
46
|
-
context 'client' do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
45
|
+
context 'client with a full store', vcr: { cassette_name: 'web/rtm_start' } do
|
46
|
+
let(:client) { Slack::RealTime::Client.new(store_class: Slack::RealTime::Stores::Store) }
|
47
|
+
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
|
48
|
+
describe '#start!' do
|
49
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
50
|
+
before do
|
51
|
+
allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
52
|
+
allow(socket).to receive(:connect!)
|
53
|
+
allow(socket).to receive(:start_sync)
|
54
|
+
client.start!
|
55
|
+
end
|
56
|
+
context 'properties provided upon connection' do
|
57
|
+
it 'sets url' do
|
58
|
+
expect(client.url).to eq url
|
56
59
|
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
it 'sets ims' do
|
80
|
-
expect(client.ims.count).to eq 2
|
81
|
-
expect(client.ims.values.first['user']).to eq 'USLACKBOT'
|
82
|
-
end
|
83
|
-
it 'sets bots' do
|
84
|
-
expect(client.bots.count).to eq 16
|
85
|
-
expect(client.bots.values.first['name']).to eq 'bot'
|
86
|
-
end
|
87
|
-
it 'sets groups' do
|
88
|
-
expect(client.groups.count).to eq 1
|
89
|
-
end
|
60
|
+
it 'sets team' do
|
61
|
+
expect(client.team.domain).to eq 'dblockdotorg'
|
62
|
+
end
|
63
|
+
it 'sets teams' do
|
64
|
+
expect(client.teams.count).to eq 1
|
65
|
+
expect(client.teams.values.first).to eq client.team
|
66
|
+
end
|
67
|
+
it 'sets self' do
|
68
|
+
expect(client.self.id).to eq 'U07518DTL'
|
69
|
+
end
|
70
|
+
it 'sets users' do
|
71
|
+
expect(client.users.count).to eq 18
|
72
|
+
expect(client.users.values.first['id']).to eq 'U07518DTL'
|
73
|
+
end
|
74
|
+
it 'sets channels' do
|
75
|
+
expect(client.channels.count).to eq 37
|
76
|
+
expect(client.channels.values.first['name']).to eq 'a1'
|
77
|
+
end
|
78
|
+
it 'sets ims' do
|
79
|
+
expect(client.ims.count).to eq 2
|
80
|
+
expect(client.ims.values.first['user']).to eq 'USLACKBOT'
|
90
81
|
end
|
91
|
-
it '
|
92
|
-
expect(client.
|
82
|
+
it 'sets bots' do
|
83
|
+
expect(client.bots.count).to eq 16
|
84
|
+
expect(client.bots.values.first['name']).to eq 'bot'
|
93
85
|
end
|
94
|
-
it '
|
95
|
-
expect(client.
|
86
|
+
it 'sets groups' do
|
87
|
+
expect(client.groups.count).to eq 1
|
88
|
+
end
|
89
|
+
end
|
90
|
+
it 'uses web client to fetch url' do
|
91
|
+
expect(client.web_client).to be_a Slack::Web::Client
|
92
|
+
end
|
93
|
+
it 'remembers socket' do
|
94
|
+
expect(client.instance_variable_get('@socket')).to eq socket
|
95
|
+
end
|
96
|
+
it 'cannot be invoked twice' do
|
97
|
+
expect do
|
98
|
+
client.start!
|
99
|
+
end.to raise_error Slack::RealTime::Client::ClientAlreadyStartedError
|
100
|
+
end
|
101
|
+
describe '#stop!' do
|
102
|
+
before do
|
103
|
+
expect(socket).to receive(:disconnect!)
|
104
|
+
client.stop!
|
96
105
|
end
|
97
106
|
it 'cannot be invoked twice' do
|
107
|
+
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
98
108
|
expect do
|
99
|
-
client.
|
100
|
-
end.to raise_error Slack::RealTime::Client::
|
109
|
+
client.stop!
|
110
|
+
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
101
111
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
112
|
+
end
|
113
|
+
describe '#next_id' do
|
114
|
+
it 'increments' do
|
115
|
+
previous_id = client.send(:next_id)
|
116
|
+
expect(client.send(:next_id)).to eq previous_id + 1
|
117
|
+
end
|
118
|
+
end
|
119
|
+
context 'subclassed' do
|
120
|
+
let(:client) { Class.new(Slack::RealTime::Client).new(store_class: Slack::RealTime::Stores::Store) }
|
121
|
+
it 'runs event handlers' do
|
122
|
+
event = Slack::RealTime::Event.new(
|
123
|
+
'type' => 'team_rename',
|
124
|
+
'name' => 'New Team Name Inc.'
|
125
|
+
)
|
126
|
+
client.send(:dispatch, event)
|
127
|
+
expect(client.store.team.name).to eq 'New Team Name Inc.'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
context 'client with a default store', vcr: { cassette_name: 'web/rtm_connect' } do
|
133
|
+
let(:client) { Slack::RealTime::Client.new }
|
134
|
+
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
135
|
+
describe '#start!' do
|
136
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
137
|
+
before do
|
138
|
+
allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
139
|
+
allow(socket).to receive(:connect!)
|
140
|
+
allow(socket).to receive(:start_sync)
|
141
|
+
client.start!
|
142
|
+
end
|
143
|
+
context 'properties provided upon connection' do
|
144
|
+
it 'sets url' do
|
145
|
+
expect(client.url).to eq url
|
146
|
+
end
|
147
|
+
it 'sets team' do
|
148
|
+
expect(client.team.domain).to eq 'dblockdotorg'
|
149
|
+
end
|
150
|
+
it 'sets teams' do
|
151
|
+
expect(client.teams.count).to eq 1
|
152
|
+
expect(client.teams.values.first).to eq client.team
|
153
|
+
end
|
154
|
+
it 'sets self' do
|
155
|
+
expect(client.self.id).to eq 'U07518DTL'
|
156
|
+
end
|
157
|
+
it 'sets user' do
|
158
|
+
expect(client.users.count).to eq 1
|
159
|
+
expect(client.users.values.first['id']).to eq 'U07518DTL'
|
160
|
+
end
|
161
|
+
it 'no channels' do
|
162
|
+
expect(client.channels.count).to eq 0
|
163
|
+
end
|
164
|
+
it 'no ims' do
|
165
|
+
expect(client.ims.count).to eq 0
|
166
|
+
end
|
167
|
+
it 'no bots' do
|
168
|
+
expect(client.bots.count).to eq 0
|
169
|
+
end
|
170
|
+
it 'no groups' do
|
171
|
+
expect(client.groups.count).to eq 0
|
172
|
+
end
|
173
|
+
end
|
174
|
+
it 'uses web client to fetch url' do
|
175
|
+
expect(client.web_client).to be_a Slack::Web::Client
|
176
|
+
end
|
177
|
+
it 'remembers socket' do
|
178
|
+
expect(client.instance_variable_get('@socket')).to eq socket
|
179
|
+
end
|
180
|
+
it 'cannot be invoked twice' do
|
181
|
+
expect do
|
182
|
+
client.start!
|
183
|
+
end.to raise_error Slack::RealTime::Client::ClientAlreadyStartedError
|
184
|
+
end
|
185
|
+
describe '#stop!' do
|
186
|
+
before do
|
187
|
+
expect(socket).to receive(:disconnect!)
|
188
|
+
client.stop!
|
189
|
+
end
|
190
|
+
it 'cannot be invoked twice' do
|
191
|
+
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
192
|
+
expect do
|
105
193
|
client.stop!
|
106
|
-
end
|
107
|
-
it 'cannot be invoked twice' do
|
108
|
-
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
109
|
-
expect do
|
110
|
-
client.stop!
|
111
|
-
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
112
|
-
end
|
194
|
+
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
113
195
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
196
|
+
end
|
197
|
+
describe '#next_id' do
|
198
|
+
it 'increments' do
|
199
|
+
previous_id = client.send(:next_id)
|
200
|
+
expect(client.send(:next_id)).to eq previous_id + 1
|
119
201
|
end
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
it "doesn't handle events" do
|
126
|
-
event = Slack::RealTime::Event.new(
|
127
|
-
'type' => 'team_rename',
|
128
|
-
'name' => 'New Team Name Inc.'
|
129
|
-
)
|
130
|
-
expect(client).to_not receive(:run_handlers)
|
131
|
-
client.send(:dispatch, event)
|
132
|
-
end
|
133
|
-
it 'self' do
|
134
|
-
expect(client.self).to be nil
|
135
|
-
end
|
136
|
-
it 'team' do
|
137
|
-
expect(client.team).to be nil
|
138
|
-
end
|
202
|
+
end
|
203
|
+
context 'store_class: nil' do
|
204
|
+
let(:client) { Slack::RealTime::Client.new(store_class: nil) }
|
205
|
+
it 'sets store to nil' do
|
206
|
+
expect(client.store).to be nil
|
139
207
|
end
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
208
|
+
it "doesn't handle events" do
|
209
|
+
event = Slack::RealTime::Event.new(
|
210
|
+
'type' => 'team_rename',
|
211
|
+
'name' => 'New Team Name Inc.'
|
212
|
+
)
|
213
|
+
expect(client).to_not receive(:run_handlers)
|
214
|
+
client.send(:dispatch, event)
|
215
|
+
end
|
216
|
+
it 'self' do
|
217
|
+
expect(client.self).to be nil
|
218
|
+
end
|
219
|
+
it 'team' do
|
220
|
+
expect(client.team).to be nil
|
150
221
|
end
|
151
222
|
end
|
152
223
|
end
|
@@ -190,6 +261,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
190
261
|
after do
|
191
262
|
Slack::RealTime::Client.config.reset
|
192
263
|
end
|
264
|
+
let(:url) { 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid' }
|
193
265
|
let(:client) { Slack::RealTime::Client.new }
|
194
266
|
context 'ping' do
|
195
267
|
before do
|
@@ -201,7 +273,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
201
273
|
it 'sets ping' do
|
202
274
|
expect(client.websocket_ping).to eq 15
|
203
275
|
end
|
204
|
-
it 'creates a connection with custom ping' do
|
276
|
+
it 'creates a connection with custom ping', vcr: { cassette_name: 'web/rtm_connect' } do
|
205
277
|
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to receive(:new).with(url, nil, ping: 15).and_return(ws)
|
206
278
|
client.start!
|
207
279
|
end
|
@@ -226,7 +298,7 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
226
298
|
headers: { 'User-Agent' => 'ruby' }
|
227
299
|
)
|
228
300
|
end
|
229
|
-
it 'creates a connection with custom proxy' do
|
301
|
+
it 'creates a connection with custom proxy', vcr: { cassette_name: 'web/rtm_connect' } do
|
230
302
|
expect(Slack::RealTime::Concurrency::Mock::WebSocket).to receive(:new).with(
|
231
303
|
url,
|
232
304
|
nil,
|
@@ -256,26 +328,85 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
256
328
|
allow(socket).to receive(:connect!)
|
257
329
|
allow(socket).to receive(:start_sync)
|
258
330
|
end
|
259
|
-
it 'calls rtm_start with start options' do
|
260
|
-
expect(client.web_client).to receive(:
|
331
|
+
it 'calls rtm_start with start options', vcr: { cassette_name: 'web/rtm_connect' } do
|
332
|
+
expect(client.web_client).to receive(:rtm_connect).with(simple_latest: true).and_call_original
|
261
333
|
client.start!
|
262
334
|
end
|
263
335
|
end
|
264
336
|
end
|
265
337
|
end
|
266
338
|
context 'store_class' do
|
267
|
-
|
268
|
-
|
269
|
-
|
339
|
+
context 'starter' do
|
340
|
+
before do
|
341
|
+
Slack::RealTime::Client.configure do |config|
|
342
|
+
config.store_class = Slack::RealTime::Stores::Starter
|
343
|
+
end
|
344
|
+
end
|
345
|
+
describe '#initialize' do
|
346
|
+
it 'can be overriden explicitly' do
|
347
|
+
client = Slack::RealTime::Client.new(store_class: Slack::RealTime::Store)
|
348
|
+
expect(client.send(:store_class)).to eq Slack::RealTime::Store
|
349
|
+
end
|
350
|
+
it 'sets store_class' do
|
351
|
+
expect(client.send(:store_class)).to eq(Slack::RealTime::Stores::Starter)
|
352
|
+
end
|
353
|
+
context 'start!' do
|
354
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
355
|
+
before do
|
356
|
+
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
357
|
+
allow(socket).to receive(:connect!)
|
358
|
+
allow(socket).to receive(:start_sync)
|
359
|
+
end
|
360
|
+
it 'instantiates the correct store class', vcr: { cassette_name: 'web/rtm_connect' } do
|
361
|
+
client.start!
|
362
|
+
expect(client.store).to be_a Slack::RealTime::Stores::Starter
|
363
|
+
end
|
364
|
+
end
|
270
365
|
end
|
271
366
|
end
|
367
|
+
context 'store' do
|
368
|
+
before do
|
369
|
+
Slack::RealTime::Client.configure do |config|
|
370
|
+
config.store_class = Slack::RealTime::Stores::Store
|
371
|
+
end
|
372
|
+
end
|
373
|
+
describe '#initialize' do
|
374
|
+
context 'start!' do
|
375
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
376
|
+
before do
|
377
|
+
allow(Slack::RealTime::Socket).to receive(:new).and_return(socket)
|
378
|
+
allow(socket).to receive(:connect!)
|
379
|
+
allow(socket).to receive(:start_sync)
|
380
|
+
end
|
381
|
+
it 'calls rtm_start and not rtm_connect', vcr: { cassette_name: 'web/rtm_start' } do
|
382
|
+
expect(client.web_client).to receive(:rtm_start).and_call_original
|
383
|
+
client.start!
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
context 'start_method' do
|
272
390
|
describe '#initialize' do
|
273
391
|
it 'can be overriden explicitly' do
|
274
|
-
client = Slack::RealTime::Client.new(
|
275
|
-
expect(client.send(:
|
392
|
+
client = Slack::RealTime::Client.new(start_method: :overriden)
|
393
|
+
expect(client.send(:start_method)).to eq :overriden
|
276
394
|
end
|
277
|
-
|
278
|
-
|
395
|
+
context 'with start_method' do
|
396
|
+
before do
|
397
|
+
Slack::RealTime::Client.configure do |config|
|
398
|
+
config.start_method = :overriden
|
399
|
+
end
|
400
|
+
end
|
401
|
+
it 'sets start_method' do
|
402
|
+
expect(client.send(:start_method)).to eq :overriden
|
403
|
+
end
|
404
|
+
it 'calls the overriden method' do
|
405
|
+
expect(client.web_client).to receive(:overriden).and_raise('overriden')
|
406
|
+
expect do
|
407
|
+
client.start!
|
408
|
+
end.to raise_error RuntimeError, 'overriden'
|
409
|
+
end
|
279
410
|
end
|
280
411
|
context 'start!' do
|
281
412
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
@@ -284,9 +415,9 @@ RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' }
|
|
284
415
|
allow(socket).to receive(:connect!)
|
285
416
|
allow(socket).to receive(:start_sync)
|
286
417
|
end
|
287
|
-
it '
|
418
|
+
it 'defaults to :rtm_connect', vcr: { cassette_name: 'web/rtm_connect' } do
|
419
|
+
expect(client.web_client).to receive(:rtm_connect).and_call_original
|
288
420
|
client.start!
|
289
|
-
expect(client.store).to be_a Slack::RealTime::Stores::Starter
|
290
421
|
end
|
291
422
|
end
|
292
423
|
end
|
@@ -7,20 +7,41 @@ begin
|
|
7
7
|
context 'with url' do
|
8
8
|
let(:url) { 'wss://echo.websocket.org/websocket/xyz' }
|
9
9
|
let(:logger) { ::Logger.new(STDOUT) }
|
10
|
-
|
10
|
+
let(:test_socket) do
|
11
|
+
Class.new(described_class) do
|
12
|
+
def read
|
13
|
+
fail EOFError
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
let(:socket) { test_socket.new(url, ping: 42, logger: logger) }
|
11
18
|
let(:driver) { WebSocket::Driver::Client }
|
12
19
|
let(:ws) { double(driver) }
|
20
|
+
subject { socket }
|
13
21
|
|
14
22
|
describe '#connect!' do
|
15
23
|
pending 'connects'
|
16
24
|
pending 'pings every 30s'
|
17
25
|
end
|
18
26
|
|
19
|
-
|
20
|
-
|
27
|
+
context 'with a driver' do
|
28
|
+
before do
|
21
29
|
socket.instance_variable_set('@driver', ws)
|
22
|
-
|
23
|
-
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#disconnect!' do
|
33
|
+
it 'closes and nils the websocket' do
|
34
|
+
expect(ws).to receive(:close)
|
35
|
+
socket.disconnect!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#run_loop' do
|
40
|
+
it 'runs' do
|
41
|
+
expect(ws).to receive(:emit)
|
42
|
+
expect(ws).to receive(:start)
|
43
|
+
socket.run_loop
|
44
|
+
end
|
24
45
|
end
|
25
46
|
end
|
26
47
|
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
[Slack::RealTime::Stores::Store, Slack::RealTime::Stores::Starter].each do |store_class|
|
4
|
-
RSpec.describe store_class, vcr: { cassette_name: 'web/rtm_start' } do
|
4
|
+
RSpec.describe store_class, vcr: { cassette_name: store_class == Slack::RealTime::Stores::Store ? 'web/rtm_start' : 'web/rtm_connect' } do
|
5
5
|
include_context 'connected client', store_class: store_class
|
6
6
|
|
7
7
|
context 'team' do
|
8
8
|
it 'sets team data on rtm.start' do
|
9
9
|
expect(client.team.name).to eq 'dblock'
|
10
10
|
expect(client.team.domain).to eq 'dblockdotorg'
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
if store_class == Slack::RealTime::Stores::Store
|
12
|
+
expect(client.team.email_domain).to eq 'dblock.org'
|
13
|
+
expect(client.team.prefs.invites_only_admins).to be true
|
14
|
+
expect(client.team.plan).to eq ''
|
15
|
+
end
|
14
16
|
end
|
15
17
|
it 'team_domain_change' do
|
16
18
|
event = Slack::RealTime::Event.new(
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# require 'spec_helper'
|
2
|
+
|
3
|
+
#
|
4
|
+
# to re-record a rtm_connect fixture run with
|
5
|
+
# SLACK_API_TOKEN=... CONCURRENCY=faye-websocket rspec spec/slack/real_time/rtm_connect_spec.rb
|
6
|
+
# edit rtm_connect.yml and remove the token, fix wss:// path (run specs, fix failures)
|
7
|
+
#
|
8
|
+
|
9
|
+
# RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_connect' } do
|
10
|
+
# it 'connects' do
|
11
|
+
# Slack::Web::Client.new.rtm_connect(mpim_aware: true)
|
12
|
+
# end
|
13
|
+
# end
|
@@ -4,7 +4,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Auth do
|
|
4
4
|
let(:client) { Slack::Web::Client.new }
|
5
5
|
context 'without auth', vcr: { cassette_name: 'web/auth_test_error' } do
|
6
6
|
it 'fails with an exception' do
|
7
|
-
expect { client.auth_test }.to raise_error Slack::Web::Api::
|
7
|
+
expect { client.auth_test }.to raise_error Slack::Web::Api::Errors::SlackError, 'not_authed'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
context 'with auth', vcr: { cassette_name: 'web/auth_test_success' } do
|
@@ -13,8 +13,13 @@ RSpec.describe Slack::Web::Api::Endpoints::Auth do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
context '429 error', vcr: { cassette_name: 'web/429_error' } do
|
16
|
-
it 'fails with an exception' do
|
17
|
-
|
16
|
+
it 'fails with an specific exception' do
|
17
|
+
begin
|
18
|
+
client.auth_test
|
19
|
+
rescue Slack::Web::Api::Errors::TooManyRequestsError => e
|
20
|
+
expect(e.message).to eq('Retry after 3600 seconds')
|
21
|
+
expect(e.retry_after).to eq(3600)
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Slack::Web::Api::Errors::SlackError do
|
4
|
+
let(:client) { Slack::Web::Client.new }
|
5
|
+
it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
|
6
|
+
begin
|
7
|
+
client.auth_test
|
8
|
+
fail 'Expected to receive Slack::Web::Api::Errors::SlackError.'
|
9
|
+
rescue Slack::Web::Api::Errors::SlackError => e
|
10
|
+
expect(e.response).to_not be_nil
|
11
|
+
expect(e.response.status).to eq 200
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -25,7 +25,7 @@ RSpec.describe Slack::Web::Api::Mixins::Channels do
|
|
25
25
|
expect(subject.channels_id(channel: '#general')).to eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' })
|
26
26
|
end
|
27
27
|
it 'fails with an exception' do
|
28
|
-
expect { subject.channels_id(channel: '#invalid') }.to raise_error Slack::Web::Api::
|
28
|
+
expect { subject.channels_id(channel: '#invalid') }.to raise_error Slack::Web::Api::Errors::SlackError, 'channel_not_found'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -25,7 +25,7 @@ RSpec.describe Slack::Web::Api::Mixins::Groups do
|
|
25
25
|
expect(subject.groups_id(channel: '#general')).to eq('ok' => true, 'group' => { 'id' => 'CDEADBEEF' })
|
26
26
|
end
|
27
27
|
it 'fails with an exception' do
|
28
|
-
expect { subject.groups_id(channel: '#invalid') }.to raise_error Slack::Web::Api::
|
28
|
+
expect { subject.groups_id(channel: '#invalid') }.to raise_error Slack::Web::Api::Errors::SlackError, 'channel_not_found'
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -26,7 +26,7 @@ RSpec.describe Slack::Web::Api::Mixins::Users do
|
|
26
26
|
expect(subject.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' })
|
27
27
|
end
|
28
28
|
it 'fails with an exception' do
|
29
|
-
expect { subject.users_id(user: '@foo') }.to raise_error Slack::Web::Api::
|
29
|
+
expect { subject.users_id(user: '@foo') }.to raise_error Slack::Web::Api::Errors::SlackError, 'user_not_found'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
context '#users_search' do
|
@@ -1,11 +1,16 @@
|
|
1
1
|
RSpec.shared_context 'connected client' do |opts|
|
2
2
|
let(:client) { Slack::RealTime::Client.new(opts || {}) }
|
3
3
|
let(:ws) { double(Slack::RealTime::Concurrency::Mock::WebSocket) }
|
4
|
-
let(:url)
|
4
|
+
let(:url) do
|
5
|
+
Slack::RealTime.config.store_class == Slack::RealTime::Stores::Store ?
|
6
|
+
'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' :
|
7
|
+
'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid'
|
8
|
+
end
|
5
9
|
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
6
10
|
before do
|
7
11
|
Slack::RealTime.configure do |config|
|
8
12
|
config.concurrency = Slack::RealTime::Concurrency::Mock
|
13
|
+
config.store_class = (opts || {})[:store_class] || Slack::RealTime::Stores::Store
|
9
14
|
end
|
10
15
|
allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30, logger: Slack::Logger.default).and_return(socket)
|
11
16
|
allow(socket).to receive(:start_sync)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -331,6 +331,8 @@ files:
|
|
331
331
|
- lib/slack/web/api/endpoints/users.rb
|
332
332
|
- lib/slack/web/api/endpoints/users_profile.rb
|
333
333
|
- lib/slack/web/api/error.rb
|
334
|
+
- lib/slack/web/api/errors/slack_error.rb
|
335
|
+
- lib/slack/web/api/errors/too_many_requests_error.rb
|
334
336
|
- lib/slack/web/api/mixins.rb
|
335
337
|
- lib/slack/web/api/mixins/channels.id.json
|
336
338
|
- lib/slack/web/api/mixins/channels.id.rb
|
@@ -369,6 +371,7 @@ files:
|
|
369
371
|
- spec/fixtures/slack/web/auth_test_success.yml
|
370
372
|
- spec/fixtures/slack/web/channels_info.yml
|
371
373
|
- spec/fixtures/slack/web/groups_info.yml
|
374
|
+
- spec/fixtures/slack/web/rtm_connect.yml
|
372
375
|
- spec/fixtures/slack/web/rtm_start.yml
|
373
376
|
- spec/fixtures/slack/web/users_info.yml
|
374
377
|
- spec/fixtures/slack/web/users_list.yml
|
@@ -389,6 +392,7 @@ files:
|
|
389
392
|
- spec/slack/real_time/event_handlers/im_spec.rb
|
390
393
|
- spec/slack/real_time/event_handlers/team_spec.rb
|
391
394
|
- spec/slack/real_time/event_handlers/user_spec.rb
|
395
|
+
- spec/slack/real_time/rtm_connect_spec.rb
|
392
396
|
- spec/slack/real_time/rtm_start_spec.rb
|
393
397
|
- spec/slack/real_time/store_spec.rb
|
394
398
|
- spec/slack/slack_spec.rb
|
@@ -419,6 +423,7 @@ files:
|
|
419
423
|
- spec/slack/web/api/endpoints/usergroups_users_spec.rb
|
420
424
|
- spec/slack/web/api/endpoints/users_profile_spec.rb
|
421
425
|
- spec/slack/web/api/error_spec.rb
|
426
|
+
- spec/slack/web/api/errors/slack_error_spec.rb
|
422
427
|
- spec/slack/web/api/mixins/channels_spec.rb
|
423
428
|
- spec/slack/web/api/mixins/groups_spec.rb
|
424
429
|
- spec/slack/web/api/mixins/users_spec.rb
|
@@ -450,7 +455,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
450
455
|
version: 1.3.6
|
451
456
|
requirements: []
|
452
457
|
rubyforge_project:
|
453
|
-
rubygems_version: 2.6.
|
458
|
+
rubygems_version: 2.6.12
|
454
459
|
signing_key:
|
455
460
|
specification_version: 4
|
456
461
|
summary: Slack Web and RealTime API client.
|
@@ -460,6 +465,7 @@ test_files:
|
|
460
465
|
- spec/fixtures/slack/web/auth_test_success.yml
|
461
466
|
- spec/fixtures/slack/web/channels_info.yml
|
462
467
|
- spec/fixtures/slack/web/groups_info.yml
|
468
|
+
- spec/fixtures/slack/web/rtm_connect.yml
|
463
469
|
- spec/fixtures/slack/web/rtm_start.yml
|
464
470
|
- spec/fixtures/slack/web/users_info.yml
|
465
471
|
- spec/fixtures/slack/web/users_list.yml
|
@@ -480,6 +486,7 @@ test_files:
|
|
480
486
|
- spec/slack/real_time/event_handlers/im_spec.rb
|
481
487
|
- spec/slack/real_time/event_handlers/team_spec.rb
|
482
488
|
- spec/slack/real_time/event_handlers/user_spec.rb
|
489
|
+
- spec/slack/real_time/rtm_connect_spec.rb
|
483
490
|
- spec/slack/real_time/rtm_start_spec.rb
|
484
491
|
- spec/slack/real_time/store_spec.rb
|
485
492
|
- spec/slack/slack_spec.rb
|
@@ -510,6 +517,7 @@ test_files:
|
|
510
517
|
- spec/slack/web/api/endpoints/usergroups_users_spec.rb
|
511
518
|
- spec/slack/web/api/endpoints/users_profile_spec.rb
|
512
519
|
- spec/slack/web/api/error_spec.rb
|
520
|
+
- spec/slack/web/api/errors/slack_error_spec.rb
|
513
521
|
- spec/slack/web/api/mixins/channels_spec.rb
|
514
522
|
- spec/slack/web/api/mixins/groups_spec.rb
|
515
523
|
- spec/slack/web/api/mixins/users_spec.rb
|