slack-ruby-client 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b4523b02fb8e41e2a529f21283e9631aca6e04bb
4
- data.tar.gz: 6324f7a54941b201b7aa729178418241accf836c
2
+ SHA256:
3
+ metadata.gz: 488002a6ea8cb58f2aeb4e21d5008c47fae73f4d6c6d8d9930a324f1b24492dd
4
+ data.tar.gz: b05b1307ff8f64000eccecf83b7cf818bcebcace33c1e3232691680c109a562d
5
5
  SHA512:
6
- metadata.gz: 958f43b8c6c3591d81761e60c310c6cf2638b26ab79b9bf56748768a2e8800fdad85733262c5a93d4272b3861f475b2cbb2f1eabb01fadb3a2848a09c82be3d7
7
- data.tar.gz: 1787862cbf85c3cd762c8b044afd89d98c92ee0cd959aaf94da5b5d513cd3c24c3d8de005eece992a5f13ed76a8279231d40d8ade39dd32c4efe692c9118b79c
6
+ metadata.gz: 4beafc46990017ebe15b2860f7f601968fc0df6cf195e3b5a79fa173e59b4d8f34dbc4fe29c969b3be545d7b1c15046589d4446560ce6d032aaaa6ecd6b0e3bc
7
+ data.tar.gz: e2acea4de6fe0d5517cc8294c6712f4bea8aa35aec9630b1a8c6f7c3144d78a36063a8ec59f91c0fbc73c0c7dd96be582a7ba656872298dc81ed1a03c1dc87fd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.11.1 (1/23/2017)
2
+
3
+ * [#187](https://github.com/slack-ruby/slack-ruby-client/pull/187): Concatenate error message when multiple errors present - [@chrislopresto](https://github.com/chrislopresto).
4
+ * [#188](https://github.com/slack-ruby/slack-ruby-client/pull/188): Fixed `NoMethodError` when Slack is unavailable - [@sonicdoe](https://github.com/sonicdoe).
5
+ * [#196](https://github.com/slack-ruby/slack-ruby-client/pull/196): Added `users_lookupByEmail` - [@manuelmeurer](https://github.com/manuelmeurer).
6
+ * [#185](https://github.com/slack-ruby/slack-ruby-client/pull/185): Calling undocumented endpoints will now produce a warning - [@aviflombaum](https://github.com/aviflombaum).
7
+
1
8
  ### 0.11.0 (11/25/2017)
2
9
 
3
10
  * [#173](https://github.com/slack-ruby/slack-ruby-client/issues/173): Added dialog support - [@alexagranov](https://github.com/alexagranov).
data/README.md CHANGED
@@ -18,7 +18,7 @@ A Ruby client for the Slack [Web](https://api.slack.com/web) and [RealTime Messa
18
18
 
19
19
  ## Stable Release
20
20
 
21
- You're reading the documentation for the **stable** release of slack-ruby-client, 0.11.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
21
+ You're reading the documentation for the **next** release of slack-ruby-client. Please see the documentation for the [last stable release, v0.11.1](https://github.com/slack-ruby/slack-ruby-client/blob/v0.11.1/README.md) unless you're integrating with HEAD. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
22
22
 
23
23
  ## Installation
24
24
 
@@ -184,6 +184,10 @@ You can also pass request options, including `timeout` and `open_timeout` into i
184
184
  client.channels_list(request: { timeout: 180 })
185
185
  ```
186
186
 
187
+ You can also control what proxy options are used by modifying the `http_proxy` environment variable per [Net::HTTP's documentation](https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html#class-Net::HTTP-label-Proxies).
188
+
189
+ Note that Docker on OSX seems to incorrectly set the proxy, causing `Faraday::ConnectionFailed, ERROR -- : Failed to open TCP connection to : (getaddrinfo: Name or service not known)`. You might need to manually unset `http_proxy` in that case, eg. `http_proxy="" bundle exec ruby ./my_bot.rb`.
190
+
187
191
  #### Pagination Support
188
192
 
189
193
  The Web client natively supports [cursor pagination](https://api.slack.com/docs/pagination#cursors) for methods that allow it, such as `users_list`. Supply a block and the client will make repeated requests adjusting the value of `cursor` with every response. The default limit is set to 100 and can be adjusted via `Slack::Web::Client.config.default_page_size` or by passing it directly into the API call.
@@ -210,6 +214,14 @@ end
210
214
  all_members # many thousands of team members retrieved 10 at a time
211
215
  ```
212
216
 
217
+ #### Error Handling
218
+
219
+ If a request fails, a `Slack::Web::Api::Errors::SlackError` will be raised. The error message contains the error code. In case of multiple errors, the error codes are separated by commas. The original response is also accessible using the `response` attribute.
220
+
221
+ If you exceed [Slack’s rate limits](https://api.slack.com/docs/rate-limits), a `Slack::Web::Api::Errors::TooManyRequestsError` will be raised instead.
222
+
223
+ In any other case, a `Faraday::ClientError` will be raised. This may be the case if Slack is temporarily unavailable, for example.
224
+
213
225
  ### RealTime Client
214
226
 
215
227
  The Real Time Messaging API is a WebSocket-based API that allows you to receive events from Slack in real time and send messages as user.
@@ -35,6 +35,7 @@ command 'conversations' do |g|
35
35
  g.command 'history' do |c|
36
36
  c.flag 'channel', desc: 'Conversation ID to fetch history for.'
37
37
  c.flag 'cursor', desc: "Paginate through collections of data by setting the cursor parameter to a next_cursor attribute returned by a previous request's response_metadata. Default value fetches the first 'page' of the collection. See pagination for more detail."
38
+ c.flag 'inclusive', desc: 'Include messages with latest or oldest timestamp in results only when either timestamp is specified.'
38
39
  c.flag 'latest', desc: 'End of time range of messages to include in results.'
39
40
  c.flag 'limit', desc: "The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached."
40
41
  c.flag 'oldest', desc: 'Start of time range of messages to include in results.'
@@ -141,7 +142,10 @@ command 'conversations' do |g|
141
142
  c.flag 'channel', desc: 'Conversation ID to fetch thread from.'
142
143
  c.flag 'ts', desc: "Unique identifier of a thread's parent message."
143
144
  c.flag 'cursor', desc: "Paginate through collections of data by setting the cursor parameter to a next_cursor attribute returned by a previous request's response_metadata. Default value fetches the first 'page' of the collection. See pagination for more detail."
145
+ c.flag 'inclusive', desc: 'Include messages with latest or oldest timestamp in results only when either timestamp is specified.'
146
+ c.flag 'latest', desc: 'End of time range of messages to include in results.'
144
147
  c.flag 'limit', desc: "The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached."
148
+ c.flag 'oldest', desc: 'Start of time range of messages to include in results.'
145
149
  c.action do |_global_options, options, _args|
146
150
  puts JSON.dump($client.conversations_replies(options))
147
151
  end
@@ -52,12 +52,21 @@ command 'users' do |g|
52
52
  c.flag 'cursor', desc: "Paginate through collections of data by setting the cursor parameter to a next_cursor attribute returned by a previous request's response_metadata. Default value fetches the first 'page' of the collection. See pagination for more detail."
53
53
  c.flag 'include_locale', desc: 'Set this to true to receive the locale for users. Defaults to false.'
54
54
  c.flag 'limit', desc: "The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached."
55
- c.flag 'presence', desc: 'Whether to include presence data in the output. Setting this to false improves performance, especially with large teams.'
55
+ c.flag 'presence', desc: 'Whether to include presence data in the output. Defaults to false. Setting this to true reduces performance, especially with large teams.'
56
56
  c.action do |_global_options, options, _args|
57
57
  puts JSON.dump($client.users_list(options))
58
58
  end
59
59
  end
60
60
 
61
+ g.desc 'Find a user with an email address.'
62
+ g.long_desc %( Find a user with an email address. )
63
+ g.command 'lookupByEmail' do |c|
64
+ c.flag 'email', desc: 'An email address belonging to a user in the workspace.'
65
+ c.action do |_global_options, options, _args|
66
+ puts JSON.dump($client.users_lookupByEmail(options))
67
+ end
68
+ end
69
+
61
70
  g.desc 'This method searches for users.'
62
71
  g.long_desc %( This method searches for users. )
63
72
  g.command 'search' do |c|
data/lib/slack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = '0.11.0'.freeze
2
+ VERSION = '0.11.1'.freeze
3
3
  end
@@ -41,6 +41,7 @@ module Slack
41
41
  def channels_delete(options = {})
42
42
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
43
43
  options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
44
+ logger.warn('The channels.delete method is undocumented.')
44
45
  post('channels.delete', options)
45
46
  end
46
47
 
@@ -19,6 +19,7 @@ module Slack
19
19
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
20
20
  throw ArgumentError.new('Required arguments :command missing') if options[:command].nil?
21
21
  options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
22
+ logger.warn('The chat.command method is undocumented.')
22
23
  post('chat.command', options)
23
24
  end
24
25
 
@@ -52,6 +52,8 @@ module Slack
52
52
  # Conversation ID to fetch history for.
53
53
  # @option options [Object] :cursor
54
54
  # Paginate through collections of data by setting the cursor parameter to a next_cursor attribute returned by a previous request's response_metadata. Default value fetches the first "page" of the collection. See pagination for more detail.
55
+ # @option options [Object] :inclusive
56
+ # Include messages with latest or oldest timestamp in results only when either timestamp is specified.
55
57
  # @option options [timestamp] :latest
56
58
  # End of time range of messages to include in results.
57
59
  # @option options [Object] :limit
@@ -233,8 +235,14 @@ module Slack
233
235
  # Unique identifier of a thread's parent message.
234
236
  # @option options [Object] :cursor
235
237
  # Paginate through collections of data by setting the cursor parameter to a next_cursor attribute returned by a previous request's response_metadata. Default value fetches the first "page" of the collection. See pagination for more detail.
238
+ # @option options [Object] :inclusive
239
+ # Include messages with latest or oldest timestamp in results only when either timestamp is specified.
240
+ # @option options [timestamp] :latest
241
+ # End of time range of messages to include in results.
236
242
  # @option options [Object] :limit
237
243
  # The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached.
244
+ # @option options [timestamp] :oldest
245
+ # Start of time range of messages to include in results.
238
246
  # @see https://api.slack.com/methods/conversations.replies
239
247
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/conversations/conversations.replies.json
240
248
  def conversations_replies(options = {})
@@ -30,6 +30,7 @@ module Slack
30
30
  def files_edit(options = {})
31
31
  throw ArgumentError.new('Required arguments :file missing') if options[:file].nil?
32
32
  throw ArgumentError.new('Required arguments :title missing') if options[:title].nil?
33
+ logger.warn('The files.edit method is undocumented.')
33
34
  post('files.edit', options)
34
35
  end
35
36
 
@@ -102,6 +103,7 @@ module Slack
102
103
  throw ArgumentError.new('Required arguments :file missing') if options[:file].nil?
103
104
  throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
104
105
  options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
106
+ logger.warn('The files.share method is undocumented.')
105
107
  post('files.share', options)
106
108
  end
107
109
 
@@ -61,7 +61,7 @@ module Slack
61
61
  # @option options [Object] :limit
62
62
  # The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached.
63
63
  # @option options [Object] :presence
64
- # Whether to include presence data in the output. Setting this to false improves performance, especially with large teams.
64
+ # Whether to include presence data in the output. Defaults to false. Setting this to true reduces performance, especially with large teams.
65
65
  # @see https://api.slack.com/methods/users.list
66
66
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.list.json
67
67
  def users_list(options = {})
@@ -74,6 +74,18 @@ module Slack
74
74
  end
75
75
  end
76
76
 
77
+ #
78
+ # Find a user with an email address.
79
+ #
80
+ # @option options [Object] :email
81
+ # An email address belonging to a user in the workspace.
82
+ # @see https://api.slack.com/methods/users.lookupByEmail
83
+ # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.lookupByEmail.json
84
+ def users_lookupByEmail(options = {})
85
+ throw ArgumentError.new('Required arguments :email missing') if options[:email].nil?
86
+ post('users.lookupByEmail', options)
87
+ end
88
+
77
89
  #
78
90
  # Marks a user as active.
79
91
  #
@@ -25,6 +25,7 @@ module Slack
25
25
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/undocumented/users.admin/users.admin.invite.json
26
26
  def users_admin_invite(options = {})
27
27
  throw ArgumentError.new('Required arguments :email missing') if options[:email].nil?
28
+ logger.warn('The users.admin.invite method is undocumented.')
28
29
  post('users.admin.invite', options)
29
30
  end
30
31
 
@@ -37,6 +38,7 @@ module Slack
37
38
  def users_admin_setInactive(options = {})
38
39
  throw ArgumentError.new('Required arguments :user missing') if options[:user].nil?
39
40
  options = options.merge(user: users_id(options)['user']['id']) if options[:user]
41
+ logger.warn('The users.admin.setInactive method is undocumented.')
40
42
  post('users.admin.setInactive', options)
41
43
  end
42
44
  end
@@ -10,6 +10,7 @@ module Slack
10
10
  #
11
11
  # @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/undocumented/users.prefs/users.prefs.get.json
12
12
  def users_prefs_get(options = {})
13
+ logger.warn('The users.prefs.get method is undocumented.')
13
14
  post('users.prefs.get', options)
14
15
  end
15
16
  end
@@ -44,6 +44,9 @@ module Slack
44
44
  <% if data['args']['user'] %>
45
45
  options = options.merge(user: users_id(options)['user']['id']) if options[:user]
46
46
  <% end %>
47
+ <% if data['undocumented'] %>
48
+ logger.warn('The <%= group %>.<%= name %> method is undocumented.')
49
+ <% end %>
47
50
  <% if data['args'].keys.include?('cursor') %>
48
51
  if block_given?
49
52
  Pagination::Cursor.new(self, :<%= group.gsub(".", "_") %>_<%= name %>, options).each do |page|
@@ -6,10 +6,9 @@ module Slack
6
6
  def on_complete(env)
7
7
  if env.status == 429
8
8
  raise Slack::Web::Api::Errors::TooManyRequestsError, env.response
9
- elsif (body = env.body) && body['ok']
10
- nil
11
- else
12
- raise Slack::Web::Api::Errors::SlackError.new(body['error'], env.response)
9
+ elsif (body = env.body) && !body['ok']
10
+ error_message = body['error'] || body['errors'].map { |message| message['error'] }.join(',')
11
+ raise Slack::Web::Api::Errors::SlackError.new(error_message, env.response)
13
12
  end
14
13
  end
15
14
  end
@@ -0,0 +1,14 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://slack.com/api/auth.test
6
+ response:
7
+ status:
8
+ code: 503
9
+ message: Service Unavailable
10
+ body:
11
+ encoding: US-ASCII
12
+ string: ''
13
+ http_version:
14
+ recorded_at: Thu, 30 Nov 2017 14:36:26 GMT
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Client do
4
+ let(:client) { Slack::Web::Client.new }
5
+ it 'raises a Faraday::ClientError when Slack is unavailable', vcr: { cassette_name: 'web/503_error' } do
6
+ begin
7
+ client.auth_test
8
+ raise 'Expected to receive Faraday::ClientError.'
9
+ rescue Faraday::ClientError => e
10
+ expect(e.response).to_not be_nil
11
+ expect(e.response[:status]).to eq 503
12
+ end
13
+ end
14
+ end
@@ -170,5 +170,13 @@ RSpec.describe Slack::Web::Client do
170
170
  expect(request.options.timeout).to eq 3
171
171
  end
172
172
  end
173
+ context 'calling undocumented methods' do
174
+ let(:client) { Slack::Web::Client.new }
175
+ it 'produces a warning' do
176
+ expect(client.logger).to receive(:warn).with('The users.admin.setInactive method is undocumented.')
177
+ expect(client).to receive(:post)
178
+ client.users_admin_setInactive(user: 'U092BDCLV')
179
+ end
180
+ end
173
181
  end
174
182
  end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Slack::Web::Faraday::Response::RaiseError do
4
+ describe '#on_complete' do
5
+ let(:subject) { described_class.new }
6
+ let(:status) { 200 }
7
+ let(:response) { nil }
8
+ let(:body) { {} }
9
+ let(:env) { double status: status, response: response, body: body }
10
+
11
+ context 'with status of 429' do
12
+ let(:status) { 429 }
13
+
14
+ it 'raises a TooManyRequestsError' do
15
+ expect { subject.on_complete(env) }.to raise_error(Slack::Web::Api::Errors::TooManyRequestsError)
16
+ end
17
+ end
18
+
19
+ context 'with an ok payload in the body' do
20
+ let(:body) { { 'ok' => 'true' } }
21
+
22
+ it 'is nil' do
23
+ expect(subject.on_complete(env)).to eq nil
24
+ end
25
+ end
26
+
27
+ context 'with a single error in the body' do
28
+ let(:body) { { 'error' => 'already_in_channel' } }
29
+
30
+ it 'raises a SlackError with the error message' do
31
+ expect { subject.on_complete(env) }.to raise_error(Slack::Web::Api::Errors::SlackError, 'already_in_channel')
32
+ end
33
+ end
34
+
35
+ context 'with multiple errors in the body' do
36
+ let(:body) do
37
+ {
38
+ 'errors' => [
39
+ { 'error' => 'already_in_channel' },
40
+ { 'error' => 'something_else_terrible' }
41
+ ]
42
+ }
43
+ end
44
+
45
+ it 'raises a SlackError with the concatenated error messages' do
46
+ expect { subject.on_complete(env) }.to raise_error(Slack::Web::Api::Errors::SlackError, 'already_in_channel,something_else_terrible')
47
+ end
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-25 00:00:00.000000000 Z
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -368,6 +368,7 @@ files:
368
368
  - slack-ruby-client.gemspec
369
369
  - slack.png
370
370
  - spec/fixtures/slack/web/429_error.yml
371
+ - spec/fixtures/slack/web/503_error.yml
371
372
  - spec/fixtures/slack/web/auth_test_error.yml
372
373
  - spec/fixtures/slack/web/auth_test_success.yml
373
374
  - spec/fixtures/slack/web/channels_info.yml
@@ -431,12 +432,14 @@ files:
431
432
  - spec/slack/web/api/endpoints/users_prefs_spec.rb
432
433
  - spec/slack/web/api/endpoints/users_profile_spec.rb
433
434
  - spec/slack/web/api/error_spec.rb
435
+ - spec/slack/web/api/errors/service_unavailable_spec.rb
434
436
  - spec/slack/web/api/errors/slack_error_spec.rb
435
437
  - spec/slack/web/api/mixins/channels_spec.rb
436
438
  - spec/slack/web/api/mixins/groups_spec.rb
437
439
  - spec/slack/web/api/mixins/users_spec.rb
438
440
  - spec/slack/web/api/pagination/cursor_spec.rb
439
441
  - spec/slack/web/client_spec.rb
442
+ - spec/slack/web/faraday/response/raise_error_spec.rb
440
443
  - spec/spec_helper.rb
441
444
  - spec/support/queue_with_timeout.rb
442
445
  - spec/support/real_time/concurrency/mock.rb
@@ -464,12 +467,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
464
467
  version: 1.3.6
465
468
  requirements: []
466
469
  rubyforge_project:
467
- rubygems_version: 2.6.12
470
+ rubygems_version: 2.7.4
468
471
  signing_key:
469
472
  specification_version: 4
470
473
  summary: Slack Web and RealTime API client.
471
474
  test_files:
472
475
  - spec/fixtures/slack/web/429_error.yml
476
+ - spec/fixtures/slack/web/503_error.yml
473
477
  - spec/fixtures/slack/web/auth_test_error.yml
474
478
  - spec/fixtures/slack/web/auth_test_success.yml
475
479
  - spec/fixtures/slack/web/channels_info.yml
@@ -533,12 +537,14 @@ test_files:
533
537
  - spec/slack/web/api/endpoints/users_prefs_spec.rb
534
538
  - spec/slack/web/api/endpoints/users_profile_spec.rb
535
539
  - spec/slack/web/api/error_spec.rb
540
+ - spec/slack/web/api/errors/service_unavailable_spec.rb
536
541
  - spec/slack/web/api/errors/slack_error_spec.rb
537
542
  - spec/slack/web/api/mixins/channels_spec.rb
538
543
  - spec/slack/web/api/mixins/groups_spec.rb
539
544
  - spec/slack/web/api/mixins/users_spec.rb
540
545
  - spec/slack/web/api/pagination/cursor_spec.rb
541
546
  - spec/slack/web/client_spec.rb
547
+ - spec/slack/web/faraday/response/raise_error_spec.rb
542
548
  - spec/spec_helper.rb
543
549
  - spec/support/queue_with_timeout.rb
544
550
  - spec/support/real_time/concurrency/mock.rb