slack-ruby-client-bhe 0.5.4

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.
Files changed (147) hide show
  1. checksums.yaml +17 -0
  2. data/.gitignore +4 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +6 -0
  6. data/.rubocop_todo.yml +78 -0
  7. data/.travis.yml +26 -0
  8. data/CHANGELOG.md +79 -0
  9. data/CONTRIBUTING.md +157 -0
  10. data/Gemfile +5 -0
  11. data/LICENSE.md +22 -0
  12. data/README.md +385 -0
  13. data/RELEASING.md +69 -0
  14. data/Rakefile +19 -0
  15. data/UPGRADING.md +26 -0
  16. data/bin/commands.rb +21 -0
  17. data/bin/commands/api.rb +14 -0
  18. data/bin/commands/auth.rb +12 -0
  19. data/bin/commands/channels.rb +149 -0
  20. data/bin/commands/chat.rb +47 -0
  21. data/bin/commands/dnd.rb +47 -0
  22. data/bin/commands/emoji.rb +12 -0
  23. data/bin/commands/files.rb +72 -0
  24. data/bin/commands/groups.rb +167 -0
  25. data/bin/commands/im.rb +53 -0
  26. data/bin/commands/mpim.rb +53 -0
  27. data/bin/commands/oauth.rb +16 -0
  28. data/bin/commands/pins.rb +37 -0
  29. data/bin/commands/reactions.rb +53 -0
  30. data/bin/commands/rtm.rb +15 -0
  31. data/bin/commands/search.rb +40 -0
  32. data/bin/commands/stars.rb +37 -0
  33. data/bin/commands/team.rb +32 -0
  34. data/bin/commands/usergroups.rb +73 -0
  35. data/bin/commands/users.rb +57 -0
  36. data/bin/slack +50 -0
  37. data/examples/hi_real_time/Gemfile +5 -0
  38. data/examples/hi_real_time/hi.gif +0 -0
  39. data/examples/hi_real_time/hi.rb +32 -0
  40. data/examples/hi_real_time_and_web/Gemfile +5 -0
  41. data/examples/hi_real_time_and_web/hi.gif +0 -0
  42. data/examples/hi_real_time_and_web/hi.rb +24 -0
  43. data/examples/hi_real_time_async/Gemfile +5 -0
  44. data/examples/hi_real_time_async/hi.rb +29 -0
  45. data/examples/hi_web/Gemfile +3 -0
  46. data/examples/hi_web/hi.gif +0 -0
  47. data/examples/hi_web/hi.rb +12 -0
  48. data/examples/new_ticket/Gemfile +3 -0
  49. data/examples/new_ticket/new_ticket.rb +25 -0
  50. data/lib/slack-ruby-client.rb +29 -0
  51. data/lib/slack.rb +1 -0
  52. data/lib/slack/config.rb +21 -0
  53. data/lib/slack/messages/formatting.rb +30 -0
  54. data/lib/slack/real_time/api/message.rb +20 -0
  55. data/lib/slack/real_time/api/message_id.rb +14 -0
  56. data/lib/slack/real_time/api/ping.rb +16 -0
  57. data/lib/slack/real_time/api/typing.rb +17 -0
  58. data/lib/slack/real_time/client.rb +152 -0
  59. data/lib/slack/real_time/concurrency.rb +8 -0
  60. data/lib/slack/real_time/concurrency/celluloid.rb +93 -0
  61. data/lib/slack/real_time/concurrency/eventmachine.rb +39 -0
  62. data/lib/slack/real_time/config.rb +55 -0
  63. data/lib/slack/real_time/socket.rb +81 -0
  64. data/lib/slack/version.rb +3 -0
  65. data/lib/slack/web/api/endpoints.rb +53 -0
  66. data/lib/slack/web/api/endpoints/api.rb +24 -0
  67. data/lib/slack/web/api/endpoints/auth.rb +20 -0
  68. data/lib/slack/web/api/endpoints/channels.rb +220 -0
  69. data/lib/slack/web/api/endpoints/chat.rb +91 -0
  70. data/lib/slack/web/api/endpoints/dnd.rb +64 -0
  71. data/lib/slack/web/api/endpoints/emoji.rb +20 -0
  72. data/lib/slack/web/api/endpoints/files.rb +108 -0
  73. data/lib/slack/web/api/endpoints/groups.rb +247 -0
  74. data/lib/slack/web/api/endpoints/im.rb +85 -0
  75. data/lib/slack/web/api/endpoints/mpim.rb +84 -0
  76. data/lib/slack/web/api/endpoints/oauth.rb +32 -0
  77. data/lib/slack/web/api/endpoints/pins.rb +64 -0
  78. data/lib/slack/web/api/endpoints/presence.rb +23 -0
  79. data/lib/slack/web/api/endpoints/reactions.rb +89 -0
  80. data/lib/slack/web/api/endpoints/rtm.rb +27 -0
  81. data/lib/slack/web/api/endpoints/search.rb +65 -0
  82. data/lib/slack/web/api/endpoints/stars.rb +61 -0
  83. data/lib/slack/web/api/endpoints/team.rb +47 -0
  84. data/lib/slack/web/api/endpoints/usergroups.rb +113 -0
  85. data/lib/slack/web/api/endpoints/users.rb +73 -0
  86. data/lib/slack/web/api/error.rb +14 -0
  87. data/lib/slack/web/api/mixins.rb +3 -0
  88. data/lib/slack/web/api/mixins/channels.id.json +20 -0
  89. data/lib/slack/web/api/mixins/channels.id.rb +26 -0
  90. data/lib/slack/web/api/mixins/groups.id.json +20 -0
  91. data/lib/slack/web/api/mixins/groups.id.rb +26 -0
  92. data/lib/slack/web/api/mixins/users.id.json +20 -0
  93. data/lib/slack/web/api/mixins/users.id.rb +26 -0
  94. data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +13 -0
  95. data/lib/slack/web/api/patches/chat.2.attachments-json.patch +17 -0
  96. data/lib/slack/web/api/schema/group.json +14 -0
  97. data/lib/slack/web/api/schema/method.json +45 -0
  98. data/lib/slack/web/api/tasks/generate.rake +61 -0
  99. data/lib/slack/web/api/templates/command.erb +34 -0
  100. data/lib/slack/web/api/templates/commands.erb +5 -0
  101. data/lib/slack/web/api/templates/endpoints.erb +21 -0
  102. data/lib/slack/web/api/templates/method.erb +49 -0
  103. data/lib/slack/web/client.rb +28 -0
  104. data/lib/slack/web/config.rb +41 -0
  105. data/lib/slack/web/faraday/connection.rb +29 -0
  106. data/lib/slack/web/faraday/request.rb +39 -0
  107. data/lib/slack/web/faraday/response/raise_error.rb +15 -0
  108. data/lib/slack_ruby_client.rb +1 -0
  109. data/screenshots/register-bot.png +0 -0
  110. data/slack-ruby-client.gemspec +31 -0
  111. data/slack.png +0 -0
  112. data/spec/fixtures/slack/web/429_error.yml +83 -0
  113. data/spec/fixtures/slack/web/auth_test_error.yml +48 -0
  114. data/spec/fixtures/slack/web/auth_test_success.yml +57 -0
  115. data/spec/fixtures/slack/web/channels_info.yml +46 -0
  116. data/spec/fixtures/slack/web/groups_info.yml +43 -0
  117. data/spec/fixtures/slack/web/rtm_start.yml +73 -0
  118. data/spec/fixtures/slack/web/users_info.yml +130 -0
  119. data/spec/fixtures/slack/web/users_list.yml +72 -0
  120. data/spec/integration/integration_spec.rb +107 -0
  121. data/spec/slack/config_spec.rb +14 -0
  122. data/spec/slack/messages/formatting_spec.rb +43 -0
  123. data/spec/slack/real_time/api/message_spec.rb +15 -0
  124. data/spec/slack/real_time/api/ping_spec.rb +15 -0
  125. data/spec/slack/real_time/api/typing_spec.rb +15 -0
  126. data/spec/slack/real_time/client_spec.rb +198 -0
  127. data/spec/slack/real_time/concurrency/celluloid_spec.rb +58 -0
  128. data/spec/slack/real_time/concurrency/eventmachine_spec.rb +49 -0
  129. data/spec/slack/slack_spec.rb +58 -0
  130. data/spec/slack/version_spec.rb +7 -0
  131. data/spec/slack/web/api/endpoints/auth_spec.rb +20 -0
  132. data/spec/slack/web/api/endpoints/channels_spec.rb +11 -0
  133. data/spec/slack/web/api/endpoints/chat_spec.rb +33 -0
  134. data/spec/slack/web/api/endpoints/groups_spec.rb +11 -0
  135. data/spec/slack/web/api/endpoints/users_spec.rb +17 -0
  136. data/spec/slack/web/api/error_spec.rb +14 -0
  137. data/spec/slack/web/api/mixins/channels_spec.rb +31 -0
  138. data/spec/slack/web/api/mixins/groups_spec.rb +31 -0
  139. data/spec/slack/web/api/mixins/users_spec.rb +31 -0
  140. data/spec/slack/web/client_spec.rb +134 -0
  141. data/spec/spec_helper.rb +14 -0
  142. data/spec/support/queue_with_timeout.rb +34 -0
  143. data/spec/support/real_time/concurrency/mock.rb +31 -0
  144. data/spec/support/real_time/connected_client.rb +16 -0
  145. data/spec/support/token.rb +10 -0
  146. data/spec/support/vcr.rb +8 -0
  147. metadata +392 -0
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ begin
4
+ RSpec.describe Slack::RealTime::Concurrency::Eventmachine::Socket do
5
+ context 'with url' do
6
+ let(:url) { 'wss://ms174.slack-msgs.com/websocket/xyz' }
7
+ let(:socket) { described_class.new(url, ping: 42) }
8
+ let(:ws) { double(Faye::WebSocket::Client) }
9
+ describe '#initialize' do
10
+ it 'sets url' do
11
+ expect(socket.url).to eq url
12
+ end
13
+ end
14
+ describe '#connect!' do
15
+ before do
16
+ allow(ws).to receive(:on).with(:close)
17
+ end
18
+ it 'connects' do
19
+ allow(Faye::WebSocket::Client).to receive(:new).and_return(ws)
20
+ socket.connect!
21
+ expect(socket.instance_variable_get('@driver')).to eq ws
22
+ end
23
+ it 'pings every 30s' do
24
+ expect(Faye::WebSocket::Client).to receive(:new).with(url, nil, ping: 42).and_return(ws)
25
+ socket.connect!
26
+ end
27
+ end
28
+ describe '#disconnect!' do
29
+ it 'closes and nils the websocket' do
30
+ socket.instance_variable_set('@driver', ws)
31
+ expect(ws).to receive(:close)
32
+ socket.disconnect!
33
+ end
34
+ end
35
+ describe 'send_data' do
36
+ before do
37
+ allow(Faye::WebSocket::Client).to receive(:new).and_return(ws)
38
+ allow(ws).to receive(:on)
39
+ socket.connect!
40
+ end
41
+ it 'sends data' do
42
+ expect(ws).to receive(:send).with('data')
43
+ socket.send_data('data')
44
+ end
45
+ end
46
+ end
47
+ end
48
+ rescue LoadError
49
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slack do
4
+ let(:slack) { File.expand_path(File.join(__FILE__, '../../../bin/slack')) }
5
+ before do
6
+ @token = ENV.delete('SLACK_API_TOKEN')
7
+ end
8
+ after do
9
+ ENV['SLACK_API_TOKEN'] = @token if @token
10
+ end
11
+ describe '#help' do
12
+ it 'displays help' do
13
+ help = `"#{slack}" help`
14
+ expect(help).to include 'slack - Slack client.'
15
+ end
16
+ end
17
+ context 'globals' do
18
+ it 'enables request and response logging with -d' do
19
+ output = `"#{slack}" --vcr-cassette-name=web/auth_test_success --slack-api-token=token -d auth test 2>&1`
20
+ expect(output).to include 'post https://slack.com/api/auth.test'
21
+ expect(output).to include 'Status: 200'
22
+ end
23
+ it 'requires --slack-api-token' do
24
+ err = `"#{slack}" auth test 2>&1`
25
+ expect(err).to start_with 'error: parse error: Set Slack API token via --slack-api-token or SLACK_API_TOKEN.'
26
+ end
27
+ end
28
+ describe '#auth' do
29
+ context 'bad auth' do
30
+ it 'fails with an exception' do
31
+ err = `"#{slack}" --vcr-cassette-name=web/auth_test_error --slack-api-token=token auth test 2>&1`
32
+ expect(err).to eq "error: not_authed\n"
33
+ end
34
+ end
35
+ context 'good auth' do
36
+ it 'succeeds' do
37
+ json = JSON.parse `"#{slack}" --vcr-cassette-name=web/auth_test_success --slack-api-token=token auth test 2>&1`
38
+ expect(json).to eq(
39
+ 'ok' => true,
40
+ 'url' => 'https://rubybot.slack.com/',
41
+ 'team' => 'team_name',
42
+ 'user' => 'user_name',
43
+ 'team_id' => 'TDEADBEEF',
44
+ 'user_id' => 'UBAADFOOD'
45
+ )
46
+ expect(json['ok']).to be true
47
+ end
48
+ end
49
+ end
50
+ describe '#users' do
51
+ it 'list' do
52
+ json = JSON.parse `"#{slack}" --vcr-cassette-name=web/users_list --slack-api-token=token users list --presence=true 2>&1`
53
+ expect(json['ok']).to be true
54
+ expect(json['members'].size).to eq 9
55
+ expect(json['members'].first['presence']).to eq 'away'
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slack do
4
+ it 'has a version' do
5
+ expect(Slack::VERSION).to_not be nil
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Endpoints::Auth do
4
+ let(:client) { Slack::Web::Client.new }
5
+ context 'without auth', vcr: { cassette_name: 'web/auth_test_error' } do
6
+ it 'fails with an exception' do
7
+ expect { client.auth_test }.to raise_error Slack::Web::Api::Error, 'not_authed'
8
+ end
9
+ end
10
+ context 'with auth', vcr: { cassette_name: 'web/auth_test_success' } do
11
+ it 'succeeds' do
12
+ expect { client.auth_test }.to_not raise_error
13
+ end
14
+ end
15
+ context '429 error', vcr: { cassette_name: 'web/429_error' } do
16
+ it 'fails with an exception' do
17
+ expect { client.auth_test }.to raise_error Faraday::ClientError
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Endpoints::Channels do
4
+ let(:client) { Slack::Web::Client.new }
5
+ context 'channels' do
6
+ it 'info', vcr: { cassette_name: 'web/channels_info' } do
7
+ json = client.channels_info(channel: '#general')
8
+ expect(json['channel']['name']).to eq 'general'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Endpoints::Chat do
4
+ let(:client) { Slack::Web::Client.new }
5
+ context 'chat_postMessage' do
6
+ it 'automatically converts attachments into JSON' do
7
+ expect(client).to receive(:post).with(
8
+ 'chat.postMessage',
9
+ channel: 'channel',
10
+ text: 'text',
11
+ attachments: '[]'
12
+ )
13
+ client.chat_postMessage(channel: 'channel', text: 'text', attachments: [])
14
+ end
15
+ context 'text and attachment arguments' do
16
+ it 'requires text or attachments' do
17
+ expect { client.chat_postMessage(channel: 'channel') }.to raise_error ArgumentError, /Required arguments :text or :attachments missing/
18
+ end
19
+ it 'only text' do
20
+ expect(client).to receive(:post).with('chat.postMessage', hash_including(text: 'text'))
21
+ expect { client.chat_postMessage(channel: 'channel', text: 'text') }.to_not raise_error
22
+ end
23
+ it 'only attachments' do
24
+ expect(client).to receive(:post).with('chat.postMessage', hash_including(attachments: '[]'))
25
+ expect { client.chat_postMessage(channel: 'channel', attachments: []) }.to_not raise_error
26
+ end
27
+ it 'both text and attachments' do
28
+ expect(client).to receive(:post).with('chat.postMessage', hash_including(text: 'text', attachments: '[]'))
29
+ expect { client.chat_postMessage(channel: 'channel', text: 'text', attachments: []) }.to_not raise_error
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Endpoints::Groups do
4
+ let(:client) { Slack::Web::Client.new }
5
+ context 'groups' do
6
+ it 'info', vcr: { cassette_name: 'web/groups_info' } do
7
+ json = client.groups_info(channel: '#mpdm-dblock--rubybot--player1-1')
8
+ expect(json['group']['name']).to eq 'mpdm-dblock--rubybot--player1-1'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Endpoints::Users do
4
+ let(:client) { Slack::Web::Client.new }
5
+ context 'users' do
6
+ it 'list', vcr: { cassette_name: 'web/users_list' } do
7
+ json = client.users_list(presence: true)
8
+ expect(json['ok']).to be true
9
+ expect(json['members'].size).to eq 9
10
+ expect(json['members'].first['presence']).to eq 'away'
11
+ end
12
+ it 'info', vcr: { cassette_name: 'web/users_info' } do
13
+ json = client.users_info(user: '@aws')
14
+ expect(json['user']['name']).to eq 'aws'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Error 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::Error.'
9
+ rescue Slack::Web::Api::Error => e
10
+ expect(e.response).to_not be_nil
11
+ expect(e.response.status).to eq 200
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Mixins::Channels do
4
+ let(:klass) do
5
+ Class.new do
6
+ include Slack::Web::Api::Mixins::Channels
7
+ end
8
+ end
9
+ subject do
10
+ klass.new
11
+ end
12
+ before do
13
+ allow(subject).to receive(:channels_list).and_return(
14
+ 'channels' => [{
15
+ 'id' => 'CDEADBEEF',
16
+ 'name' => 'general'
17
+ }]
18
+ )
19
+ end
20
+ context '#channels_id' do
21
+ it 'leaves channels specified by ID alone' do
22
+ expect(subject.channels_id(channel: 'C123456')).to eq('ok' => true, 'channel' => { 'id' => 'C123456' })
23
+ end
24
+ it 'translates a channel that starts with a #' do
25
+ expect(subject.channels_id(channel: '#general')).to eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' })
26
+ end
27
+ it 'fails with an exception' do
28
+ expect { subject.channels_id(channel: '#invalid') }.to raise_error Slack::Web::Api::Error, 'channel_not_found'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Mixins::Groups do
4
+ let(:klass) do
5
+ Class.new do
6
+ include Slack::Web::Api::Mixins::Groups
7
+ end
8
+ end
9
+ subject do
10
+ klass.new
11
+ end
12
+ before do
13
+ allow(subject).to receive(:groups_list).and_return(
14
+ 'groups' => [{
15
+ 'id' => 'CDEADBEEF',
16
+ 'name' => 'general'
17
+ }]
18
+ )
19
+ end
20
+ context '#groups_id' do
21
+ it 'leaves groups specified by ID alone' do
22
+ expect(subject.groups_id(channel: 'C123456')).to eq('ok' => true, 'group' => { 'id' => 'C123456' })
23
+ end
24
+ it 'translates a channel that starts with a #' do
25
+ expect(subject.groups_id(channel: '#general')).to eq('ok' => true, 'group' => { 'id' => 'CDEADBEEF' })
26
+ end
27
+ it 'fails with an exception' do
28
+ expect { subject.groups_id(channel: '#invalid') }.to raise_error Slack::Web::Api::Error, 'channel_not_found'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Api::Mixins::Users do
4
+ let(:klass) do
5
+ Class.new do
6
+ include Slack::Web::Api::Mixins::Users
7
+ end
8
+ end
9
+ subject do
10
+ klass.new
11
+ end
12
+ before do
13
+ allow(subject).to receive(:users_list).and_return(
14
+ 'members' => [{
15
+ 'id' => 'UDEADBEEF',
16
+ 'name' => 'aws'
17
+ }]
18
+ )
19
+ end
20
+ context '#users_id' do
21
+ it 'leaves users specified by ID alone' do
22
+ expect(subject.users_id(user: 'U123456')).to eq('ok' => true, 'user' => { 'id' => 'U123456' })
23
+ end
24
+ it 'translates a user that starts with a #' do
25
+ expect(subject.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' })
26
+ end
27
+ it 'fails with an exception' do
28
+ expect { subject.users_id(user: '@foo') }.to raise_error Slack::Web::Api::Error, 'user_not_found'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,134 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Client do
4
+ before do
5
+ Slack::Config.reset
6
+ end
7
+ context 'with defaults' do
8
+ let(:client) { Slack::Web::Client.new }
9
+ describe '#initialize' do
10
+ it 'sets user-agent' do
11
+ expect(client.user_agent).to eq Slack::Web::Config.user_agent
12
+ expect(client.user_agent).to include Slack::VERSION
13
+ end
14
+ Slack::Web::Config::ATTRIBUTES.each do |key|
15
+ it "sets #{key}" do
16
+ expect(client.send(key)).to eq Slack::Web::Config.send(key)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ context 'with custom settings' do
22
+ describe '#initialize' do
23
+ Slack::Web::Config::ATTRIBUTES.each do |key|
24
+ context key do
25
+ let(:client) { Slack::Web::Client.new(key => 'custom') }
26
+ it "sets #{key}" do
27
+ expect(client.send(key)).to_not eq Slack::Web::Config.send(key)
28
+ expect(client.send(key)).to eq 'custom'
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ context 'global config' do
35
+ after do
36
+ Slack::Web::Client.config.reset
37
+ end
38
+ let(:client) { Slack::Web::Client.new }
39
+ context 'user-agent' do
40
+ before do
41
+ Slack::Web::Client.configure do |config|
42
+ config.user_agent = 'custom/user-agent'
43
+ end
44
+ end
45
+ describe '#initialize' do
46
+ it 'sets user-agent' do
47
+ expect(client.user_agent).to eq 'custom/user-agent'
48
+ end
49
+ it 'creates a connection with the custom user-agent' do
50
+ expect(client.send(:connection).headers).to eq(
51
+ 'Accept' => 'application/json; charset=utf-8',
52
+ 'User-Agent' => 'custom/user-agent'
53
+ )
54
+ end
55
+ end
56
+ end
57
+ context 'token' do
58
+ before do
59
+ Slack.configure do |config|
60
+ config.token = 'global default'
61
+ end
62
+ end
63
+ it 'defaults token to global default' do
64
+ client = Slack::Web::Client.new
65
+ expect(client.token).to eq 'global default'
66
+ end
67
+ context 'with web config' do
68
+ before do
69
+ Slack::Web::Client.configure do |config|
70
+ config.token = 'custom web token'
71
+ end
72
+ end
73
+ it 'overrides token to web config' do
74
+ client = Slack::Web::Client.new
75
+ expect(client.token).to eq 'custom web token'
76
+ end
77
+ it 'overrides token to specific token' do
78
+ client = Slack::Web::Client.new(token: 'local token')
79
+ expect(client.token).to eq 'local token'
80
+ end
81
+ end
82
+ end
83
+ context 'proxy' do
84
+ before do
85
+ Slack::Web::Client.configure do |config|
86
+ config.proxy = 'http://localhost:8080'
87
+ end
88
+ end
89
+ describe '#initialize' do
90
+ it 'sets proxy' do
91
+ expect(client.proxy).to eq 'http://localhost:8080'
92
+ end
93
+ it 'creates a connection with the proxy' do
94
+ expect(client.send(:connection).proxy.uri.to_s).to eq 'http://localhost:8080'
95
+ end
96
+ end
97
+ end
98
+ context 'SSL options' do
99
+ before do
100
+ Slack::Web::Client.configure do |config|
101
+ config.ca_path = '/ca_path'
102
+ config.ca_file = '/ca_file'
103
+ end
104
+ end
105
+ describe '#initialize' do
106
+ it 'sets ca_path and ca_file' do
107
+ expect(client.ca_path).to eq '/ca_path'
108
+ expect(client.ca_file).to eq '/ca_file'
109
+ end
110
+ it 'creates a connection with ssl options' do
111
+ ssl = client.send(:connection).ssl
112
+ expect(ssl.ca_path).to eq '/ca_path'
113
+ expect(ssl.ca_file).to eq '/ca_file'
114
+ end
115
+ end
116
+ end
117
+ context 'logger option' do
118
+ let(:logger) { Logger.new(STDOUT) }
119
+ before do
120
+ Slack::Web::Client.configure do |config|
121
+ config.logger = logger
122
+ end
123
+ end
124
+ describe '#initialize' do
125
+ it 'sets logger' do
126
+ expect(client.logger).to eq logger
127
+ end
128
+ it 'creates a connection with a logger' do
129
+ expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end