slack-ruby-client 0.2.0 → 0.2.1
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/CHANGELOG.md +5 -0
- data/README.md +5 -1
- data/lib/slack/real_time/client.rb +2 -1
- data/lib/slack/real_time/config.rb +3 -0
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/client.rb +1 -0
- data/lib/slack/web/config.rb +4 -1
- data/lib/slack/web/faraday/request.rb +1 -1
- data/spec/slack/real_time/client_spec.rb +98 -67
- data/spec/slack/web/client_spec.rb +26 -0
- data/spec/support/token.rb +10 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3ede2b9aafcaacd0d2186d80106272f0faa2857
|
4
|
+
data.tar.gz: 171278a9d042e8c5ef793bebe7b844152bf0f263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f6e90d7c8a2242f2ccb912824f9de373f5a0100cac4f9caf543e62b2029fee95ced93948422a3bd8c44e15f455e96ae650606697e1962784748346c03ad840c
|
7
|
+
data.tar.gz: 8c3506854646e6608207a00fdc9968087378b7e090ec14f7dee0c450368c051dd358c32b66c079c52f6be57149982490f877714537b65ee490fc3ca83fcfa5fa
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.2.1 (8/2/2015)
|
2
|
+
|
3
|
+
* Set Slack API token via `Slack::RealTime::Client.new(token: 'token')` and `Slack::Web::Client.new(token: 'token')` - [@dblock](https://github.com/dblock).
|
4
|
+
* Set Slack API token via `Slack::RealTime::Client.configure` and `Slack::Web::Client.configure` - [@dblock](https://github.com/dblock).
|
5
|
+
|
1
6
|
### 0.2.0 (7/31/2015)
|
2
7
|
|
3
8
|
* [#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).
|
data/README.md
CHANGED
@@ -32,6 +32,8 @@ Slack.configure do |config|
|
|
32
32
|
end
|
33
33
|
```
|
34
34
|
|
35
|
+
This sets a global default token. You can also pass a token into the initializer of both `Slack::Web::Client` and `Slack::RealTime::Client` or configure those separately via `Slack::Web::Config.configure` and `Slack::RealTime::Config.configure`. The instance token will be used over the client type token over the global default.
|
36
|
+
|
35
37
|
### Web Client
|
36
38
|
|
37
39
|
The Slack Web API allows you to build applications that interact with Slack. For example, send messages with [chat_PostMessage](https://api.slack.com/methods/chat.postMessage).
|
@@ -68,6 +70,7 @@ The following settings are supported.
|
|
68
70
|
|
69
71
|
setting | description
|
70
72
|
-------------|-------------------------------------------------------------------------------------------------
|
73
|
+
token | Slack API token.
|
71
74
|
user_agent | User-agent, defaults to _Slack Ruby Client/version_.
|
72
75
|
proxy | Optional HTTP proxy.
|
73
76
|
ca_path | Optional SSL certificates path.
|
@@ -138,6 +141,7 @@ The following settings are supported.
|
|
138
141
|
|
139
142
|
setting | description
|
140
143
|
----------------|-----------------------------------------------------------------------------------------------------
|
144
|
+
token | Slack API token.
|
141
145
|
websocket_ping | The number of seconds that indicates how often the WebSocket should send ping frames, default is 30.
|
142
146
|
websocket_proxy | Connect via proxy, include `:origin` and `:headers`.
|
143
147
|
|
@@ -180,6 +184,6 @@ See [CONTRIBUTING](CONTRIBUTING.md).
|
|
180
184
|
|
181
185
|
## Copyright and License
|
182
186
|
|
183
|
-
Copyright (c) 2015, Daniel Doubrovkine, Artsy and [Contributors](CHANGELOG.md).
|
187
|
+
Copyright (c) 2015, [Daniel Doubrovkine](https://twitter.com/dblockdotorg), [Artsy](https://www.artsy.net) and [Contributors](CHANGELOG.md).
|
184
188
|
|
185
189
|
This project is licensed under the [MIT License](LICENSE.md).
|
@@ -14,10 +14,11 @@ module Slack
|
|
14
14
|
|
15
15
|
def initialize(options = {})
|
16
16
|
@callbacks = {}
|
17
|
-
@web_client = Slack::Web::Client.new
|
18
17
|
Slack::RealTime::Config::ATTRIBUTES.each do |key|
|
19
18
|
send("#{key}=", options[key] || Slack::RealTime.config.send(key))
|
20
19
|
end
|
20
|
+
@token ||= Slack.config.token
|
21
|
+
@web_client = Slack::Web::Client.new(token: token)
|
21
22
|
end
|
22
23
|
|
23
24
|
[:url, :team, :self, :users, :channels, :groups, :ims, :bots].each do |attr|
|
data/lib/slack/version.rb
CHANGED
data/lib/slack/web/client.rb
CHANGED
data/lib/slack/web/config.rb
CHANGED
@@ -8,7 +8,8 @@ module Slack
|
|
8
8
|
:user_agent,
|
9
9
|
:ca_path,
|
10
10
|
:ca_file,
|
11
|
-
:endpoint
|
11
|
+
:endpoint,
|
12
|
+
:token
|
12
13
|
]
|
13
14
|
|
14
15
|
attr_accessor(*Config::ATTRIBUTES)
|
@@ -18,6 +19,8 @@ module Slack
|
|
18
19
|
self.user_agent = "Slack Ruby Client/#{Slack::VERSION}"
|
19
20
|
self.ca_path = `openssl version -a | grep OPENSSLDIR | awk '{print $2}'|sed -e 's/\"//g'`
|
20
21
|
self.ca_file = "#{ca_path}/ca-certificates.crt"
|
22
|
+
self.token = nil
|
23
|
+
self.proxy = nil
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
@@ -1,92 +1,123 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe Slack::RealTime::Client, vcr: { cassette_name: 'web/rtm_start' } do
|
4
|
-
let(:client) { Slack::RealTime::Client.new }
|
5
4
|
let(:ws) { double(Faye::WebSocket::Client, on: true) }
|
6
5
|
let(:url) { 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid=' }
|
7
6
|
before do
|
8
7
|
allow(EM).to receive(:run).and_yield
|
9
8
|
end
|
10
|
-
context '
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30).and_return(socket)
|
15
|
-
allow(socket).to receive(:connect!).and_yield(ws)
|
16
|
-
client.start!
|
9
|
+
context 'token' do
|
10
|
+
before do
|
11
|
+
Slack.configure do |config|
|
12
|
+
config.token = 'global default'
|
17
13
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
it 'sets users' do
|
29
|
-
expect(client.users.count).to eq 7
|
30
|
-
expect(client.users.first['id']).to eq 'U07KECJ77'
|
31
|
-
end
|
32
|
-
it 'sets channels' do
|
33
|
-
expect(client.channels.count).to eq 8
|
34
|
-
expect(client.channels.first['name']).to eq 'demo'
|
35
|
-
end
|
36
|
-
it 'sets ims' do
|
37
|
-
expect(client.ims.count).to eq 2
|
38
|
-
expect(client.ims.first['user']).to eq 'USLACKBOT'
|
39
|
-
end
|
40
|
-
it 'sets bots' do
|
41
|
-
expect(client.bots.count).to eq 5
|
42
|
-
expect(client.bots.first['name']).to eq 'bot'
|
43
|
-
end
|
44
|
-
it 'sets groups' do
|
45
|
-
expect(client.groups.count).to eq 0
|
14
|
+
end
|
15
|
+
it 'defaults token to global default' do
|
16
|
+
client = Slack::RealTime::Client.new
|
17
|
+
expect(client.token).to eq 'global default'
|
18
|
+
expect(client.web_client.token).to eq 'global default'
|
19
|
+
end
|
20
|
+
context 'with real time config' do
|
21
|
+
before do
|
22
|
+
Slack::RealTime::Client.configure do |config|
|
23
|
+
config.token = 'custom real time token'
|
46
24
|
end
|
47
25
|
end
|
48
|
-
it '
|
49
|
-
|
26
|
+
it 'overrides token to real time config' do
|
27
|
+
client = Slack::RealTime::Client.new
|
28
|
+
expect(client.token).to eq 'custom real time token'
|
29
|
+
expect(client.web_client.token).to eq 'custom real time token'
|
50
30
|
end
|
51
|
-
it '
|
52
|
-
|
31
|
+
it 'overrides token to specific token' do
|
32
|
+
client = Slack::RealTime::Client.new(token: 'local token')
|
33
|
+
expect(client.token).to eq 'local token'
|
34
|
+
expect(client.web_client.token).to eq 'local token'
|
53
35
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
describe '#
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context 'client' do
|
39
|
+
let(:client) { Slack::RealTime::Client.new }
|
40
|
+
context 'started' do
|
41
|
+
describe '#start!' do
|
42
|
+
let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
|
60
43
|
before do
|
61
|
-
|
62
|
-
|
44
|
+
allow(Slack::RealTime::Socket).to receive(:new).with(url, ping: 30).and_return(socket)
|
45
|
+
allow(socket).to receive(:connect!).and_yield(ws)
|
46
|
+
client.start!
|
47
|
+
end
|
48
|
+
context 'properties provided upon connection' do
|
49
|
+
it 'sets url' do
|
50
|
+
expect(client.url).to eq url
|
51
|
+
end
|
52
|
+
it 'sets team' do
|
53
|
+
expect(client.team['domain']).to eq 'dblockdotorg'
|
54
|
+
end
|
55
|
+
it 'sets self' do
|
56
|
+
expect(client.self['id']).to eq 'U07518DTL'
|
57
|
+
end
|
58
|
+
it 'sets users' do
|
59
|
+
expect(client.users.count).to eq 7
|
60
|
+
expect(client.users.first['id']).to eq 'U07KECJ77'
|
61
|
+
end
|
62
|
+
it 'sets channels' do
|
63
|
+
expect(client.channels.count).to eq 8
|
64
|
+
expect(client.channels.first['name']).to eq 'demo'
|
65
|
+
end
|
66
|
+
it 'sets ims' do
|
67
|
+
expect(client.ims.count).to eq 2
|
68
|
+
expect(client.ims.first['user']).to eq 'USLACKBOT'
|
69
|
+
end
|
70
|
+
it 'sets bots' do
|
71
|
+
expect(client.bots.count).to eq 5
|
72
|
+
expect(client.bots.first['name']).to eq 'bot'
|
73
|
+
end
|
74
|
+
it 'sets groups' do
|
75
|
+
expect(client.groups.count).to eq 0
|
76
|
+
end
|
77
|
+
end
|
78
|
+
it 'uses web client to fetch url' do
|
79
|
+
expect(client.web_client).to be_a Slack::Web::Client
|
80
|
+
end
|
81
|
+
it 'remembers socket' do
|
82
|
+
expect(client.instance_variable_get('@socket')).to eq socket
|
63
83
|
end
|
64
84
|
it 'cannot be invoked twice' do
|
65
|
-
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
66
85
|
expect do
|
86
|
+
client.start!
|
87
|
+
end.to raise_error Slack::RealTime::Client::ClientAlreadyStartedError
|
88
|
+
end
|
89
|
+
describe '#stop!' do
|
90
|
+
before do
|
91
|
+
expect(socket).to receive(:disconnect!)
|
67
92
|
client.stop!
|
68
|
-
end
|
93
|
+
end
|
94
|
+
it 'cannot be invoked twice' do
|
95
|
+
client.instance_variable_set('@socket', nil) # caused by a :close callback
|
96
|
+
expect do
|
97
|
+
client.stop!
|
98
|
+
end.to raise_error Slack::RealTime::Client::ClientNotStartedError
|
99
|
+
end
|
69
100
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
101
|
+
describe '#next_id' do
|
102
|
+
it 'increments' do
|
103
|
+
previous_id = client.send(:next_id)
|
104
|
+
expect(client.send(:next_id)).to eq previous_id + 1
|
105
|
+
end
|
75
106
|
end
|
76
107
|
end
|
77
108
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
109
|
+
context 'with defaults' do
|
110
|
+
describe '#initialize' do
|
111
|
+
it 'sets ping' do
|
112
|
+
expect(client.websocket_ping).to eq 30
|
113
|
+
end
|
114
|
+
it "doesn't set proxy" do
|
115
|
+
expect(client.websocket_proxy).to be nil
|
116
|
+
end
|
117
|
+
Slack::RealTime::Config::ATTRIBUTES.each do |key|
|
118
|
+
it "sets #{key}" do
|
119
|
+
expect(client.send(key)).to eq Slack::RealTime::Config.send(key)
|
120
|
+
end
|
90
121
|
end
|
91
122
|
end
|
92
123
|
end
|
@@ -51,6 +51,32 @@ RSpec.describe Slack::Web::Client do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
|
+
context 'token' do
|
55
|
+
before do
|
56
|
+
Slack.configure do |config|
|
57
|
+
config.token = 'global default'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
it 'defaults token to global default' do
|
61
|
+
client = Slack::Web::Client.new
|
62
|
+
expect(client.token).to eq 'global default'
|
63
|
+
end
|
64
|
+
context 'with web config' do
|
65
|
+
before do
|
66
|
+
Slack::Web::Client.configure do |config|
|
67
|
+
config.token = 'custom web token'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
it 'overrides token to web config' do
|
71
|
+
client = Slack::Web::Client.new
|
72
|
+
expect(client.token).to eq 'custom web token'
|
73
|
+
end
|
74
|
+
it 'overrides token to specific token' do
|
75
|
+
client = Slack::Web::Client.new(token: 'local token')
|
76
|
+
expect(client.token).to eq 'local token'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
54
80
|
context 'proxy' do
|
55
81
|
before do
|
56
82
|
Slack::Web::Client.configure do |config|
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- spec/slack/web/client_spec.rb
|
246
246
|
- spec/spec_helper.rb
|
247
247
|
- spec/support/real_time/connected_client.rb
|
248
|
+
- spec/support/token.rb
|
248
249
|
- spec/support/vcr.rb
|
249
250
|
homepage: http://github.com/dblock/slack-ruby-client
|
250
251
|
licenses:
|
@@ -285,4 +286,5 @@ test_files:
|
|
285
286
|
- spec/slack/web/client_spec.rb
|
286
287
|
- spec/spec_helper.rb
|
287
288
|
- spec/support/real_time/connected_client.rb
|
289
|
+
- spec/support/token.rb
|
288
290
|
- spec/support/vcr.rb
|