slack-ruby-client 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c6d144362dda5a6aeaa3beeb8ec0e1885061898
4
- data.tar.gz: e6d9ec22b44554a6f5d89fdbcc794effcef152a1
3
+ metadata.gz: 1cc706e591e468957eef12d0ea962b1a8273f9ce
4
+ data.tar.gz: edfcbef27ea25566be7342d61d213cb6bc4c651e
5
5
  SHA512:
6
- metadata.gz: 0f5e30d233a1cd645a672715856bbf3300533e473c1c51f6b3181def7ee6614dfc3ea46f3dcf721614a78f1a6c4720c852f934a0ace4462f07dd20dae1ddebb8
7
- data.tar.gz: bbf97b47897ba11828defcba59189fb84a9824b3f8e39556b42d0c6da9313c85f89dad822fc6fb329a4a59efe4ce850fe11f69b8a60ba5a00a180a8d7f770d59
6
+ metadata.gz: 3c768313646d77b02ff5284daa7b58f413e48b37c6c72dd33b3eb39645d19c54c863e67fb1beb6a31eb11ed6047c013ad19ec0959b6546d3de94378925071834
7
+ data.tar.gz: 8739d5a2f3824770e003b3f9d274391e278dfa19ca21592b9ce3908371807fb1add7252e19d8074302f5db264c8894163f77853d1269a732483374dd9c4262f6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.8.1 (4/28/2017)
2
+
3
+ * Added `exclude_members` option to `channels_list` Web API - [@dblock](https://github.com/dblock).
4
+ * Added `chat_unfurl` to Web API - [@dblock](https://github.com/dblock).
5
+ * Added `rtm_connect` to RTM API - [@dblock](https://github.com/dblock).
6
+ * Added `no_latest` support to `rm_start` RTM API - [@dblock](https://github.com/dblock).
7
+
1
8
  ### 0.8.0 (3/12/2017)
2
9
 
3
10
  * [#135](https://github.com/slack-ruby/slack-ruby-client/issues/135): Added `timeout` and `open_timeout` options to Web API - [@dblock](https://github.com/dblock).
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.8.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
21
+ You're reading the documentation for the **stable** release of slack-ruby-client, 0.8.1. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
22
22
 
23
23
  ## Installation
24
24
 
data/RELEASING.md CHANGED
@@ -13,12 +13,7 @@ rake
13
13
 
14
14
  Check that the last build succeeded in [Travis CI](https://travis-ci.org/slack-ruby/slack-ruby-client) for all supported platforms.
15
15
 
16
- Increment the version, modify [lib/slack/version.rb](lib/slack/version.rb).
17
-
18
- * Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.2.1` to `0.2.2`).
19
- * Increment the second number if the release contains major features or breaking API changes (eg. change `0.2.1` to `0.3.0`).
20
-
21
- Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
16
+ Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date.
22
17
 
23
18
  ```
24
19
  ### 0.2.2 (7/10/2015)
@@ -26,12 +21,18 @@ Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
26
21
 
27
22
  Remove the line with "Your contribution here.", since there will be no more contributions to this release.
28
23
 
29
- Remove the "Stable Release" section in README that warns users that they are reading the documentation for an unreleased version.
24
+ Change `**next**` in the "Stable Release" section in README that warns users that they are reading the documentation for an unreleased version with `**stable**`.
25
+
26
+ ```
27
+ ## Stable Release
28
+
29
+ You're reading the documentation for the **stable** release of slack-ruby-client, 0.2.2. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
30
+ ```
30
31
 
31
32
  Commit your changes.
32
33
 
33
34
  ```
34
- git add README.md CHANGELOG.md lib/slack/version.rb
35
+ git add README.md CHANGELOG.md
35
36
  git commit -m "Preparing for release, 0.2.2."
36
37
  git push origin master
37
38
  ```
@@ -52,18 +53,25 @@ Pushed slack-ruby-client 0.2.2 to rubygems.org.
52
53
  Add the next release to [CHANGELOG.md](CHANGELOG.md).
53
54
 
54
55
  ```
55
- Next Release
56
- ============
56
+ ### 0.2.3 (Next)
57
57
 
58
58
  * Your contribution here.
59
59
  ```
60
60
 
61
61
  Increment the third version number in [lib/slack/version.rb](lib/slack/version.rb).
62
62
 
63
+ Undo your change in README about the stable release.
64
+
65
+ ```
66
+ ## Stable Release
67
+
68
+ You're reading the documentation for the **next** release of slack-ruby-client. Please see the documentation for the [last stable release, v0.2.2](https://github.com/slack-ruby/slack-ruby-client/blob/v0.2.2/README.md) unless you're integrating with HEAD. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
69
+ ```
70
+
63
71
  Commit your changes.
64
72
 
65
73
  ```
66
- git add CHANGELOG.md lib/slack/version.rb
74
+ git add README.md CHANGELOG.md lib/slack/version.rb
67
75
  git commit -m "Preparing for next development iteration, 0.2.3."
68
76
  git push origin master
69
77
  ```
@@ -85,7 +85,8 @@ command 'channels' do |g|
85
85
  g.desc 'This method returns a list of all channels in the team. This includes channels the caller is in, channels they are not currently in, and archived channels but does not include private channels. The number of (non-deactivated) members in each channel is also returned.'
86
86
  g.long_desc %( This method returns a list of all channels in the team. This includes channels the caller is in, channels they are not currently in, and archived channels but does not include private channels. The number of (non-deactivated) members in each channel is also returned. )
87
87
  g.command 'list' do |c|
88
- c.flag 'exclude_archived', desc: "Don't return archived channels."
88
+ c.flag 'exclude_archived', desc: 'Exclude archived channels from the list.'
89
+ c.flag 'exclude_members', desc: 'Exclude the members collection from each channel.'
89
90
  c.action do |_global_options, options, _args|
90
91
  puts JSON.dump($client.channels_list(options))
91
92
  end
data/bin/commands/chat.rb CHANGED
@@ -44,6 +44,18 @@ command 'chat' do |g|
44
44
  end
45
45
  end
46
46
 
47
+ g.desc 'This method attaches Slack app unfurl behavior to a specified and relevant message. A user token is required as this method does not support bot user tokens.'
48
+ g.long_desc %( This method attaches Slack app unfurl behavior to a specified and relevant message. A user token is required as this method does not support bot user tokens. )
49
+ g.command 'unfurl' do |c|
50
+ c.flag 'channel', desc: 'Channel ID of the message.'
51
+ c.flag 'ts', desc: 'Timestamp of the message to add unfurl behavior to.'
52
+ c.flag 'unfurls', desc: 'JSON mapping a set of URLs from the message to their unfurl attachments.'
53
+ c.flag 'user_auth_required', desc: 'Set to true or 1 to indicate the user must install your Slack app to trigger unfurls for this domain.'
54
+ c.action do |_global_options, options, _args|
55
+ puts JSON.dump($client.chat_unfurl(options))
56
+ end
57
+ end
58
+
47
59
  g.desc 'This method updates a message in a channel. Though related to chat.postMessage, some parameters of chat.update are handled differently.'
48
60
  g.long_desc %( This method updates a message in a channel. Though related to chat.postMessage, some parameters of chat.update are handled differently. )
49
61
  g.command 'update' do |c|
data/bin/commands/rtm.rb CHANGED
@@ -2,12 +2,21 @@
2
2
 
3
3
  desc 'Rtm methods.'
4
4
  command 'rtm' do |g|
5
- g.desc 'This method starts a Real Time Messaging API session. Refer to the'
6
- g.long_desc %( This method starts a Real Time Messaging API session. Refer to the RTM API documentation for full details on how to use the RTM API. )
5
+ g.desc 'This method begins a Real Time Messaging API session and reserves your application a specific URL with which to connect via websocket.'
6
+ g.long_desc %( This method begins a Real Time Messaging API session and reserves your application a specific URL with which to connect via websocket. )
7
+ g.command 'connect' do |c|
8
+ c.action do |_global_options, options, _args|
9
+ puts JSON.dump($client.rtm_connect(options))
10
+ end
11
+ end
12
+
13
+ g.desc 'This method begins a Real Time Messaging API session and reserves your application a specific URL with which to connect via websocket.'
14
+ g.long_desc %( This method begins a Real Time Messaging API session and reserves your application a specific URL with which to connect via websocket. )
7
15
  g.command 'start' do |c|
8
16
  c.flag 'simple_latest', desc: 'Return timestamp only for latest message object of each channel (improves performance).'
9
17
  c.flag 'no_unreads', desc: 'Skip unread counts for each channel (improves performance).'
10
18
  c.flag 'mpim_aware', desc: 'Returns MPIMs to the client in the API response.'
19
+ c.flag 'no_latest', desc: 'Exclude latest timestamps for channels, groups, mpims, and ims. Automatically sets no_unreads to 1.'
11
20
  c.action do |_global_options, options, _args|
12
21
  puts JSON.dump($client.rtm_start(options))
13
22
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  desc 'UsersProfile methods.'
4
4
  command 'users_profile' do |g|
5
- g.desc 'This method is used to get the profile information for a user.'
6
- g.long_desc %( This method is used to get the profile information for a user. )
5
+ g.desc "Use this method to retrieve a user's profile information."
6
+ g.long_desc %( Use this method to retrieve a user's profile information. )
7
7
  g.command 'get' do |c|
8
8
  c.flag 'user', desc: 'User to retrieve profile info for.'
9
9
  c.flag 'include_labels', desc: 'Include labels for each ID in custom profile fields.'
@@ -12,8 +12,8 @@ command 'users_profile' do |g|
12
12
  end
13
13
  end
14
14
 
15
- g.desc 'This method is used to set the profile information for a user.'
16
- g.long_desc %( This method is used to set the profile information for a user. )
15
+ g.desc "Use this method to set a user's profile information, including name, email, current status, and other attributes."
16
+ g.long_desc %( Use this method to set a user's profile information, including name, email, current status, and other attributes. )
17
17
  g.command 'set' do |c|
18
18
  c.flag 'user', desc: 'ID of user to change. This argument may only be specified by team admins on paid teams.'
19
19
  c.flag 'profile', desc: 'Collection of key:value pairs presented as a URL-encoded JSON hash.'
@@ -1,11 +1,11 @@
1
- require 'slack/version'
2
- require 'slack/logger'
3
- require 'slack/config'
1
+ require_relative 'slack/version'
2
+ require_relative 'slack/logger'
3
+ require_relative 'slack/config'
4
4
 
5
5
  # Messages
6
6
  require 'hashie'
7
- require 'slack/messages/message'
8
- require 'slack/messages/formatting'
7
+ require_relative 'slack/messages/message'
8
+ require_relative 'slack/messages/formatting'
9
9
 
10
10
  # Web API
11
11
  require 'faraday'
@@ -17,25 +17,25 @@ begin
17
17
  rescue LoadError
18
18
  # ignore, only used in users_search
19
19
  end
20
- require 'slack/web/config'
21
- require 'slack/web/api/error'
22
- require 'slack/web/faraday/response/raise_error'
23
- require 'slack/web/faraday/connection'
24
- require 'slack/web/faraday/request'
25
- require 'slack/web/api/mixins'
26
- require 'slack/web/api/endpoints'
27
- require 'slack/web/client'
20
+ require_relative 'slack/web/config'
21
+ require_relative 'slack/web/api/error'
22
+ require_relative 'slack/web/faraday/response/raise_error'
23
+ require_relative 'slack/web/faraday/connection'
24
+ require_relative 'slack/web/faraday/request'
25
+ require_relative 'slack/web/api/mixins'
26
+ require_relative 'slack/web/api/endpoints'
27
+ require_relative 'slack/web/client'
28
28
 
29
29
  # RealTime API
30
30
  require 'active_support'
31
31
  require 'active_support/core_ext'
32
- require 'slack/real_time/concurrency'
33
- require 'slack/real_time/socket'
34
- require 'slack/real_time/api/message_id'
35
- require 'slack/real_time/api/ping'
36
- require 'slack/real_time/api/message'
37
- require 'slack/real_time/api/typing'
38
- require 'slack/real_time/models'
39
- require 'slack/real_time/stores'
40
- require 'slack/real_time/config'
41
- require 'slack/real_time/client'
32
+ require_relative 'slack/real_time/concurrency'
33
+ require_relative 'slack/real_time/socket'
34
+ require_relative 'slack/real_time/api/message_id'
35
+ require_relative 'slack/real_time/api/ping'
36
+ require_relative 'slack/real_time/api/message'
37
+ require_relative 'slack/real_time/api/typing'
38
+ require_relative 'slack/real_time/models'
39
+ require_relative 'slack/real_time/stores'
40
+ require_relative 'slack/real_time/config'
41
+ require_relative 'slack/real_time/client'
@@ -1,7 +1,7 @@
1
- require 'slack/real_time/models/base'
2
- require 'slack/real_time/models/user'
3
- require 'slack/real_time/models/bot'
4
- require 'slack/real_time/models/channel'
5
- require 'slack/real_time/models/group'
6
- require 'slack/real_time/models/team'
7
- require 'slack/real_time/models/im'
1
+ require_relative 'models/base'
2
+ require_relative 'models/user'
3
+ require_relative 'models/bot'
4
+ require_relative 'models/channel'
5
+ require_relative 'models/group'
6
+ require_relative 'models/team'
7
+ require_relative 'models/im'
@@ -1,6 +1,6 @@
1
- require 'slack/real_time/stores/base'
2
- require 'slack/real_time/stores/starter'
3
- require 'slack/real_time/stores/store'
1
+ require_relative 'stores/base'
2
+ require_relative 'stores/starter'
3
+ require_relative 'stores/store'
4
4
 
5
5
  module Slack
6
6
  module RealTime
data/lib/slack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = '0.8.0'.freeze
2
+ VERSION = '0.8.1'.freeze
3
3
  end
@@ -1,30 +1,30 @@
1
1
  # This file was auto-generated by lib/tasks/web.rake
2
2
 
3
- require 'slack/web/api/endpoints/api'
4
- require 'slack/web/api/endpoints/auth'
5
- require 'slack/web/api/endpoints/bots'
6
- require 'slack/web/api/endpoints/channels'
7
- require 'slack/web/api/endpoints/chat'
8
- require 'slack/web/api/endpoints/dnd'
9
- require 'slack/web/api/endpoints/emoji'
10
- require 'slack/web/api/endpoints/files_comments'
11
- require 'slack/web/api/endpoints/files'
12
- require 'slack/web/api/endpoints/groups'
13
- require 'slack/web/api/endpoints/im'
14
- require 'slack/web/api/endpoints/mpim'
15
- require 'slack/web/api/endpoints/oauth'
16
- require 'slack/web/api/endpoints/pins'
17
- require 'slack/web/api/endpoints/reactions'
18
- require 'slack/web/api/endpoints/reminders'
19
- require 'slack/web/api/endpoints/rtm'
20
- require 'slack/web/api/endpoints/search'
21
- require 'slack/web/api/endpoints/stars'
22
- require 'slack/web/api/endpoints/team'
23
- require 'slack/web/api/endpoints/team_profile'
24
- require 'slack/web/api/endpoints/usergroups'
25
- require 'slack/web/api/endpoints/usergroups_users'
26
- require 'slack/web/api/endpoints/users'
27
- require 'slack/web/api/endpoints/users_profile'
3
+ require_relative 'endpoints/api'
4
+ require_relative 'endpoints/auth'
5
+ require_relative 'endpoints/bots'
6
+ require_relative 'endpoints/channels'
7
+ require_relative 'endpoints/chat'
8
+ require_relative 'endpoints/dnd'
9
+ require_relative 'endpoints/emoji'
10
+ require_relative 'endpoints/files_comments'
11
+ require_relative 'endpoints/files'
12
+ require_relative 'endpoints/groups'
13
+ require_relative 'endpoints/im'
14
+ require_relative 'endpoints/mpim'
15
+ require_relative 'endpoints/oauth'
16
+ require_relative 'endpoints/pins'
17
+ require_relative 'endpoints/reactions'
18
+ require_relative 'endpoints/reminders'
19
+ require_relative 'endpoints/rtm'
20
+ require_relative 'endpoints/search'
21
+ require_relative 'endpoints/stars'
22
+ require_relative 'endpoints/team'
23
+ require_relative 'endpoints/team_profile'
24
+ require_relative 'endpoints/usergroups'
25
+ require_relative 'endpoints/usergroups_users'
26
+ require_relative 'endpoints/users'
27
+ require_relative 'endpoints/users_profile'
28
28
 
29
29
  module Slack
30
30
  module Web
@@ -132,7 +132,9 @@ module Slack
132
132
  # This method returns a list of all channels in the team. This includes channels the caller is in, channels they are not currently in, and archived channels but does not include private channels. The number of (non-deactivated) members in each channel is also returned.
133
133
  #
134
134
  # @option options [Object] :exclude_archived
135
- # Don't return archived channels.
135
+ # Exclude archived channels from the list.
136
+ # @option options [Object] :exclude_members
137
+ # Exclude the members collection from each channel.
136
138
  # @see https://api.slack.com/methods/channels.list
137
139
  # @see https://github.com/dblock/slack-api-ref/blob/master/methods/channels/channels.list.json
138
140
  def channels_list(options = {})
@@ -81,6 +81,27 @@ module Slack
81
81
  post('chat.postMessage', options)
82
82
  end
83
83
 
84
+ #
85
+ # This method attaches Slack app unfurl behavior to a specified and relevant message. A user token is required as this method does not support bot user tokens.
86
+ #
87
+ # @option options [channel] :channel
88
+ # Channel ID of the message.
89
+ # @option options [timestamp] :ts
90
+ # Timestamp of the message to add unfurl behavior to.
91
+ # @option options [Object] :unfurls
92
+ # JSON mapping a set of URLs from the message to their unfurl attachments.
93
+ # @option options [Object] :user_auth_required
94
+ # Set to true or 1 to indicate the user must install your Slack app to trigger unfurls for this domain.
95
+ # @see https://api.slack.com/methods/chat.unfurl
96
+ # @see https://github.com/dblock/slack-api-ref/blob/master/methods/chat/chat.unfurl.json
97
+ def chat_unfurl(options = {})
98
+ throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
99
+ throw ArgumentError.new('Required arguments :ts missing') if options[:ts].nil?
100
+ throw ArgumentError.new('Required arguments :unfurls missing') if options[:unfurls].nil?
101
+ options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
102
+ post('chat.unfurl', options)
103
+ end
104
+
84
105
  #
85
106
  # This method updates a message in a channel. Though related to chat.postMessage, some parameters of chat.update are handled differently.
86
107
  #
@@ -6,8 +6,16 @@ module Slack
6
6
  module Endpoints
7
7
  module Rtm
8
8
  #
9
- # This method starts a Real Time Messaging API session. Refer to the
10
- # RTM API documentation for full details on how to use the RTM API.
9
+ # This method begins a Real Time Messaging API session and reserves your application a specific URL with which to connect via websocket.
10
+ #
11
+ # @see https://api.slack.com/methods/rtm.connect
12
+ # @see https://github.com/dblock/slack-api-ref/blob/master/methods/rtm/rtm.connect.json
13
+ def rtm_connect(options = {})
14
+ post('rtm.connect', options)
15
+ end
16
+
17
+ #
18
+ # This method begins a Real Time Messaging API session and reserves your application a specific URL with which to connect via websocket.
11
19
  #
12
20
  # @option options [Object] :simple_latest
13
21
  # Return timestamp only for latest message object of each channel (improves performance).
@@ -15,6 +23,8 @@ module Slack
15
23
  # Skip unread counts for each channel (improves performance).
16
24
  # @option options [Object] :mpim_aware
17
25
  # Returns MPIMs to the client in the API response.
26
+ # @option options [Object] :no_latest
27
+ # Exclude latest timestamps for channels, groups, mpims, and ims. Automatically sets no_unreads to 1.
18
28
  # @see https://api.slack.com/methods/rtm.start
19
29
  # @see https://github.com/dblock/slack-api-ref/blob/master/methods/rtm/rtm.start.json
20
30
  def rtm_start(options = {})
@@ -6,7 +6,7 @@ module Slack
6
6
  module Endpoints
7
7
  module UsersProfile
8
8
  #
9
- # This method is used to get the profile information for a user.
9
+ # Use this method to retrieve a user's profile information.
10
10
  #
11
11
  # @option options [user] :user
12
12
  # User to retrieve profile info for.
@@ -20,7 +20,7 @@ module Slack
20
20
  end
21
21
 
22
22
  #
23
- # This method is used to set the profile information for a user.
23
+ # Use this method to set a user's profile information, including name, email, current status, and other attributes.
24
24
  #
25
25
  # @option options [user] :user
26
26
  # ID of user to change. This argument may only be specified by team admins on paid teams.
@@ -1,4 +1,4 @@
1
- require 'slack/web/api/mixins/channels.id'
2
- require 'slack/web/api/mixins/users.id'
3
- require 'slack/web/api/mixins/users.search'
4
- require 'slack/web/api/mixins/groups.id'
1
+ require_relative 'mixins/channels.id'
2
+ require_relative 'mixins/users.id'
3
+ require_relative 'mixins/users.search'
4
+ require_relative 'mixins/groups.id'
@@ -1,8 +1,11 @@
1
+ require_relative 'ids.id'
2
+
1
3
  module Slack
2
4
  module Web
3
5
  module Api
4
6
  module Mixins
5
7
  module Channels
8
+ include Ids
6
9
  #
7
10
  # This method returns a channel ID given a channel name.
8
11
  #
@@ -11,13 +14,10 @@ module Slack
11
14
  def channels_id(options = {})
12
15
  name = options[:channel]
13
16
  throw ArgumentError.new('Required arguments :channel missing') if name.nil?
14
- return { 'ok' => true, 'channel' => { 'id' => name } } unless name[0] == '#'
15
- channels_list.tap do |list|
16
- list.channels.each do |channel|
17
- return Slack::Messages::Message.new('ok' => true, 'channel' => { 'id' => channel.id }) if channel.name == name[1..-1]
18
- end
17
+
18
+ id_for(:channel, name, '#', :channels, 'channel_not_found') do
19
+ channels_list
19
20
  end
20
- fail Slack::Web::Api::Error, 'channel_not_found'
21
21
  end
22
22
  end
23
23
  end
@@ -1,8 +1,11 @@
1
+ require_relative 'ids.id'
2
+
1
3
  module Slack
2
4
  module Web
3
5
  module Api
4
6
  module Mixins
5
7
  module Groups
8
+ include Ids
6
9
  #
7
10
  # This method returns a group ID given a group name.
8
11
  #
@@ -11,13 +14,10 @@ module Slack
11
14
  def groups_id(options = {})
12
15
  name = options[:channel]
13
16
  throw ArgumentError.new('Required arguments :channel missing') if name.nil?
14
- return { 'ok' => true, 'group' => { 'id' => name } } unless name[0] == '#'
15
- groups_list.tap do |list|
16
- list.groups.each do |group|
17
- return Slack::Messages::Message.new('ok' => true, 'group' => { 'id' => group.id }) if group.name == name[1..-1]
18
- end
17
+
18
+ id_for(:group, name, '#', :groups, 'channel_not_found') do
19
+ groups_list
19
20
  end
20
- fail Slack::Web::Api::Error, 'channel_not_found'
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,23 @@
1
+ module Slack
2
+ module Web
3
+ module Api
4
+ module Mixins
5
+ module Ids
6
+ private
7
+
8
+ def id_for(key, name, prefix, list_method, not_found_error)
9
+ return { 'ok' => true, key.to_s => { 'id' => name } } unless name[0] == prefix
10
+
11
+ yield.tap do |list|
12
+ list.public_send(list_method).each do |li|
13
+ return Slack::Messages::Message.new('ok' => true, key.to_s => { 'id' => li.id }) if li.name == name[1..-1]
14
+ end
15
+ end
16
+
17
+ fail Slack::Web::Api::Error, not_found_error
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,8 +1,11 @@
1
+ require_relative 'ids.id'
2
+
1
3
  module Slack
2
4
  module Web
3
5
  module Api
4
6
  module Mixins
5
7
  module Users
8
+ include Ids
6
9
  #
7
10
  # This method returns a user ID given a user name.
8
11
  #
@@ -11,13 +14,10 @@ module Slack
11
14
  def users_id(options = {})
12
15
  name = options[:user]
13
16
  throw ArgumentError.new('Required arguments :user missing') if name.nil?
14
- return { 'ok' => true, 'user' => { 'id' => name } } unless name[0] == '@'
15
- users_list.tap do |list|
16
- list.members.each do |user|
17
- return Slack::Messages::Message.new('ok' => true, 'user' => { 'id' => user.id }) if user.name == name[1..-1]
18
- end
17
+
18
+ id_for(:user, name, '@', :members, 'user_not_found') do
19
+ users_list
19
20
  end
20
- fail Slack::Web::Api::Error, 'user_not_found'
21
21
  end
22
22
  end
23
23
  end
@@ -1,7 +1,7 @@
1
1
  # This file was auto-generated by lib/tasks/web.rake
2
2
 
3
3
  <% files.each do |f| %>
4
- require 'slack/web/api/endpoints/<%= f %>'
4
+ require_relative 'endpoints/<%= f %>'
5
5
  <% end %>
6
6
 
7
7
  module Slack
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.8.0
4
+ version: 0.8.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-03-12 00:00:00.000000000 Z
11
+ date: 2017-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -336,6 +336,7 @@ files:
336
336
  - lib/slack/web/api/mixins/channels.id.rb
337
337
  - lib/slack/web/api/mixins/groups.id.json
338
338
  - lib/slack/web/api/mixins/groups.id.rb
339
+ - lib/slack/web/api/mixins/ids.id.rb
339
340
  - lib/slack/web/api/mixins/users.id.json
340
341
  - lib/slack/web/api/mixins/users.id.rb
341
342
  - lib/slack/web/api/mixins/users.search.json
@@ -449,7 +450,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
449
450
  version: 1.3.6
450
451
  requirements: []
451
452
  rubyforge_project:
452
- rubygems_version: 2.6.7
453
+ rubygems_version: 2.6.10
453
454
  signing_key:
454
455
  specification_version: 4
455
456
  summary: Slack Web and RealTime API client.