slack-ruby-client 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59058e21912e23e38cc9fe877b7edbb463b07c5b
4
- data.tar.gz: beb3d5ee788708f684f10430764a7c9c8a70263e
3
+ metadata.gz: f3ede2b9aafcaacd0d2186d80106272f0faa2857
4
+ data.tar.gz: 171278a9d042e8c5ef793bebe7b844152bf0f263
5
5
  SHA512:
6
- metadata.gz: 7df8114e487363c6e5cd5b4ea6a650247ffe4c0062c58b472f2a715888246c1d906658531db405a544ac5952923dade5bb1241a71b4b64a200310e5ac5d0e2a7
7
- data.tar.gz: 1d180b4b25cf3c8cd514e40ebe2bb98bab04d0e0f2588f1ac733f61f97de0f1a3e1115266cec3d1b5bbf64e6ee22ce24b6630c1207956042e6eb72f494360ca0
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|
@@ -4,6 +4,7 @@ module Slack
4
4
  extend self
5
5
 
6
6
  ATTRIBUTES = [
7
+ :token,
7
8
  :websocket_ping,
8
9
  :websocket_proxy
9
10
  ]
@@ -12,6 +13,8 @@ module Slack
12
13
 
13
14
  def reset
14
15
  self.websocket_ping = 30
16
+ self.websocket_proxy = nil
17
+ self.token = nil
15
18
  end
16
19
  end
17
20
 
data/lib/slack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -11,6 +11,7 @@ module Slack
11
11
  Slack::Web::Config::ATTRIBUTES.each do |key|
12
12
  send("#{key}=", options[key] || Slack::Web.config.send(key))
13
13
  end
14
+ @token ||= Slack.config.token
14
15
  end
15
16
 
16
17
  class << self
@@ -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
 
@@ -21,7 +21,7 @@ module Slack
21
21
  private
22
22
 
23
23
  def request(method, path, options)
24
- options = options.merge(token: Slack.config.token)
24
+ options = options.merge(token: token)
25
25
  response = connection.send(method) do |request|
26
26
  case method
27
27
  when :get, :delete
@@ -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 'started' do
11
- describe '#start!' do
12
- let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
13
- before do
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
- context 'properties provided upon connection' do
19
- it 'sets url' do
20
- expect(client.url).to eq url
21
- end
22
- it 'sets team' do
23
- expect(client.team['domain']).to eq 'dblockdotorg'
24
- end
25
- it 'sets self' do
26
- expect(client.self['id']).to eq 'U07518DTL'
27
- end
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 'uses web client to fetch url' do
49
- expect(client.web_client).to be_a Slack::Web::Client
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 'remembers socket' do
52
- expect(client.instance_variable_get('@socket')).to eq socket
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
- it 'cannot be invoked twice' do
55
- expect do
56
- client.start!
57
- end.to raise_error Slack::RealTime::Client::ClientAlreadyStartedError
58
- end
59
- describe '#stop!' do
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
- expect(socket).to receive(:disconnect!)
62
- client.stop!
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.to raise_error Slack::RealTime::Client::ClientNotStartedError
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
- end
71
- describe '#next_id' do
72
- it 'increments' do
73
- previous_id = client.send(:next_id)
74
- expect(client.send(:next_id)).to eq previous_id + 1
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
- end
79
- context 'with defaults' do
80
- describe '#initialize' do
81
- it 'sets ping' do
82
- expect(client.websocket_ping).to eq 30
83
- end
84
- it "doesn't set proxy" do
85
- expect(client.websocket_proxy).to be nil
86
- end
87
- Slack::RealTime::Config::ATTRIBUTES.each do |key|
88
- it "sets #{key}" do
89
- expect(client.send(key)).to eq Slack::RealTime::Config.send(key)
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|
@@ -0,0 +1,10 @@
1
+ RSpec.configure do |config|
2
+ config.before do
3
+ @old_token = Slack::Config.token
4
+ end
5
+ config.after do
6
+ Slack::Config.token = @old_token
7
+ Slack::Web::Config.reset
8
+ Slack::RealTime::Config.reset
9
+ end
10
+ end
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.0
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-07-31 00:00:00.000000000 Z
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