slack-ruby-client 0.14.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (274) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.rubocop.yml +15 -3
  4. data/.rubocop_todo.yml +110 -38
  5. data/.travis.yml +2 -5
  6. data/CHANGELOG.md +42 -0
  7. data/CONTRIBUTING.md +19 -8
  8. data/Dangerfile +1 -1
  9. data/Gemfile +1 -2
  10. data/LICENSE.md +1 -1
  11. data/README.md +38 -36
  12. data/RELEASING.md +1 -1
  13. data/UPGRADING.md +62 -2
  14. data/bin/commands/admin_analytics.rb +16 -0
  15. data/bin/commands/admin_apps.rb +26 -2
  16. data/bin/commands/admin_apps_requests.rb +1 -0
  17. data/bin/commands/admin_auth_policy.rb +39 -0
  18. data/bin/commands/admin_barriers.rb +47 -0
  19. data/bin/commands/admin_conversations.rb +155 -3
  20. data/bin/commands/admin_conversations_ekm.rb +17 -0
  21. data/bin/commands/admin_conversations_restrictAccess.rb +37 -0
  22. data/bin/commands/admin_conversations_whitelist.rb +37 -0
  23. data/bin/commands/admin_emoji.rb +1 -1
  24. data/bin/commands/admin_teams.rb +1 -1
  25. data/bin/commands/admin_usergroups.rb +48 -0
  26. data/bin/commands/admin_users.rb +3 -2
  27. data/bin/commands/admin_users_session.rb +62 -0
  28. data/bin/commands/api.rb +0 -1
  29. data/bin/commands/apps_connections.rb +13 -0
  30. data/bin/commands/apps_event_authorizations.rb +16 -0
  31. data/bin/commands/apps_manifest.rb +51 -0
  32. data/bin/commands/auth_teams.rb +16 -0
  33. data/bin/commands/bots.rb +1 -0
  34. data/bin/commands/calls.rb +52 -0
  35. data/bin/commands/calls_participants.rb +25 -0
  36. data/bin/commands/channels.rb +1 -155
  37. data/bin/commands/chat.rb +17 -12
  38. data/bin/commands/chat_scheduledMessages.rb +1 -0
  39. data/bin/commands/conversations.rb +71 -3
  40. data/bin/commands/dnd.rb +2 -0
  41. data/bin/commands/files.rb +6 -4
  42. data/bin/commands/files_remote.rb +2 -2
  43. data/bin/commands/groups.rb +1 -162
  44. data/bin/commands/im.rb +1 -63
  45. data/bin/commands/migration.rb +1 -0
  46. data/bin/commands/mpim.rb +1 -61
  47. data/bin/commands/oauth.rb +0 -13
  48. data/bin/commands/oauth_v2.rb +13 -1
  49. data/bin/commands/openid_connect.rb +27 -0
  50. data/bin/commands/pins.rb +2 -4
  51. data/bin/commands/reactions.rb +1 -0
  52. data/bin/commands/reminders.rb +6 -0
  53. data/bin/commands/rtm.rb +2 -2
  54. data/bin/commands/search.rb +4 -0
  55. data/bin/commands/stars.rb +7 -6
  56. data/bin/commands/team.rb +3 -0
  57. data/bin/commands/team_billing.rb +13 -0
  58. data/bin/commands/team_preferences.rb +13 -0
  59. data/bin/commands/tooling_tokens.rb +14 -0
  60. data/bin/commands/usergroups.rb +5 -0
  61. data/bin/commands/usergroups_users.rb +2 -0
  62. data/bin/commands/users.rb +4 -2
  63. data/bin/commands/users_profile.rb +5 -5
  64. data/bin/commands/views.rb +2 -2
  65. data/bin/commands/workflows.rb +38 -0
  66. data/bin/commands.rb +17 -8
  67. data/lib/slack/config.rb +1 -2
  68. data/lib/slack/events/request.rb +10 -4
  69. data/lib/slack/messages/message.rb +0 -4
  70. data/lib/slack/real_time/client.rb +6 -6
  71. data/lib/slack/real_time/concurrency/async.rb +7 -11
  72. data/lib/slack/real_time/concurrency.rb +0 -2
  73. data/lib/slack/real_time/config.rb +5 -14
  74. data/lib/slack/real_time/models/base.rb +0 -4
  75. data/lib/slack/real_time/socket.rb +3 -4
  76. data/lib/slack/real_time/stores/base.rb +4 -7
  77. data/lib/slack/real_time/stores/starter.rb +6 -3
  78. data/lib/slack/real_time/stores/store.rb +5 -0
  79. data/lib/slack/version.rb +1 -1
  80. data/lib/slack/web/api/endpoints/admin_analytics.rb +28 -0
  81. data/lib/slack/web/api/endpoints/admin_apps.rb +42 -6
  82. data/lib/slack/web/api/endpoints/admin_apps_approved.rb +2 -2
  83. data/lib/slack/web/api/endpoints/admin_apps_requests.rb +4 -2
  84. data/lib/slack/web/api/endpoints/admin_apps_restricted.rb +2 -2
  85. data/lib/slack/web/api/endpoints/admin_auth_policy.rb +72 -0
  86. data/lib/slack/web/api/endpoints/admin_barriers.rb +82 -0
  87. data/lib/slack/web/api/endpoints/admin_conversations.rb +234 -4
  88. data/lib/slack/web/api/endpoints/admin_conversations_ekm.rb +35 -0
  89. data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +61 -0
  90. data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +64 -0
  91. data/lib/slack/web/api/endpoints/admin_emoji.rb +10 -10
  92. data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +7 -7
  93. data/lib/slack/web/api/endpoints/admin_inviteRequests_approved.rb +3 -3
  94. data/lib/slack/web/api/endpoints/admin_inviteRequests_denied.rb +2 -2
  95. data/lib/slack/web/api/endpoints/admin_teams.rb +7 -7
  96. data/lib/slack/web/api/endpoints/admin_teams_admins.rb +2 -2
  97. data/lib/slack/web/api/endpoints/admin_teams_owners.rb +2 -2
  98. data/lib/slack/web/api/endpoints/admin_teams_settings.rb +5 -5
  99. data/lib/slack/web/api/endpoints/admin_usergroups.rb +77 -0
  100. data/lib/slack/web/api/endpoints/admin_users.rb +23 -23
  101. data/lib/slack/web/api/endpoints/admin_users_session.rb +97 -3
  102. data/lib/slack/web/api/endpoints/api.rb +1 -3
  103. data/lib/slack/web/api/endpoints/apps.rb +2 -2
  104. data/lib/slack/web/api/endpoints/apps_connections.rb +21 -0
  105. data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +34 -0
  106. data/lib/slack/web/api/endpoints/apps_manifest.rb +75 -0
  107. data/lib/slack/web/api/endpoints/auth.rb +1 -1
  108. data/lib/slack/web/api/endpoints/auth_teams.rb +33 -0
  109. data/lib/slack/web/api/endpoints/bots.rb +3 -1
  110. data/lib/slack/web/api/endpoints/calls.rb +83 -0
  111. data/lib/slack/web/api/endpoints/calls_participants.rb +42 -0
  112. data/lib/slack/web/api/endpoints/channels.rb +1 -245
  113. data/lib/slack/web/api/endpoints/chat.rb +76 -66
  114. data/lib/slack/web/api/endpoints/chat_scheduledMessages.rb +5 -3
  115. data/lib/slack/web/api/endpoints/conversations.rb +149 -41
  116. data/lib/slack/web/api/endpoints/dialog.rb +2 -2
  117. data/lib/slack/web/api/endpoints/dnd.rb +6 -3
  118. data/lib/slack/web/api/endpoints/files.rb +21 -17
  119. data/lib/slack/web/api/endpoints/files_comments.rb +1 -1
  120. data/lib/slack/web/api/endpoints/files_remote.rb +23 -23
  121. data/lib/slack/web/api/endpoints/groups.rb +0 -253
  122. data/lib/slack/web/api/endpoints/im.rb +0 -101
  123. data/lib/slack/web/api/endpoints/migration.rb +4 -2
  124. data/lib/slack/web/api/endpoints/mpim.rb +0 -96
  125. data/lib/slack/web/api/endpoints/oauth.rb +5 -30
  126. data/lib/slack/web/api/endpoints/oauth_v2.rb +24 -6
  127. data/lib/slack/web/api/endpoints/openid_connect.rb +42 -0
  128. data/lib/slack/web/api/endpoints/pins.rb +7 -12
  129. data/lib/slack/web/api/endpoints/reactions.rb +16 -14
  130. data/lib/slack/web/api/endpoints/reminders.rb +17 -5
  131. data/lib/slack/web/api/endpoints/rtm.rb +10 -10
  132. data/lib/slack/web/api/endpoints/search.rb +27 -13
  133. data/lib/slack/web/api/endpoints/stars.rb +13 -11
  134. data/lib/slack/web/api/endpoints/team.rb +11 -5
  135. data/lib/slack/web/api/endpoints/team_billing.rb +21 -0
  136. data/lib/slack/web/api/endpoints/team_preferences.rb +21 -0
  137. data/lib/slack/web/api/endpoints/team_profile.rb +1 -1
  138. data/lib/slack/web/api/endpoints/tooling_tokens.rb +24 -0
  139. data/lib/slack/web/api/endpoints/usergroups.rb +26 -16
  140. data/lib/slack/web/api/endpoints/usergroups_users.rb +9 -5
  141. data/lib/slack/web/api/endpoints/users.rb +20 -18
  142. data/lib/slack/web/api/endpoints/users_profile.rb +7 -7
  143. data/lib/slack/web/api/endpoints/views.rb +13 -13
  144. data/lib/slack/web/api/endpoints/workflows.rb +61 -0
  145. data/lib/slack/web/api/endpoints.rb +35 -18
  146. data/lib/slack/web/api/errors/server_error.rb +37 -0
  147. data/lib/slack/web/api/errors/too_many_requests_error.rb +1 -4
  148. data/lib/slack/web/api/errors.rb +486 -12
  149. data/lib/slack/web/api/mixins/{channels.id.rb → conversations.id.rb} +3 -5
  150. data/lib/slack/web/api/mixins/ids.id.rb +3 -5
  151. data/lib/slack/web/api/mixins/users.id.rb +1 -3
  152. data/lib/slack/web/api/mixins.rb +1 -2
  153. data/lib/slack/web/api/patches/{chat.6.block-kit-support.patch → chat.1.patch} +25 -24
  154. data/lib/slack/web/api/templates/endpoints.erb +1 -2
  155. data/lib/slack/web/api/templates/method.erb +4 -1
  156. data/lib/slack/web/api/templates/method_spec.erb +1 -1
  157. data/lib/slack/web/config.rb +2 -0
  158. data/lib/slack/web/faraday/connection.rb +23 -20
  159. data/lib/slack/web/faraday/request.rb +2 -1
  160. data/lib/slack/web/faraday/response/raise_error.rb +12 -1
  161. data/lib/slack/web/faraday/response/wrap_error.rb +24 -0
  162. data/lib/slack/web/pagination/cursor.rb +3 -7
  163. data/lib/slack-ruby-client.rb +4 -4
  164. data/lib/tasks/web.rake +11 -3
  165. data/slack-ruby-client.gemspec +6 -7
  166. data/spec/fixtures/slack/web/429_error.yml +50 -54
  167. data/spec/fixtures/slack/web/auth_test_error.yml +51 -18
  168. data/spec/fixtures/slack/web/auth_test_success.yml +50 -26
  169. data/spec/fixtures/slack/web/conversations_info.yml +167 -0
  170. data/spec/fixtures/slack/web/conversations_setTopic.yml +84 -0
  171. data/spec/fixtures/slack/web/conversations_setTopic_one_page.yml +172 -0
  172. data/spec/fixtures/slack/web/conversations_setTopic_paginated.yml +253 -0
  173. data/spec/fixtures/slack/web/paginated_users_list.yml +501 -69
  174. data/spec/fixtures/slack/web/rtm_connect.yml +267 -30
  175. data/spec/fixtures/slack/web/rtm_start.yml +771 -60
  176. data/spec/fixtures/slack/web/users_info.yml +153 -69
  177. data/spec/fixtures/slack/web/users_list.yml +102 -41
  178. data/spec/fixtures/slack/web/views_open_error.yml +49 -42
  179. data/spec/slack/events/request_spec.rb +13 -8
  180. data/spec/slack/real_time/client_spec.rb +35 -22
  181. data/spec/slack/real_time/concurrency/with_concurrency_spec.rb +10 -0
  182. data/spec/slack/real_time/concurrency/without_concurrency_spec.rb +10 -0
  183. data/spec/slack/real_time/event_handlers/bot_spec.rb +1 -1
  184. data/spec/slack/real_time/event_handlers/channel_spec.rb +1 -1
  185. data/spec/slack/real_time/event_handlers/im_spec.rb +5 -5
  186. data/spec/slack/real_time/event_handlers/user_spec.rb +2 -2
  187. data/spec/slack/real_time/rtm_connect_spec.rb +1 -1
  188. data/spec/slack/real_time/rtm_start_spec.rb +1 -1
  189. data/spec/slack/slack_spec.rb +3 -1
  190. data/spec/slack/web/api/endpoints/admin_analytics_spec.rb +13 -0
  191. data/spec/slack/web/api/endpoints/admin_apps_spec.rb +10 -0
  192. data/spec/slack/web/api/endpoints/admin_auth_policy_spec.rb +35 -0
  193. data/spec/slack/web/api/endpoints/admin_barriers_spec.rb +38 -0
  194. data/spec/slack/web/api/endpoints/{apps_permissions_scopes_spec.rb → admin_conversations_ekm_spec.rb} +1 -1
  195. data/spec/slack/web/api/endpoints/admin_conversations_restrictAccess_spec.rb +32 -0
  196. data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +85 -0
  197. data/spec/slack/web/api/endpoints/admin_emoji_spec.rb +6 -6
  198. data/spec/slack/web/api/endpoints/admin_teams_settings_spec.rb +10 -10
  199. data/spec/slack/web/api/endpoints/admin_teams_spec.rb +2 -2
  200. data/spec/slack/web/api/endpoints/admin_usergroups_spec.rb +37 -0
  201. data/spec/slack/web/api/endpoints/admin_users_session_spec.rb +28 -0
  202. data/spec/slack/web/api/endpoints/admin_users_spec.rb +15 -23
  203. data/spec/slack/web/api/endpoints/{apps_permissions_resources_spec.rb → apps_connections_spec.rb} +1 -1
  204. data/spec/slack/web/api/endpoints/apps_event_authorizations_spec.rb +13 -0
  205. data/spec/slack/web/api/endpoints/apps_manifest_spec.rb +36 -0
  206. data/spec/slack/web/api/endpoints/apps_spec.rb +2 -2
  207. data/spec/slack/web/api/endpoints/auth_teams_spec.rb +8 -0
  208. data/spec/slack/web/api/endpoints/calls_participants_spec.rb +24 -0
  209. data/spec/slack/web/api/endpoints/calls_spec.rb +31 -0
  210. data/spec/slack/web/api/endpoints/custom_specs/auth_spec.rb +4 -6
  211. data/spec/slack/web/api/endpoints/custom_specs/conversations_spec.rb +13 -0
  212. data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +2 -2
  213. data/spec/slack/web/api/endpoints/dnd_spec.rb +0 -5
  214. data/spec/slack/web/api/endpoints/files_comments_spec.rb +2 -2
  215. data/spec/slack/web/api/endpoints/files_remote_spec.rb +3 -3
  216. data/spec/slack/web/api/endpoints/files_spec.rb +4 -4
  217. data/spec/slack/web/api/endpoints/oauth_spec.rb +0 -22
  218. data/spec/slack/web/api/endpoints/oauth_v2_spec.rb +6 -3
  219. data/spec/slack/web/api/endpoints/openid_connect_spec.rb +8 -0
  220. data/spec/slack/web/api/endpoints/pins_spec.rb +1 -4
  221. data/spec/slack/web/api/endpoints/reactions_spec.rb +3 -3
  222. data/spec/slack/web/api/endpoints/reminders_spec.rb +2 -2
  223. data/spec/slack/web/api/endpoints/team_billing_spec.rb +8 -0
  224. data/spec/slack/web/api/endpoints/team_preferences_spec.rb +8 -0
  225. data/spec/slack/web/api/endpoints/tooling_tokens_spec.rb +13 -0
  226. data/spec/slack/web/api/endpoints/usergroups_users_spec.rb +2 -2
  227. data/spec/slack/web/api/endpoints/workflows_spec.rb +26 -0
  228. data/spec/slack/web/api/error_spec.rb +5 -7
  229. data/spec/slack/web/api/errors/slack_error_spec.rb +21 -26
  230. data/spec/slack/web/api/mixins/conversations_list_spec.rb +21 -0
  231. data/spec/slack/web/api/mixins/{channels_spec.rb → conversations_spec.rb} +8 -8
  232. data/spec/slack/web/api/mixins/users_spec.rb +1 -1
  233. data/spec/slack/web/api/pagination/cursor_spec.rb +1 -3
  234. data/spec/slack/web/client_spec.rb +123 -1
  235. data/spec/slack/web/faraday/request_spec.rb +80 -0
  236. data/spec/slack/web/faraday/response/raise_error_spec.rb +8 -6
  237. data/spec/spec_helper.rb +1 -1
  238. data/spec/support/real_time/connected_client.rb +1 -7
  239. data/spec/support/vcr.rb +36 -1
  240. metadata +95 -173
  241. data/examples/hi_real_time/Gemfile +0 -6
  242. data/examples/hi_real_time/hi.gif +0 -0
  243. data/examples/hi_real_time/hi.rb +0 -41
  244. data/examples/hi_real_time_async_celluloid/Gemfile +0 -7
  245. data/examples/hi_real_time_async_celluloid/Procfile +0 -2
  246. data/examples/hi_real_time_async_celluloid/hi.rb +0 -39
  247. data/examples/hi_real_time_async_eventmachine/Gemfile +0 -7
  248. data/examples/hi_real_time_async_eventmachine/Procfile +0 -2
  249. data/examples/hi_real_time_async_eventmachine/hi.rb +0 -39
  250. data/lib/slack/real_time/concurrency/celluloid.rb +0 -142
  251. data/lib/slack/real_time/concurrency/eventmachine.rb +0 -85
  252. data/lib/slack/web/api/mixins/channels.id.json +0 -20
  253. data/lib/slack/web/api/mixins/groups.id.json +0 -20
  254. data/lib/slack/web/api/mixins/groups.id.rb +0 -27
  255. data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +0 -13
  256. data/lib/slack/web/api/patches/chat.2.attachments-json.patch +0 -17
  257. data/lib/slack/web/api/patches/chat.3.update-attachments-support.patch +0 -21
  258. data/lib/slack/web/api/patches/chat.4.postEphemeral-attachments-support.patch +0 -17
  259. data/lib/slack/web/api/patches/chat.5.postEphemeral-text-or-attachments.patch +0 -15
  260. data/spec/fixtures/slack/web/503_error.yml +0 -14
  261. data/spec/fixtures/slack/web/channels_info.yml +0 -46
  262. data/spec/fixtures/slack/web/groups_info.yml +0 -43
  263. data/spec/slack/real_time/concurrency/celluloid_spec.rb +0 -116
  264. data/spec/slack/real_time/concurrency/eventmachine_spec.rb +0 -57
  265. data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +0 -16
  266. data/spec/slack/web/api/endpoints/apps_permissions_users_spec.rb +0 -19
  267. data/spec/slack/web/api/endpoints/conversations_spec.rb +0 -101
  268. data/spec/slack/web/api/endpoints/custom_specs/channels_spec.rb +0 -13
  269. data/spec/slack/web/api/endpoints/custom_specs/groups_spec.rb +0 -13
  270. data/spec/slack/web/api/endpoints/im_spec.rb +0 -39
  271. data/spec/slack/web/api/endpoints/mpim_spec.rb +0 -39
  272. data/spec/slack/web/api/endpoints/views_spec.rb +0 -29
  273. data/spec/slack/web/api/errors/service_unavailable_spec.rb +0 -17
  274. data/spec/slack/web/api/mixins/groups_spec.rb +0 -43
@@ -5,34 +5,29 @@ RSpec.describe Slack::Web::Api::Errors::SlackError do
5
5
  let(:client) { Slack::Web::Client.new }
6
6
 
7
7
  it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
8
- begin
9
- client.auth_test
10
- raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
11
- rescue described_class => e
12
- expect(e.response).not_to be_nil
13
- expect(e.response.status).to eq 200
14
- expect(e.message).to eql 'not_authed'
15
- expect(e.error).to eql 'not_authed'
16
- expect(e.response_metadata).to be_nil
17
- end
8
+ client.auth_test
9
+ raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
10
+ rescue described_class => e
11
+ expect(e.response).not_to be_nil
12
+ expect(e.response.status).to eq 200
13
+ expect(e.message).to eql 'not_authed'
14
+ expect(e.error).to eql 'not_authed'
15
+ expect(e.response_metadata).to be_nil
18
16
  end
19
17
 
20
18
  it 'provides access to any response_metadata', vcr: { cassette_name: 'web/views_open_error' } do
21
- begin
22
- client.views_open(trigger_id: 'trigger_id', view: {})
23
- raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
24
- rescue described_class => e
25
- expect(e.response).not_to be_nil
26
- expect(e.response.status).to eq 200
27
- expect(e.message).to eql 'invalid_arguments'
28
- expect(e.error).to eql 'invalid_arguments'
29
- expect(e.response_metadata).to eq(
30
- 'messages' => [
31
- "[ERROR] missing required field: title [json-pointer:\/view]",
32
- "[ERROR] missing required field: blocks [json-pointer:\/view]",
33
- "[ERROR] missing required field: type [json-pointer:\/view]"
34
- ]
35
- )
36
- end
19
+ client.views_open(trigger_id: 'trigger_id', view: {})
20
+ raise 'Expected to receive Slack::Web::Api::Errors::SlackError.'
21
+ rescue described_class => e
22
+ expect(e.response).not_to be_nil
23
+ expect(e.response.status).to eq 200
24
+ expect(e.message).to eql 'invalid_arguments'
25
+ expect(e.error).to eql 'invalid_arguments'
26
+ expect(e.response_metadata).to eq(
27
+ 'messages' => [
28
+ '[ERROR] failed to match all allowed schemas [json-pointer:/view]',
29
+ '[ERROR] missing required field: type [json-pointer:/view]'
30
+ ]
31
+ )
37
32
  end
38
33
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ RSpec.describe Slack::Web::Client do
5
+ context 'conversations_setTopic' do
6
+ it 'does not invoke conversations_list', vcr: { cassette_name: 'web/conversations_setTopic' } do
7
+ rc = subject.conversations_setTopic({ channel: 'C019CV63UTC', topic: 'new topic' })
8
+ expect(rc.channel.topic.value).to eq 'new topic'
9
+ end
10
+
11
+ it 'resolves IDs via conversations_list', vcr: { cassette_name: 'web/conversations_setTopic_one_page' } do
12
+ rc = subject.conversations_setTopic({ channel: '#1', topic: 'new topic' })
13
+ expect(rc.channel.topic.value).to eq 'new topic'
14
+ end
15
+
16
+ it 'paginates to resolve IDs', vcr: { cassette_name: 'web/conversations_setTopic_paginated' } do
17
+ rc = subject.conversations_setTopic({ channel: '#topic', topic: 'new topic' })
18
+ expect(rc.channel.topic.value).to eq 'new topic'
19
+ end
20
+ end
21
+ end
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
  require 'spec_helper'
3
3
 
4
- RSpec.describe Slack::Web::Api::Mixins::Channels do
5
- subject(:channels) do
4
+ RSpec.describe Slack::Web::Api::Mixins::Conversations do
5
+ subject(:conversations) do
6
6
  klass.new
7
7
  end
8
8
 
9
9
  let(:klass) do
10
10
  Class.new do
11
- include Slack::Web::Api::Mixins::Channels
11
+ include Slack::Web::Api::Mixins::Conversations
12
12
  end
13
13
  end
14
14
 
15
15
  before do
16
- allow(channels).to receive(:channels_list).and_return(
16
+ allow(conversations).to receive(:conversations_list).and_yield(
17
17
  Slack::Messages::Message.new(
18
18
  'channels' => [{
19
19
  'id' => 'CDEADBEEF',
@@ -23,19 +23,19 @@ RSpec.describe Slack::Web::Api::Mixins::Channels do
23
23
  )
24
24
  end
25
25
 
26
- context '#channels_id' do
26
+ describe '#conversations_id' do
27
27
  it 'leaves channels specified by ID alone' do
28
- expect(channels.channels_id(channel: 'C123456')).to(
28
+ expect(conversations.conversations_id(channel: 'C123456')).to(
29
29
  eq('ok' => true, 'channel' => { 'id' => 'C123456' })
30
30
  )
31
31
  end
32
32
  it 'translates a channel that starts with a #' do
33
- expect(channels.channels_id(channel: '#general')).to(
33
+ expect(conversations.conversations_id(channel: '#general')).to(
34
34
  eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' })
35
35
  )
36
36
  end
37
37
  it 'fails with an exception' do
38
- expect { channels.channels_id(channel: '#invalid') }.to(
38
+ expect { conversations.conversations_id(channel: '#invalid') }.to(
39
39
  raise_error(Slack::Web::Api::Errors::SlackError, 'channel_not_found')
40
40
  )
41
41
  end
@@ -13,7 +13,7 @@ RSpec.describe Slack::Web::Api::Mixins::Users do
13
13
  end
14
14
 
15
15
  before do
16
- allow(users).to receive(:users_list).and_return(
16
+ allow(users).to receive(:users_list).and_yield(
17
17
  Slack::Messages::Message.new(
18
18
  'members' => [{
19
19
  'id' => 'UDEADBEEF',
@@ -30,7 +30,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
30
30
  cursor.to_a
31
31
  end
32
32
  context 'with rate limiting' do
33
- let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(nil) }
33
+ let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(OpenStruct.new(headers: { 'retry-after' => 9 })) }
34
34
 
35
35
  context 'with default max retries' do
36
36
  it 'sleeps after a TooManyRequestsError' do
@@ -43,7 +43,6 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
43
43
  expect(client).to(
44
44
  receive(:users_list).with(limit: 100, cursor: 'next').ordered.and_raise(error)
45
45
  )
46
- expect(error).to receive(:retry_after).once.ordered.and_return(9)
47
46
  expect(cursor).to receive(:sleep).once.ordered.with(9)
48
47
  expect(client).to(
49
48
  receive(:users_list)
@@ -67,7 +66,6 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
67
66
  expect(client).to(
68
67
  receive(:users_list).with(limit: 100, cursor: 'next').exactly(5).times.and_raise(error)
69
68
  )
70
- expect(error).to receive(:retry_after).exactly(4).times.and_return(9)
71
69
  expect(cursor).to receive(:sleep).exactly(4).times.with(9)
72
70
  expect { cursor.to_a }.to raise_error(error)
73
71
  end
@@ -150,6 +150,50 @@ RSpec.describe Slack::Web::Client do
150
150
  end
151
151
  end
152
152
 
153
+ context 'adapter option' do
154
+ let(:adapter) { Faraday.default_adapter }
155
+ let(:adapter_class) { Faraday::Adapter::NetHttp }
156
+
157
+ around do |ex|
158
+ previous_adapter = Faraday.default_adapter
159
+ # ensure default adapter is set for this spec
160
+ Faraday.default_adapter = :net_http
161
+ ex.run
162
+ Faraday.default_adapter = previous_adapter
163
+ end
164
+
165
+ context 'default adapter' do
166
+ describe '#initialize' do
167
+ it 'sets adapter' do
168
+ expect(client.adapter).to eq adapter
169
+ end
170
+ it 'creates a connection with an adapter' do
171
+ expect(client.send(:connection).adapter).to eq adapter_class
172
+ end
173
+ end
174
+ end
175
+
176
+ context 'non default adapter' do
177
+ let(:adapter) { :typhoeus }
178
+ let(:adapter_class) { Faraday::Adapter::Typhoeus }
179
+
180
+ before do
181
+ described_class.configure do |config|
182
+ config.adapter = adapter
183
+ end
184
+ end
185
+
186
+ describe '#initialize' do
187
+ it 'sets adapter' do
188
+ expect(client.adapter).to eq adapter
189
+ end
190
+ it 'creates a connection with an adapter' do
191
+ expect(client.send(:connection).adapter).to eq adapter_class
192
+ end
193
+ end
194
+ end
195
+ end
196
+
153
197
  context 'timeout options' do
154
198
  before do
155
199
  described_class.configure do |config|
@@ -182,7 +226,10 @@ RSpec.describe Slack::Web::Client do
182
226
  request = nil
183
227
  response = conn.post do |r|
184
228
  r.path = 'rtm.start'
185
- r.body = { token: 'token' }
229
+ r.headers = {
230
+ 'Accept' => ['application/json; charset=utf-8'],
231
+ 'Authorization' => ['Bearer <SLACK_API_TOKEN>']
232
+ }
186
233
  request = r
187
234
  end
188
235
 
@@ -205,5 +252,80 @@ RSpec.describe Slack::Web::Client do
205
252
  client.users_admin_setInactive(user: 'U092BDCLV')
206
253
  end
207
254
  end
255
+
256
+ context 'persistent capability' do
257
+ describe '#initialize' do
258
+ it 'caches the Faraday connection to allow persistent adapters' do
259
+ first = client.send(:connection)
260
+ second = client.send(:connection)
261
+
262
+ expect(first).to equal second
263
+ end
264
+ end
265
+ end
266
+
267
+ context 'server failures' do
268
+ subject(:request) { client.api_test }
269
+
270
+ let(:stub_slack_request) { stub_request(:post, 'https://slack.com/api/api.test') }
271
+ let(:exception) do
272
+ request
273
+ rescue Slack::Web::Api::Errors::ServerError => e
274
+ return e
275
+ end
276
+
277
+ context 'parsing error' do
278
+ before { stub_slack_request.to_return(body: '<html></html>') }
279
+
280
+ it 'raises ParsingError' do
281
+ expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
282
+ expect(exception.response.body).to eq('<html></html>')
283
+ expect(exception.cause).to be_a(Faraday::ParsingError)
284
+ expect(exception.cause.cause.cause).to be_a(JSON::ParserError)
285
+ end
286
+ end
287
+
288
+ context 'timeout' do
289
+ context 'open timeout' do
290
+ before { stub_slack_request.to_timeout }
291
+
292
+ it 'raises TimoutError' do
293
+ expect { request }.to raise_error(Slack::Web::Api::Errors::TimeoutError).with_message('timeout_error')
294
+ expect(exception.cause).to be_a(Faraday::ConnectionFailed)
295
+ expect(exception.cause.cause).to be_a(Net::OpenTimeout)
296
+ end
297
+ end
298
+
299
+ context 'read timeout' do
300
+ before { stub_slack_request.to_raise(Net::ReadTimeout) }
301
+
302
+ it 'raises TimeoutError' do
303
+ expect { request }.to raise_error(Slack::Web::Api::Errors::TimeoutError).with_message('timeout_error')
304
+ expect(exception.cause).to be_a(Faraday::TimeoutError)
305
+ expect(exception.cause.cause).to be_a(Net::ReadTimeout)
306
+ end
307
+ end
308
+ end
309
+
310
+ context '5xx response' do
311
+ context 'with a JSON body' do
312
+ before { stub_slack_request.to_return(status: 500, body: '{}') }
313
+
314
+ it 'raises UnavailableError' do
315
+ expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
316
+ expect(exception.response.status).to eq(500)
317
+ end
318
+ end
319
+
320
+ context 'with a HTML response' do
321
+ before { stub_slack_request.to_return(status: 500, body: '<html></html>') }
322
+
323
+ it 'raises UnavailableError' do
324
+ expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')
325
+ expect(exception.response.status).to eq(500)
326
+ end
327
+ end
328
+ end
329
+ end
208
330
  end
209
331
  end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+
4
+ class DummyClient
5
+ include Slack::Web::Faraday::Connection
6
+ include Slack::Web::Faraday::Request
7
+
8
+ attr_reader :token
9
+
10
+ def initialize(token)
11
+ @token = token
12
+ end
13
+ end
14
+
15
+ RSpec.describe Slack::Web::Faraday::Request do
16
+ let(:token) { 'by-the-power-of-grayskull' }
17
+ let(:client) { DummyClient.new(token) }
18
+
19
+ before do
20
+ Slack::Config.reset
21
+ end
22
+
23
+ context 'authorization' do
24
+ let(:path) { '/any-path' }
25
+ let(:options) { {} }
26
+ let(:connection) { instance_double('Faraday::Connection') }
27
+ let(:request) { instance_double('Faraday::Request') }
28
+ let(:headers) { instance_double('Faraday::Utils::Headers') }
29
+ let(:response) { instance_double('Faraday::Response', body: '') }
30
+
31
+ before do
32
+ allow(client).to receive(:connection).and_return(connection)
33
+ allow(request).to receive(:url).with(path, options)
34
+ allow(request).to receive(:path=).with(path)
35
+ allow(request).to receive(:headers).and_return(headers)
36
+ allow(connection).to receive(:send)
37
+ .with(method).and_yield(request).and_return(response)
38
+ end
39
+
40
+ describe '#get' do
41
+ let(:method) { :get }
42
+
43
+ it 'sets authorization header' do
44
+ expect(headers).to receive(:[]=)
45
+ .with('Authorization', "Bearer #{token}")
46
+ client.send(method, path, options)
47
+ end
48
+ end
49
+
50
+ describe '#post' do
51
+ let(:method) { :post }
52
+
53
+ it 'sets authorization header' do
54
+ expect(headers).to receive(:[]=)
55
+ .with('Authorization', "Bearer #{token}")
56
+ client.send(method, path, options)
57
+ end
58
+ end
59
+
60
+ describe '#put' do
61
+ let(:method) { :put }
62
+
63
+ it 'sets authorization header' do
64
+ expect(headers).to receive(:[]=)
65
+ .with('Authorization', "Bearer #{token}")
66
+ client.send(method, path, options)
67
+ end
68
+ end
69
+
70
+ describe '#delete' do
71
+ let(:method) { :delete }
72
+
73
+ it 'sets authorization header' do
74
+ expect(headers).to receive(:[]=)
75
+ .with('Authorization', "Bearer #{token}")
76
+ client.send(method, path, options)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -2,16 +2,18 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  RSpec.describe Slack::Web::Faraday::Response::RaiseError do
5
- subject(:raise_error_obj) { described_class.new }
5
+ subject(:raise_error_obj) { described_class.new(app) }
6
6
 
7
- describe '#on_complete' do
8
- let(:status) { 200 }
9
- let(:response) { nil }
10
- let(:body) { {} }
11
- let(:env) { double status: status, response: response, body: body }
7
+ let(:app) { proc {} }
8
+ let(:status) { 200 }
9
+ let(:response) { nil }
10
+ let(:body) { {} }
11
+ let(:env) { double status: status, response: response, body: body, success?: true }
12
12
 
13
+ describe '#on_complete' do
13
14
  context 'with status of 429' do
14
15
  let(:status) { 429 }
16
+ let(:response) { OpenStruct.new(headers: { 'retry-after' => 10 }) }
15
17
 
16
18
  it 'raises a TooManyRequestsError' do
17
19
  expect { raise_error_obj.on_complete(env) }.to(
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,7 @@ Dir[File.join(File.dirname(__FILE__), 'support', '**/*.rb')].each do |file|
12
12
  end
13
13
 
14
14
  Slack.configure do |config|
15
- config.token = ENV['SLACK_API_TOKEN']
15
+ config.token = '<SLACK_API_TOKEN>' # ENV['SLACK_API_TOKEN']
16
16
  end
17
17
 
18
18
  RSpec.configure do |config|
@@ -2,13 +2,7 @@
2
2
  RSpec.shared_context 'connected client' do |opts|
3
3
  let(:client) { Slack::RealTime::Client.new(opts || {}) }
4
4
  let(:ws) { double(Slack::RealTime::Concurrency::Mock::WebSocket) }
5
- let(:url) do
6
- if Slack::RealTime.config.store_class == Slack::RealTime::Stores::Store
7
- 'wss://ms173.slack-msgs.com/websocket/lqcUiAvrKTP-uuid='
8
- else
9
- 'wss://mpmulti-w5tz.slack-msgs.com/websocket/uid'
10
- end
11
- end
5
+ let(:url) { 'wss://cerberus-xxxx.lb.slack-msgs.com/websocket/uid' }
12
6
  let(:socket) { double(Slack::RealTime::Socket, connected?: true) }
13
7
 
14
8
  before do
data/spec/support/vcr.rb CHANGED
@@ -5,6 +5,41 @@ require 'webmock/rspec'
5
5
  VCR.configure do |config|
6
6
  config.cassette_library_dir = 'spec/fixtures/slack'
7
7
  config.hook_into :webmock
8
- # config.default_cassette_options = { record: :new_episodes }
9
8
  config.configure_rspec_metadata!
9
+ if ENV.key?('SLACK_API_TOKEN')
10
+ config.filter_sensitive_data('<SLACK_API_TOKEN>') do
11
+ ENV['SLACK_API_TOKEN']
12
+ end
13
+ end
14
+ config.before_record do |i|
15
+ i.response.body.force_encoding('UTF-8')
16
+ end
17
+ config.register_request_matcher :client_headers do |recorded, actual|
18
+ authorizations = ENV.key?('SLACK_API_TOKEN') ? actual.headers['Authorization'].map do |auth|
19
+ auth.gsub(ENV['SLACK_API_TOKEN'], '<SLACK_API_TOKEN>')
20
+ end : actual.headers['Authorization']
21
+ actual.headers['Accept'] == recorded.headers['Accept'] &&
22
+ authorizations == recorded.headers['Authorization']
23
+ end
24
+ config.default_cassette_options = {
25
+ match_requests_on: %i[method uri body client_headers]
26
+ # record: :new_episodes
27
+ }
28
+ end
29
+
30
+ module VCR
31
+ module Errors
32
+ class UnhandledHTTPRequestError
33
+ private
34
+
35
+ # Force unhandled HTTP error reports to include the headers
36
+ # for our custom matcher `client_headers`.
37
+ #
38
+ # This patch can be removed if https://github.com/vcr/vcr/issues/912
39
+ # is ever resolved.
40
+ def match_request_on_headers?
41
+ true
42
+ end
43
+ end
44
+ end
10
45
  end