slack-ruby-client 1.0.0 → 2.1.0

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 (239) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/integration_test.yml +45 -0
  4. data/.github/workflows/lint.yml +14 -0
  5. data/.github/workflows/pr_lint.yml +21 -0
  6. data/.github/workflows/test.yml +37 -0
  7. data/.gitignore +4 -3
  8. data/.rubocop.yml +6 -1
  9. data/.rubocop_todo.yml +88 -34
  10. data/.ruby-version +1 -0
  11. data/CHANGELOG.md +36 -0
  12. data/CONTRIBUTING.md +6 -5
  13. data/Gemfile +13 -1
  14. data/Gemfile.danger +6 -0
  15. data/README.md +78 -76
  16. data/RELEASING.md +2 -2
  17. data/SECURITY.md +9 -0
  18. data/UPGRADING.md +28 -0
  19. data/bin/commands/admin_analytics.rb +16 -10
  20. data/bin/commands/admin_apps.rb +48 -42
  21. data/bin/commands/admin_apps_approved.rb +17 -11
  22. data/bin/commands/admin_apps_requests.rb +28 -11
  23. data/bin/commands/admin_apps_restricted.rb +17 -11
  24. data/bin/commands/admin_audit_anomaly_allow.rb +29 -0
  25. data/bin/commands/admin_auth_policy.rb +37 -31
  26. data/bin/commands/admin_barriers.rb +44 -38
  27. data/bin/commands/admin_conversations.rb +221 -163
  28. data/bin/commands/admin_conversations_ekm.rb +17 -11
  29. data/bin/commands/admin_conversations_restrictAccess.rb +35 -29
  30. data/bin/commands/admin_emoji.rb +50 -44
  31. data/bin/commands/admin_inviteRequests.rb +34 -28
  32. data/bin/commands/admin_inviteRequests_approved.rb +16 -10
  33. data/bin/commands/admin_inviteRequests_denied.rb +16 -10
  34. data/bin/commands/admin_roles.rb +46 -0
  35. data/bin/commands/admin_teams.rb +26 -20
  36. data/bin/commands/admin_teams_admins.rb +16 -10
  37. data/bin/commands/admin_teams_owners.rb +16 -10
  38. data/bin/commands/admin_teams_settings.rb +59 -53
  39. data/bin/commands/admin_usergroups.rb +45 -39
  40. data/bin/commands/admin_users.rb +91 -85
  41. data/bin/commands/admin_users_session.rb +72 -66
  42. data/bin/commands/admin_users_unsupportedVersions.rb +21 -0
  43. data/bin/commands/api.rb +14 -8
  44. data/bin/commands/apps.rb +15 -9
  45. data/bin/commands/apps_connections.rb +13 -7
  46. data/bin/commands/apps_event_authorizations.rb +16 -10
  47. data/bin/commands/apps_manifest.rb +48 -41
  48. data/bin/commands/auth.rb +21 -15
  49. data/bin/commands/auth_teams.rb +16 -10
  50. data/bin/commands/bookmarks.rb +59 -0
  51. data/bin/commands/bots.rb +15 -9
  52. data/bin/commands/calls.rb +49 -43
  53. data/bin/commands/calls_participants.rb +24 -18
  54. data/bin/commands/chat.rb +150 -141
  55. data/bin/commands/chat_scheduledMessages.rb +19 -13
  56. data/bin/commands/conversations.rb +233 -225
  57. data/bin/commands/dialog.rb +15 -9
  58. data/bin/commands/dnd.rb +46 -40
  59. data/bin/commands/emoji.rb +14 -7
  60. data/bin/commands/files.rb +112 -83
  61. data/bin/commands/files_comments.rb +15 -9
  62. data/bin/commands/files_remote.rb +73 -67
  63. data/bin/commands/functions_workflows_steps.rb +22 -0
  64. data/bin/commands/functions_workflows_steps_responses.rb +22 -0
  65. data/bin/commands/migration.rb +16 -10
  66. data/bin/commands/oauth.rb +18 -12
  67. data/bin/commands/oauth_v2.rb +28 -22
  68. data/bin/commands/openid_connect.rb +26 -20
  69. data/bin/commands/pins.rb +33 -26
  70. data/bin/commands/reactions.rb +52 -46
  71. data/bin/commands/reminders.rb +53 -47
  72. data/bin/commands/rtm.rb +15 -24
  73. data/bin/commands/search.rb +43 -37
  74. data/bin/commands/stars.rb +38 -32
  75. data/bin/commands/team.rb +47 -38
  76. data/bin/commands/team_billing.rb +13 -7
  77. data/bin/commands/team_preferences.rb +13 -7
  78. data/bin/commands/team_profile.rb +14 -8
  79. data/bin/commands/tooling_tokens.rb +14 -8
  80. data/bin/commands/usergroups.rb +64 -58
  81. data/bin/commands/usergroups_users.rb +27 -21
  82. data/bin/commands/users.rb +111 -105
  83. data/bin/commands/users_admin.rb +28 -22
  84. data/bin/commands/users_prefs.rb +13 -7
  85. data/bin/commands/users_profile.rb +26 -20
  86. data/bin/commands/views.rb +47 -39
  87. data/bin/commands/workflows.rb +36 -30
  88. data/bin/slack +48 -43
  89. data/lib/slack/real_time/api/message.rb +3 -2
  90. data/lib/slack/real_time/api/templates/event_handler.erb +5 -1
  91. data/lib/slack/real_time/api/typing.rb +2 -1
  92. data/lib/slack/real_time/client.rb +10 -28
  93. data/lib/slack/real_time/config.rb +3 -3
  94. data/lib/slack/real_time/models/channel.rb +4 -0
  95. data/lib/slack/real_time/models/{group.rb → mpim.rb} +1 -1
  96. data/lib/slack/real_time/models.rb +2 -1
  97. data/lib/slack/real_time/stores/base.rb +25 -9
  98. data/lib/slack/real_time/stores/starter.rb +323 -309
  99. data/lib/slack/real_time/stores/store.rb +265 -198
  100. data/lib/slack/real_time/stores.rb +1 -7
  101. data/lib/slack/version.rb +1 -1
  102. data/lib/slack/web/api/endpoints/admin_analytics.rb +2 -2
  103. data/lib/slack/web/api/endpoints/admin_apps.rb +2 -2
  104. data/lib/slack/web/api/endpoints/admin_apps_requests.rb +16 -0
  105. data/lib/slack/web/api/endpoints/admin_audit_anomaly_allow.rb +34 -0
  106. data/lib/slack/web/api/endpoints/admin_auth_policy.rb +7 -7
  107. data/lib/slack/web/api/endpoints/admin_barriers.rb +8 -8
  108. data/lib/slack/web/api/endpoints/admin_conversations.rb +110 -28
  109. data/lib/slack/web/api/endpoints/admin_conversations_restrictAccess.rb +6 -6
  110. data/lib/slack/web/api/endpoints/admin_emoji.rb +9 -9
  111. data/lib/slack/web/api/endpoints/admin_inviteRequests.rb +2 -2
  112. data/lib/slack/web/api/endpoints/admin_roles.rb +73 -0
  113. data/lib/slack/web/api/endpoints/admin_teams.rb +2 -2
  114. data/lib/slack/web/api/endpoints/admin_teams_admins.rb +1 -1
  115. data/lib/slack/web/api/endpoints/admin_teams_owners.rb +1 -1
  116. data/lib/slack/web/api/endpoints/admin_teams_settings.rb +11 -11
  117. data/lib/slack/web/api/endpoints/admin_usergroups.rb +7 -7
  118. data/lib/slack/web/api/endpoints/admin_users.rb +16 -16
  119. data/lib/slack/web/api/endpoints/admin_users_session.rb +8 -8
  120. data/lib/slack/web/api/endpoints/admin_users_unsupportedVersions.rb +25 -0
  121. data/lib/slack/web/api/endpoints/apps.rb +2 -2
  122. data/lib/slack/web/api/endpoints/apps_connections.rb +1 -1
  123. data/lib/slack/web/api/endpoints/apps_event_authorizations.rb +1 -1
  124. data/lib/slack/web/api/endpoints/apps_manifest.rb +8 -6
  125. data/lib/slack/web/api/endpoints/bookmarks.rb +88 -0
  126. data/lib/slack/web/api/endpoints/bots.rb +1 -1
  127. data/lib/slack/web/api/endpoints/calls.rb +5 -5
  128. data/lib/slack/web/api/endpoints/calls_participants.rb +4 -4
  129. data/lib/slack/web/api/endpoints/chat.rb +37 -31
  130. data/lib/slack/web/api/endpoints/conversations.rb +38 -34
  131. data/lib/slack/web/api/endpoints/dialog.rb +2 -2
  132. data/lib/slack/web/api/endpoints/dnd.rb +1 -1
  133. data/lib/slack/web/api/endpoints/emoji.rb +2 -0
  134. data/lib/slack/web/api/endpoints/files.rb +45 -10
  135. data/lib/slack/web/api/endpoints/files_comments.rb +2 -2
  136. data/lib/slack/web/api/endpoints/files_remote.rb +8 -8
  137. data/lib/slack/web/api/endpoints/functions_workflows_steps.rb +28 -0
  138. data/lib/slack/web/api/endpoints/functions_workflows_steps_responses.rb +28 -0
  139. data/lib/slack/web/api/endpoints/migration.rb +1 -1
  140. data/lib/slack/web/api/endpoints/oauth_v2.rb +2 -2
  141. data/lib/slack/web/api/endpoints/pins.rb +5 -3
  142. data/lib/slack/web/api/endpoints/reactions.rb +4 -4
  143. data/lib/slack/web/api/endpoints/reminders.rb +5 -5
  144. data/lib/slack/web/api/endpoints/rtm.rb +0 -23
  145. data/lib/slack/web/api/endpoints/search.rb +3 -3
  146. data/lib/slack/web/api/endpoints/team.rb +13 -1
  147. data/lib/slack/web/api/endpoints/tooling_tokens.rb +1 -1
  148. data/lib/slack/web/api/endpoints/usergroups.rb +5 -5
  149. data/lib/slack/web/api/endpoints/usergroups_users.rb +3 -3
  150. data/lib/slack/web/api/endpoints/users.rb +4 -4
  151. data/lib/slack/web/api/endpoints/users_admin.rb +2 -2
  152. data/lib/slack/web/api/endpoints/users_profile.rb +1 -1
  153. data/lib/slack/web/api/endpoints/views.rb +16 -11
  154. data/lib/slack/web/api/endpoints/workflows.rb +4 -4
  155. data/lib/slack/web/api/endpoints.rb +12 -0
  156. data/lib/slack/web/api/errors.rb +146 -8
  157. data/lib/slack/web/api/mixins/conversations.id.rb +1 -1
  158. data/lib/slack/web/api/mixins/users.id.rb +1 -1
  159. data/lib/slack/web/api/mixins/users.search.rb +2 -1
  160. data/lib/slack/web/api/patches/{chat.1.patch → chat.attachments-blocks.patch} +13 -14
  161. data/lib/slack/web/api/patches/{dialog.1.open-json-support.patch → dialog.encoded-json.patch} +4 -4
  162. data/lib/slack/web/api/patches/views.view-json.patch +55 -0
  163. data/lib/slack/web/api/templates/command.erb +18 -12
  164. data/lib/slack/web/api/templates/method.erb +1 -1
  165. data/lib/slack/web/config.rb +2 -2
  166. data/lib/slack/web/faraday/connection.rb +4 -4
  167. data/lib/slack/web/faraday/request.rb +2 -0
  168. data/lib/slack/web/faraday/response/raise_error.rb +2 -10
  169. data/lib/slack/web/faraday/response/wrap_error.rb +1 -1
  170. data/lib/slack-ruby-client.rb +2 -1
  171. data/lib/tasks/real_time.rake +44 -24
  172. data/lib/tasks/web.rake +9 -8
  173. data/slack-ruby-client.gemspec +5 -14
  174. data/spec/fixtures/slack/web/rtm_connect.yml +85 -1
  175. data/spec/integration/integration_spec.rb +1 -1
  176. data/spec/slack/events/config_spec.rb +2 -0
  177. data/spec/slack/events/request_spec.rb +5 -1
  178. data/spec/slack/messages/formatting_spec.rb +10 -0
  179. data/spec/slack/real_time/api/message_spec.rb +1 -1
  180. data/spec/slack/real_time/api/ping_spec.rb +1 -1
  181. data/spec/slack/real_time/api/typing_spec.rb +1 -1
  182. data/spec/slack/real_time/client_spec.rb +91 -127
  183. data/spec/slack/real_time/event_handlers/bot_spec.rb +19 -17
  184. data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +1 -1
  185. data/spec/slack/real_time/event_handlers/im_spec.rb +30 -27
  186. data/spec/slack/real_time/event_handlers/{group_spec.rb → private_channel_spec.rb} +35 -27
  187. data/spec/slack/real_time/event_handlers/{channel_spec.rb → public_channel_spec.rb} +27 -23
  188. data/spec/slack/real_time/event_handlers/team_spec.rb +7 -8
  189. data/spec/slack/real_time/event_handlers/user_spec.rb +6 -5
  190. data/spec/slack/real_time/stores/store_spec.rb +50 -0
  191. data/spec/slack/slack_spec.rb +5 -4
  192. data/spec/slack/version_spec.rb +1 -1
  193. data/spec/slack/web/api/endpoints/admin_apps_requests_spec.rb +5 -0
  194. data/spec/slack/web/api/endpoints/admin_audit_anomaly_allow_spec.rb +8 -0
  195. data/spec/slack/web/api/endpoints/admin_conversations_spec.rb +31 -0
  196. data/spec/slack/web/api/endpoints/admin_roles_spec.rb +30 -0
  197. data/spec/slack/web/api/endpoints/admin_users_unsupportedVersions_spec.rb +8 -0
  198. data/spec/slack/web/api/endpoints/bookmarks_spec.rb +40 -0
  199. data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +45 -17
  200. data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +6 -2
  201. data/spec/slack/web/api/endpoints/custom_specs/views_spec.rb +33 -16
  202. data/spec/slack/web/api/endpoints/files_spec.rb +13 -0
  203. data/spec/slack/web/api/endpoints/functions_workflows_steps_responses_spec.rb +13 -0
  204. data/spec/slack/web/api/endpoints/functions_workflows_steps_spec.rb +13 -0
  205. data/spec/slack/web/api/mixins/conversations_spec.rb +2 -0
  206. data/spec/slack/web/api/mixins/users_spec.rb +2 -0
  207. data/spec/slack/web/api/pagination/cursor_spec.rb +11 -7
  208. data/spec/slack/web/client_spec.rb +39 -11
  209. data/spec/slack/web/faraday/response/raise_error_spec.rb +1 -1
  210. data/spec/support/real_time/connected_client.rb +1 -1
  211. data/spec/support/real_time/loaded_client.rb +120 -0
  212. metadata +45 -197
  213. data/.travis.yml +0 -29
  214. data/bin/commands/admin_conversations_whitelist.rb +0 -37
  215. data/bin/commands/apps_permissions.rb +0 -23
  216. data/bin/commands/apps_permissions_resources.rb +0 -15
  217. data/bin/commands/apps_permissions_scopes.rb +0 -13
  218. data/bin/commands/apps_permissions_users.rb +0 -26
  219. data/bin/commands/channels.rb +0 -23
  220. data/bin/commands/groups.rb +0 -14
  221. data/bin/commands/im.rb +0 -6
  222. data/bin/commands/mpim.rb +0 -6
  223. data/bin/commands.rb +0 -66
  224. data/lib/slack/web/api/endpoints/admin_conversations_whitelist.rb +0 -64
  225. data/lib/slack/web/api/endpoints/apps_permissions.rb +0 -36
  226. data/lib/slack/web/api/endpoints/apps_permissions_resources.rb +0 -31
  227. data/lib/slack/web/api/endpoints/apps_permissions_scopes.rb +0 -21
  228. data/lib/slack/web/api/endpoints/apps_permissions_users.rb +0 -50
  229. data/lib/slack/web/api/endpoints/channels.rb +0 -25
  230. data/lib/slack/web/api/endpoints/groups.rb +0 -13
  231. data/lib/slack/web/api/endpoints/im.rb +0 -13
  232. data/lib/slack/web/api/endpoints/mpim.rb +0 -13
  233. data/lib/slack/web/api/endpoints/presence.rb +0 -23
  234. data/lib/slack/web/api/patches/views.1.view-json.patch +0 -40
  235. data/lib/slack/web/api/patches/views.1.views-published.patch +0 -16
  236. data/lib/slack/web/api/templates/commands.erb +0 -6
  237. data/spec/fixtures/slack/web/rtm_start.yml +0 -815
  238. data/spec/slack/real_time/rtm_start_spec.rb +0 -14
  239. data/spec/slack/real_time/store_spec.rb +0 -12
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ # This file was auto-generated by lib/tasks/web.rake
3
+
4
+ require 'spec_helper'
5
+
6
+ RSpec.describe Slack::Web::Api::Endpoints::Bookmarks do
7
+ let(:client) { Slack::Web::Client.new }
8
+ context 'bookmarks_add' do
9
+ it 'requires channel_id' do
10
+ expect { client.bookmarks_add(title: %q[], type: %q[]) }.to raise_error ArgumentError, /Required arguments :channel_id missing/
11
+ end
12
+ it 'requires title' do
13
+ expect { client.bookmarks_add(channel_id: %q[], type: %q[]) }.to raise_error ArgumentError, /Required arguments :title missing/
14
+ end
15
+ it 'requires type' do
16
+ expect { client.bookmarks_add(channel_id: %q[], title: %q[]) }.to raise_error ArgumentError, /Required arguments :type missing/
17
+ end
18
+ end
19
+ context 'bookmarks_edit' do
20
+ it 'requires bookmark_id' do
21
+ expect { client.bookmarks_edit(channel_id: %q[]) }.to raise_error ArgumentError, /Required arguments :bookmark_id missing/
22
+ end
23
+ it 'requires channel_id' do
24
+ expect { client.bookmarks_edit(bookmark_id: %q[]) }.to raise_error ArgumentError, /Required arguments :channel_id missing/
25
+ end
26
+ end
27
+ context 'bookmarks_list' do
28
+ it 'requires channel_id' do
29
+ expect { client.bookmarks_list }.to raise_error ArgumentError, /Required arguments :channel_id missing/
30
+ end
31
+ end
32
+ context 'bookmarks_remove' do
33
+ it 'requires bookmark_id' do
34
+ expect { client.bookmarks_remove(channel_id: %q[]) }.to raise_error ArgumentError, /Required arguments :bookmark_id missing/
35
+ end
36
+ it 'requires channel_id' do
37
+ expect { client.bookmarks_remove(bookmark_id: %q[]) }.to raise_error ArgumentError, /Required arguments :channel_id missing/
38
+ end
39
+ end
40
+ end
@@ -14,11 +14,13 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
14
14
  it 'automatically converts attachments and blocks into JSON' do
15
15
  expect(client).to receive(:post).with(
16
16
  'chat.postEphemeral',
17
- channel: 'channel',
18
- text: 'text',
19
- user: '123',
20
- attachments: '[]',
21
- blocks: '[]'
17
+ {
18
+ channel: 'channel',
19
+ text: 'text',
20
+ user: '123',
21
+ attachments: '[]',
22
+ blocks: '[]'
23
+ }
22
24
  )
23
25
  client.chat_postEphemeral(
24
26
  channel: 'channel',
@@ -28,17 +30,20 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
28
30
  blocks: []
29
31
  )
30
32
  end
33
+
31
34
  context 'text and user arguments' do
32
35
  it 'requires text or attachments' do
33
36
  expect { client.chat_postEphemeral(channel: 'channel') }.to(
34
37
  raise_error(ArgumentError, /Required arguments :text, :attachments or :blocks missing/)
35
38
  )
36
39
  end
40
+
37
41
  it 'requires user' do
38
42
  expect { client.chat_postEphemeral(channel: 'channel', text: 'text') }.to(
39
43
  raise_error(ArgumentError, /Required arguments :user missing/)
40
44
  )
41
45
  end
46
+
42
47
  it 'both text and user' do
43
48
  expect(client).to(
44
49
  receive(:post).with('chat.postEphemeral', hash_including(text: 'text', user: '123'))
@@ -58,6 +63,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
58
63
  client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', attachments: [])
59
64
  end.not_to raise_error
60
65
  end
66
+
61
67
  it 'attachments without text' do
62
68
  expect(client).to(
63
69
  receive(:post).with('chat.postEphemeral', hash_including(attachments: '[]'))
@@ -75,6 +81,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
75
81
  client.chat_postEphemeral(channel: 'channel', text: 'text', user: '123', blocks: [])
76
82
  end.not_to raise_error
77
83
  end
84
+
78
85
  it 'blocks without text' do
79
86
  expect(client).to receive(:post).with('chat.postEphemeral', hash_including(blocks: '[]'))
80
87
  expect do
@@ -88,31 +95,38 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
88
95
  it 'automatically converts attachments and blocks into JSON' do
89
96
  expect(client).to receive(:post).with(
90
97
  'chat.postMessage',
91
- channel: 'channel',
92
- text: 'text',
93
- attachments: '[]',
94
- blocks: '[]'
98
+ {
99
+ channel: 'channel',
100
+ text: 'text',
101
+ attachments: '[]',
102
+ blocks: '[]'
103
+ }
95
104
  )
96
105
  client.chat_postMessage(channel: 'channel', text: 'text', attachments: [], blocks: [])
97
106
  end
107
+
98
108
  context 'text, attachment and blocks arguments' do
99
109
  it 'requires text, attachments or blocks' do
100
110
  expect { client.chat_postMessage(channel: 'channel') }.to(
101
111
  raise_error(ArgumentError, /Required arguments :text, :attachments or :blocks missing/)
102
112
  )
103
113
  end
114
+
104
115
  it 'only text' do
105
116
  expect(client).to receive(:post).with('chat.postMessage', hash_including(text: 'text'))
106
117
  expect { client.chat_postMessage(channel: 'channel', text: 'text') }.not_to raise_error
107
118
  end
119
+
108
120
  it 'only attachments' do
109
121
  expect(client).to receive(:post).with('chat.postMessage', hash_including(attachments: '[]'))
110
122
  expect { client.chat_postMessage(channel: 'channel', attachments: []) }.not_to raise_error
111
123
  end
124
+
112
125
  it 'only blocks' do
113
126
  expect(client).to receive(:post).with('chat.postMessage', hash_including(blocks: '[]'))
114
127
  expect { client.chat_postMessage(channel: 'channel', blocks: []) }.not_to raise_error
115
128
  end
129
+
116
130
  it 'all text, attachments and blocks' do
117
131
  expect(client).to(
118
132
  receive(:post)
@@ -131,46 +145,60 @@ RSpec.describe Slack::Web::Api::Endpoints::Chat do
131
145
  it 'automatically converts attachments and blocks into JSON' do
132
146
  expect(client).to receive(:post).with(
133
147
  'chat.update',
134
- channel: 'channel',
135
- text: 'text',
136
- ts: ts,
137
- attachments: '[]',
138
- blocks: '[]'
148
+ {
149
+ channel: 'channel',
150
+ text: 'text',
151
+ ts: ts,
152
+ attachments: '[]',
153
+ blocks: '[]'
154
+ }
139
155
  )
140
156
  client.chat_update(channel: 'channel', text: 'text', ts: ts, attachments: [], blocks: [])
141
157
  end
158
+
142
159
  context 'ts arguments' do
143
160
  it 'requires ts' do
144
161
  expect do
145
162
  client.chat_update(channel: 'channel', text: 'text')
146
- end.to raise_error(ArgumentError, /Required arguments :ts missing>/)
163
+ end.to raise_error(ArgumentError, /Required arguments :ts missing/)
147
164
  end
148
165
  end
149
166
 
150
167
  context 'text, attachment and blocks arguments' do
151
- it 'requires text, attachments or blocks' do
168
+ it 'requires text, attachments, blocks or reply_broadcast' do
152
169
  expect { client.chat_update(channel: 'channel', ts: ts) }.to(
153
- raise_error(ArgumentError, /Required arguments :text, :attachments or :blocks missing/)
170
+ raise_error(ArgumentError, /Required arguments :text, :attachments, :blocks or :reply_broadcast missing/)
154
171
  )
155
172
  end
173
+
156
174
  it 'only text' do
157
175
  expect(client).to receive(:post).with('chat.update', hash_including(text: 'text'))
158
176
  expect do
159
177
  client.chat_update(channel: 'channel', text: 'text', ts: ts)
160
178
  end.not_to raise_error
161
179
  end
180
+
162
181
  it 'only attachments' do
163
182
  expect(client).to receive(:post).with('chat.update', hash_including(attachments: '[]'))
164
183
  expect do
165
184
  client.chat_update(channel: 'channel', ts: ts, attachments: [])
166
185
  end.not_to raise_error
167
186
  end
187
+
168
188
  it 'only blocks' do
169
189
  expect(client).to receive(:post).with('chat.update', hash_including(blocks: '[]'))
170
190
  expect do
171
191
  client.chat_update(channel: 'channel', ts: ts, blocks: [])
172
192
  end.not_to raise_error
173
193
  end
194
+
195
+ it 'only reply_broadcast' do
196
+ expect(client).to receive(:post).with('chat.update', hash_including(reply_broadcast: true))
197
+ expect do
198
+ client.chat_update(channel: 'channel', ts: ts, reply_broadcast: true)
199
+ end.not_to raise_error
200
+ end
201
+
174
202
  it 'all text, attachments and blocks' do
175
203
  expect(client).to(
176
204
  receive(:post)
@@ -8,8 +8,10 @@ RSpec.describe Slack::Web::Api::Endpoints::Dialog do
8
8
  it 'automatically converts dialog into JSON' do
9
9
  expect(client).to receive(:post).with(
10
10
  'dialog.open',
11
- trigger_id: '12345.98765.abcd2358fdea',
12
- dialog: '[]'
11
+ {
12
+ trigger_id: '12345.98765.abcd2358fdea',
13
+ dialog: '[]'
14
+ }
13
15
  )
14
16
  client.dialog_open(trigger_id: '12345.98765.abcd2358fdea', dialog: [])
15
17
  end
@@ -20,11 +22,13 @@ RSpec.describe Slack::Web::Api::Endpoints::Dialog do
20
22
  raise_error(ArgumentError, /Required arguments :dialog missing/)
21
23
  )
22
24
  end
25
+
23
26
  it 'requires trigger_id' do
24
27
  expect { client.dialog_open(dialog: []) }.to(
25
28
  raise_error(ArgumentError, /Required arguments :trigger_id missing/)
26
29
  )
27
30
  end
31
+
28
32
  it 'likes both dialog and trigger_id' do
29
33
  expect(client).to(
30
34
  receive(:post).with('dialog.open', hash_including(trigger_id: '123', dialog: '[]'))
@@ -4,13 +4,14 @@ require 'spec_helper'
4
4
  RSpec.describe Slack::Web::Api::Endpoints::Views do
5
5
  let(:client) { Slack::Web::Client.new }
6
6
  let(:trigger_id) { '12345.98765.abcd2358fdea' }
7
+ let(:view_id) { 'abc123567' }
7
8
 
8
9
  describe 'views_open' do
9
10
  context 'with a hash for view' do
10
11
  let(:view_str) { '{"celery":"man"}' }
11
12
 
12
13
  it 'automatically converts view into JSON' do
13
- expect(client).to receive(:post).with('views.open', trigger_id: trigger_id, view: view_str)
14
+ expect(client).to receive(:post).with('views.open', { trigger_id: trigger_id, view: view_str })
14
15
  client.views_open(trigger_id: trigger_id, view: { celery: 'man' })
15
16
  end
16
17
  end
@@ -19,7 +20,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
19
20
  let(:view_str) { 'celery man' }
20
21
 
21
22
  it 'leaves view as is' do
22
- expect(client).to receive(:post).with('views.open', trigger_id: trigger_id, view: view_str)
23
+ expect(client).to receive(:post).with('views.open', { trigger_id: trigger_id, view: view_str })
23
24
  client.views_open(trigger_id: trigger_id, view: 'celery man')
24
25
  end
25
26
  end
@@ -32,10 +33,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
32
33
  let(:view_str) { '{"celery":"man"}' }
33
34
 
34
35
  it 'automatically converts view into JSON' do
35
- expect(client).to receive(:post).with('views.publish',
36
- user_id: user_id,
37
- trigger_id: trigger_id,
38
- view: view_str)
36
+ expect(client).to receive(:post).with(
37
+ 'views.publish',
38
+ {
39
+ trigger_id: trigger_id,
40
+ user_id: user_id,
41
+ view: view_str
42
+ }
43
+ )
39
44
  client.views_publish(user_id: user_id, trigger_id: trigger_id, view: { celery: 'man' })
40
45
  end
41
46
  end
@@ -44,10 +49,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
44
49
  let(:view_str) { 'celery man' }
45
50
 
46
51
  it 'leaves view as is' do
47
- expect(client).to receive(:post).with('views.publish',
48
- user_id: user_id,
49
- trigger_id: trigger_id,
50
- view: view_str)
52
+ expect(client).to receive(:post).with(
53
+ 'views.publish',
54
+ {
55
+ user_id: user_id,
56
+ trigger_id: trigger_id,
57
+ view: view_str
58
+ }
59
+ )
51
60
  client.views_publish(user_id: user_id, trigger_id: trigger_id, view: 'celery man')
52
61
  end
53
62
  end
@@ -58,7 +67,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
58
67
  let(:view_str) { '{"celery":"man"}' }
59
68
 
60
69
  it 'automatically converts view into JSON' do
61
- expect(client).to receive(:post).with('views.push', trigger_id: trigger_id, view: view_str)
70
+ expect(client).to receive(:post).with('views.push', { trigger_id: trigger_id, view: view_str })
62
71
  client.views_push(trigger_id: trigger_id, view: { celery: 'man' })
63
72
  end
64
73
  end
@@ -67,7 +76,7 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
67
76
  let(:view_str) { 'celery man' }
68
77
 
69
78
  it 'leaves view as is' do
70
- expect(client).to receive(:post).with('views.push', trigger_id: trigger_id, view: view_str)
79
+ expect(client).to receive(:post).with('views.push', { trigger_id: trigger_id, view: view_str })
71
80
  client.views_push(trigger_id: trigger_id, view: 'celery man')
72
81
  end
73
82
  end
@@ -78,8 +87,8 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
78
87
  let(:view_str) { '{"celery":"man"}' }
79
88
 
80
89
  it 'automatically converts view into JSON' do
81
- expect(client).to receive(:post).with('views.update', view: view_str)
82
- client.views_update(view: { celery: 'man' })
90
+ expect(client).to receive(:post).with('views.update', { view_id: view_id, view: view_str })
91
+ client.views_update(view_id: view_id, view: { celery: 'man' })
83
92
  end
84
93
  end
85
94
 
@@ -87,8 +96,16 @@ RSpec.describe Slack::Web::Api::Endpoints::Views do
87
96
  let(:view_str) { 'celery man' }
88
97
 
89
98
  it 'leaves view as is' do
90
- expect(client).to receive(:post).with('views.update', view: view_str)
91
- client.views_update(view: 'celery man')
99
+ expect(client).to receive(:post).with('views.update', { view_id: view_id, view: view_str })
100
+ client.views_update(view_id: view_id, view: 'celery man')
101
+ end
102
+
103
+ context 'with both an external_id and view_id' do
104
+ it 'raises error' do
105
+ expect do
106
+ client.views_update(external_id: trigger_id, view_id: view_id, view: 'celery man')
107
+ end.to raise_error ArgumentError, 'One of :external_id, :view_id is required'
108
+ end
92
109
  end
93
110
  end
94
111
  end
@@ -5,6 +5,11 @@ require 'spec_helper'
5
5
 
6
6
  RSpec.describe Slack::Web::Api::Endpoints::Files do
7
7
  let(:client) { Slack::Web::Client.new }
8
+ context 'files_completeUploadExternal' do
9
+ it 'requires files' do
10
+ expect { client.files_completeUploadExternal }.to raise_error ArgumentError, /Required arguments :files missing/
11
+ end
12
+ end
8
13
  context 'files_delete' do
9
14
  it 'requires file' do
10
15
  expect { client.files_delete }.to raise_error ArgumentError, /Required arguments :file missing/
@@ -18,6 +23,14 @@ RSpec.describe Slack::Web::Api::Endpoints::Files do
18
23
  expect { client.files_edit(file: %q[F2147483862]) }.to raise_error ArgumentError, /Required arguments :title missing/
19
24
  end
20
25
  end
26
+ context 'files_getUploadURLExternal' do
27
+ it 'requires filename' do
28
+ expect { client.files_getUploadURLExternal(length: %q[]) }.to raise_error ArgumentError, /Required arguments :filename missing/
29
+ end
30
+ it 'requires length' do
31
+ expect { client.files_getUploadURLExternal(filename: %q[]) }.to raise_error ArgumentError, /Required arguments :length missing/
32
+ end
33
+ end
21
34
  context 'files_info' do
22
35
  it 'requires file' do
23
36
  expect { client.files_info }.to raise_error ArgumentError, /Required arguments :file missing/
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ # This file was auto-generated by lib/tasks/web.rake
3
+
4
+ require 'spec_helper'
5
+
6
+ RSpec.describe Slack::Web::Api::Endpoints::FunctionsWorkflowsStepsResponses do
7
+ let(:client) { Slack::Web::Client.new }
8
+ context 'functions.workflows.steps.responses_export' do
9
+ it 'requires step_id' do
10
+ expect { client.functions_workflows_steps_responses_export }.to raise_error ArgumentError, /Required arguments :step_id missing/
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ # This file was auto-generated by lib/tasks/web.rake
3
+
4
+ require 'spec_helper'
5
+
6
+ RSpec.describe Slack::Web::Api::Endpoints::FunctionsWorkflowsSteps do
7
+ let(:client) { Slack::Web::Client.new }
8
+ context 'functions.workflows.steps_list' do
9
+ it 'requires function_id' do
10
+ expect { client.functions_workflows_steps_list }.to raise_error ArgumentError, /Required arguments :function_id missing/
11
+ end
12
+ end
13
+ end
@@ -29,11 +29,13 @@ RSpec.describe Slack::Web::Api::Mixins::Conversations do
29
29
  eq('ok' => true, 'channel' => { 'id' => 'C123456' })
30
30
  )
31
31
  end
32
+
32
33
  it 'translates a channel that starts with a #' do
33
34
  expect(conversations.conversations_id(channel: '#general')).to(
34
35
  eq('ok' => true, 'channel' => { 'id' => 'CDEADBEEF' })
35
36
  )
36
37
  end
38
+
37
39
  it 'fails with an exception' do
38
40
  expect { conversations.conversations_id(channel: '#invalid') }.to(
39
41
  raise_error(Slack::Web::Api::Errors::SlackError, 'channel_not_found')
@@ -28,9 +28,11 @@ RSpec.describe Slack::Web::Api::Mixins::Users do
28
28
  it 'leaves users specified by ID alone' do
29
29
  expect(users.users_id(user: 'U123456')).to eq('ok' => true, 'user' => { 'id' => 'U123456' })
30
30
  end
31
+
31
32
  it 'translates a user that starts with a #' do
32
33
  expect(users.users_id(user: '@aws')).to eq('ok' => true, 'user' => { 'id' => 'UDEADBEEF' })
33
34
  end
35
+
34
36
  it 'fails with an exception' do
35
37
  expect { users.users_id(user: '@foo') }.to(
36
38
  raise_error(Slack::Web::Api::Errors::SlackError, 'user_not_found')
@@ -8,19 +8,22 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
8
8
  let(:cursor) { described_class.new(client, 'users_list', {}) }
9
9
 
10
10
  it 'provides a default limit' do
11
- expect(client).to receive(:users_list).with(limit: 100, cursor: nil)
11
+ expect(client).to receive(:users_list).with({ limit: 100, cursor: nil })
12
12
  cursor.first
13
13
  end
14
+
14
15
  it 'handles blank response metadata' do
15
16
  expect(client).to receive(:users_list).once.and_return(Slack::Messages::Message.new)
16
17
  cursor.to_a
17
18
  end
19
+
18
20
  it 'handles nil response metadata' do
19
21
  expect(client).to(
20
22
  receive(:users_list).once.and_return(Slack::Messages::Message.new(response_metadata: nil))
21
23
  )
22
24
  cursor.to_a
23
25
  end
26
+
24
27
  it 'paginates with a cursor inside response metadata' do
25
28
  expect(client).to receive(:users_list).twice.and_return(
26
29
  Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }),
@@ -29,6 +32,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
29
32
  expect(cursor).not_to receive(:sleep)
30
33
  cursor.to_a
31
34
  end
35
+
32
36
  context 'with rate limiting' do
33
37
  let(:error) { Slack::Web::Api::Errors::TooManyRequestsError.new(OpenStruct.new(headers: { 'retry-after' => 9 })) }
34
38
 
@@ -36,17 +40,17 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
36
40
  it 'sleeps after a TooManyRequestsError' do
37
41
  expect(client).to(
38
42
  receive(:users_list)
39
- .with(limit: 100, cursor: nil)
43
+ .with({ limit: 100, cursor: nil })
40
44
  .ordered
41
45
  .and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
42
46
  )
43
47
  expect(client).to(
44
- receive(:users_list).with(limit: 100, cursor: 'next').ordered.and_raise(error)
48
+ receive(:users_list).with({ limit: 100, cursor: 'next' }).ordered.and_raise(error)
45
49
  )
46
50
  expect(cursor).to receive(:sleep).once.ordered.with(9)
47
51
  expect(client).to(
48
52
  receive(:users_list)
49
- .with(limit: 100, cursor: 'next')
53
+ .with({ limit: 100, cursor: 'next' })
50
54
  .ordered
51
55
  .and_return(Slack::Messages::Message.new)
52
56
  )
@@ -60,11 +64,11 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
60
64
  it 'raises the error after hitting the max retries' do
61
65
  expect(client).to(
62
66
  receive(:users_list)
63
- .with(limit: 100, cursor: nil)
67
+ .with({ limit: 100, cursor: nil })
64
68
  .and_return(Slack::Messages::Message.new(response_metadata: { next_cursor: 'next' }))
65
69
  )
66
70
  expect(client).to(
67
- receive(:users_list).with(limit: 100, cursor: 'next').exactly(5).times.and_raise(error)
71
+ receive(:users_list).with({ limit: 100, cursor: 'next' }).exactly(5).times.and_raise(error)
68
72
  )
69
73
  expect(cursor).to receive(:sleep).exactly(4).times.with(9)
70
74
  expect { cursor.to_a }.to raise_error(error)
@@ -77,7 +81,7 @@ RSpec.describe Slack::Web::Api::Pagination::Cursor do
77
81
  let(:cursor) { described_class.new(client, 'users_list', limit: 42) }
78
82
 
79
83
  it 'overrides default limit' do
80
- expect(client).to receive(:users_list).with(limit: 42, cursor: nil)
84
+ expect(client).to receive(:users_list).with({ limit: 42, cursor: nil })
81
85
  cursor.first
82
86
  end
83
87
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'spec_helper'
3
+ require 'faraday/typhoeus'
3
4
 
4
5
  RSpec.describe Slack::Web::Client do
5
6
  before do
@@ -14,6 +15,7 @@ RSpec.describe Slack::Web::Client do
14
15
  expect(client.user_agent).to eq Slack::Web::Config.user_agent
15
16
  expect(client.user_agent).to include Slack::VERSION
16
17
  end
18
+
17
19
  (Slack::Web::Config::ATTRIBUTES - [:logger]).each do |key|
18
20
  it "sets #{key}" do
19
21
  expect(client.send(key)).to eq Slack::Web::Config.send(key)
@@ -55,6 +57,7 @@ RSpec.describe Slack::Web::Client do
55
57
  it 'sets user-agent' do
56
58
  expect(client.user_agent).to eq 'custom/user-agent'
57
59
  end
60
+
58
61
  it 'creates a connection with the custom user-agent' do
59
62
  expect(client.send(:connection).headers).to eq(
60
63
  'Accept' => 'application/json; charset=utf-8',
@@ -75,6 +78,7 @@ RSpec.describe Slack::Web::Client do
75
78
  client = described_class.new
76
79
  expect(client.token).to eq 'global default'
77
80
  end
81
+
78
82
  context 'with web config' do
79
83
  before do
80
84
  described_class.configure do |config|
@@ -86,6 +90,7 @@ RSpec.describe Slack::Web::Client do
86
90
  client = described_class.new
87
91
  expect(client.token).to eq 'custom web token'
88
92
  end
93
+
89
94
  it 'overrides token to specific token' do
90
95
  client = described_class.new(token: 'local token')
91
96
  expect(client.token).to eq 'local token'
@@ -104,6 +109,7 @@ RSpec.describe Slack::Web::Client do
104
109
  it 'sets proxy' do
105
110
  expect(client.proxy).to eq 'http://localhost:8080'
106
111
  end
112
+
107
113
  it 'creates a connection with the proxy' do
108
114
  expect(client.send(:connection).proxy.uri.to_s).to eq 'http://localhost:8080'
109
115
  end
@@ -123,6 +129,7 @@ RSpec.describe Slack::Web::Client do
123
129
  expect(client.ca_path).to eq '/ca_path'
124
130
  expect(client.ca_file).to eq '/ca_file'
125
131
  end
132
+
126
133
  it 'creates a connection with ssl options' do
127
134
  ssl = client.send(:connection).ssl
128
135
  expect(ssl.ca_path).to eq '/ca_path'
@@ -144,6 +151,7 @@ RSpec.describe Slack::Web::Client do
144
151
  it 'sets logger' do
145
152
  expect(client.logger).to eq logger
146
153
  end
154
+
147
155
  it 'creates a connection with a logger' do
148
156
  expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger
149
157
  end
@@ -167,6 +175,7 @@ RSpec.describe Slack::Web::Client do
167
175
  it 'sets adapter' do
168
176
  expect(client.adapter).to eq adapter
169
177
  end
178
+
170
179
  it 'creates a connection with an adapter' do
171
180
  expect(client.send(:connection).adapter).to eq adapter_class
172
181
  end
@@ -187,6 +196,7 @@ RSpec.describe Slack::Web::Client do
187
196
  it 'sets adapter' do
188
197
  expect(client.adapter).to eq adapter
189
198
  end
199
+
190
200
  it 'creates a connection with an adapter' do
191
201
  expect(client.send(:connection).adapter).to eq adapter_class
192
202
  end
@@ -207,6 +217,7 @@ RSpec.describe Slack::Web::Client do
207
217
  expect(client.timeout).to eq 10
208
218
  expect(client.open_timeout).to eq 15
209
219
  end
220
+
210
221
  it 'creates a connection with timeout options' do
211
222
  conn = client.send(:connection)
212
223
  expect(conn.options.timeout).to eq 10
@@ -216,16 +227,16 @@ RSpec.describe Slack::Web::Client do
216
227
  end
217
228
 
218
229
  context 'per-request options' do
219
- it 'applies timeout', vcr: { cassette_name: 'web/rtm_start', allow_playback_repeats: true } do
230
+ it 'applies timeout', vcr: { cassette_name: 'web/rtm_connect', allow_playback_repeats: true } do
220
231
  # reuse the same connection for the test, otherwise it creates a new one every time
221
232
  conn = client.send(:connection)
222
233
  expect(client).to receive(:connection).and_return(conn)
223
234
 
224
235
  # get the yielded request to reuse in the next call to
225
- # rtm_start so that we can examine request.options later
236
+ # rtm.connect so that we can examine request.options later
226
237
  request = nil
227
238
  response = conn.post do |r|
228
- r.path = 'rtm.start'
239
+ r.path = 'rtm.connect'
229
240
  r.headers = {
230
241
  'Accept' => ['application/json; charset=utf-8'],
231
242
  'Authorization' => ['Bearer <SLACK_API_TOKEN>']
@@ -235,7 +246,7 @@ RSpec.describe Slack::Web::Client do
235
246
 
236
247
  expect(conn).to receive(:post).and_yield(request).and_return(response)
237
248
 
238
- client.rtm_start(request: { timeout: 3 })
249
+ client.rtm_connect(request: { timeout: 3 })
239
250
 
240
251
  expect(request.options.timeout).to eq 3
241
252
  end
@@ -275,13 +286,28 @@ RSpec.describe Slack::Web::Client do
275
286
  end
276
287
 
277
288
  context 'parsing error' do
278
- before { stub_slack_request.to_return(body: '<html></html>') }
289
+ context 'when the response is not JSON' do
290
+ before do
291
+ stub_slack_request.to_return(body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
292
+ end
293
+
294
+ it 'raises ParsingError' do
295
+ expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
296
+ expect(exception.response.body).to eq('<html></html>')
297
+ expect(exception.cause).to be_a(Faraday::ParsingError)
298
+ expect(exception.cause.cause).to be_a(JSON::ParserError)
299
+ end
300
+ end
301
+
302
+ context 'when the response is malformed JSON' do
303
+ before { stub_slack_request.to_return(body: '{') }
279
304
 
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)
305
+ it 'raises ParsingError' do
306
+ expect { request }.to raise_error(Slack::Web::Api::Errors::ParsingError).with_message('parsing_error')
307
+ expect(exception.response.body).to eq('{')
308
+ expect(exception.cause).to be_a(Faraday::ParsingError)
309
+ expect(exception.cause.cause).to be_a(JSON::ParserError)
310
+ end
285
311
  end
286
312
  end
287
313
 
@@ -318,7 +344,9 @@ RSpec.describe Slack::Web::Client do
318
344
  end
319
345
 
320
346
  context 'with a HTML response' do
321
- before { stub_slack_request.to_return(status: 500, body: '<html></html>') }
347
+ before do
348
+ stub_slack_request.to_return(status: 500, body: '<html></html>', headers: { 'Content-Type' => 'text/html' })
349
+ end
322
350
 
323
351
  it 'raises UnavailableError' do
324
352
  expect { request }.to raise_error(Slack::Web::Api::Errors::UnavailableError).with_message('unavailable_error')