slack-ruby-client 0.9.0 → 0.11.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +40 -39
- data/.travis.yml +1 -9
- data/CHANGELOG.md +24 -0
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +3 -1
- data/README.md +40 -12
- data/Rakefile +1 -1
- data/UPGRADING.md +1 -1
- data/bin/commands/api.rb +2 -2
- data/bin/commands/apps_permissions.rb +22 -0
- data/bin/commands/auth.rb +4 -4
- data/bin/commands/bots.rb +2 -2
- data/bin/commands/channels.rb +52 -40
- data/bin/commands/chat.rb +63 -25
- data/bin/commands/conversations.rb +178 -0
- data/bin/commands/dialog.rb +14 -0
- data/bin/commands/dnd.rb +8 -8
- data/bin/commands/emoji.rb +2 -2
- data/bin/commands/files.rb +38 -17
- data/bin/commands/files_comments.rb +6 -6
- data/bin/commands/groups.rb +44 -51
- data/bin/commands/im.rb +16 -13
- data/bin/commands/migration.rb +14 -0
- data/bin/commands/mpim.rb +11 -11
- data/bin/commands/oauth.rb +15 -2
- data/bin/commands/pins.rb +6 -6
- data/bin/commands/reactions.rb +13 -13
- data/bin/commands/reminders.rb +10 -10
- data/bin/commands/rtm.rb +9 -6
- data/bin/commands/search.rb +9 -9
- data/bin/commands/stars.rb +8 -8
- data/bin/commands/team.rb +10 -10
- data/bin/commands/team_profile.rb +2 -2
- data/bin/commands/usergroups.rb +16 -16
- data/bin/commands/usergroups_users.rb +4 -4
- data/bin/commands/users.rb +40 -36
- data/bin/commands/users_admin.rb +28 -0
- data/bin/commands/users_prefs.rb +12 -0
- data/bin/commands/users_profile.rb +7 -7
- data/bin/commands.rb +7 -1
- data/bin/slack +1 -1
- data/examples/hi_real_time/hi.rb +1 -1
- data/examples/hi_real_time_and_web/hi.rb +1 -1
- data/examples/hi_real_time_async_celluloid/hi.rb +1 -1
- data/examples/hi_real_time_async_eventmachine/hi.rb +1 -1
- data/examples/hi_web/hi.rb +1 -1
- data/examples/new_ticket/new_ticket.rb +1 -1
- data/lib/slack/messages/formatting.rb +4 -4
- data/lib/slack/messages/message.rb +1 -2
- data/lib/slack/real_time/api/templates/event_handler.erb +1 -1
- data/lib/slack/real_time/client.rb +11 -10
- data/lib/slack/real_time/concurrency/celluloid.rb +6 -2
- data/lib/slack/real_time/config.rb +11 -11
- data/lib/slack/real_time/models/base.rb +1 -2
- data/lib/slack/real_time/socket.rb +2 -2
- data/lib/slack/real_time/stores/base.rb +1 -2
- data/lib/slack/real_time/stores/starter.rb +92 -72
- data/lib/slack/real_time/stores/store.rb +120 -90
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/api.rb +2 -2
- data/lib/slack/web/api/endpoints/apps_permissions.rb +35 -0
- data/lib/slack/web/api/endpoints/auth.rb +4 -4
- data/lib/slack/web/api/endpoints/bots.rb +2 -2
- data/lib/slack/web/api/endpoints/channels.rb +57 -34
- data/lib/slack/web/api/endpoints/chat.rb +107 -37
- data/lib/slack/web/api/endpoints/conversations.rb +301 -0
- data/lib/slack/web/api/endpoints/dialog.rb +32 -0
- data/lib/slack/web/api/endpoints/dnd.rb +9 -9
- data/lib/slack/web/api/endpoints/emoji.rb +2 -2
- data/lib/slack/web/api/endpoints/files.rb +53 -23
- data/lib/slack/web/api/endpoints/files_comments.rb +11 -11
- data/lib/slack/web/api/endpoints/groups.rb +38 -50
- data/lib/slack/web/api/endpoints/im.rb +27 -17
- data/lib/slack/web/api/endpoints/migration.rb +25 -0
- data/lib/slack/web/api/endpoints/mpim.rb +13 -15
- data/lib/slack/web/api/endpoints/oauth.rb +24 -3
- data/lib/slack/web/api/endpoints/pins.rb +6 -8
- data/lib/slack/web/api/endpoints/presence.rb +1 -1
- data/lib/slack/web/api/endpoints/reactions.rb +18 -20
- data/lib/slack/web/api/endpoints/reminders.rb +10 -10
- data/lib/slack/web/api/endpoints/rtm.rb +14 -8
- data/lib/slack/web/api/endpoints/search.rb +12 -12
- data/lib/slack/web/api/endpoints/stars.rb +10 -12
- data/lib/slack/web/api/endpoints/team.rb +12 -13
- data/lib/slack/web/api/endpoints/team_profile.rb +2 -2
- data/lib/slack/web/api/endpoints/usergroups.rb +22 -22
- data/lib/slack/web/api/endpoints/usergroups_users.rb +4 -4
- data/lib/slack/web/api/endpoints/users.rb +34 -24
- data/lib/slack/web/api/endpoints/users_admin.rb +46 -0
- data/lib/slack/web/api/endpoints/users_prefs.rb +19 -0
- data/lib/slack/web/api/endpoints/users_profile.rb +10 -10
- data/lib/slack/web/api/endpoints.rb +14 -2
- data/lib/slack/web/api/mixins/ids.id.rb +1 -1
- data/lib/slack/web/api/mixins/users.search.rb +38 -36
- data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +1 -1
- data/lib/slack/web/api/patches/chat.3.update-attachments-support.patch +4 -3
- data/lib/slack/web/api/patches/chat.4.postEphemeral-attachments-support.patch +17 -0
- data/lib/slack/web/api/patches/dialog.1.open-json-support.patch +17 -0
- data/lib/slack/web/api/templates/command.erb +4 -3
- data/lib/slack/web/api/templates/commands.erb +1 -1
- data/lib/slack/web/api/templates/endpoints.erb +2 -2
- data/lib/slack/web/api/templates/method.erb +18 -3
- data/lib/slack/web/api/templates/method_spec.erb +1 -1
- data/lib/slack/web/config.rb +16 -12
- data/lib/slack/web/faraday/connection.rb +1 -1
- data/lib/slack/web/faraday/response/raise_error.rb +3 -3
- data/lib/slack/web/pagination/cursor.rb +48 -0
- data/lib/slack-ruby-client.rb +6 -0
- data/lib/tasks/git.rake +1 -1
- data/lib/tasks/real_time.rake +1 -1
- data/lib/tasks/web.rake +4 -1
- data/slack-ruby-client.gemspec +2 -3
- data/spec/fixtures/slack/web/paginated_users_list.yml +181 -0
- data/spec/integration/integration_spec.rb +1 -1
- data/spec/slack/messages/formatting_spec.rb +1 -1
- data/spec/slack/real_time/client_spec.rb +62 -63
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +41 -31
- data/spec/slack/real_time/concurrency/it_behaves_like_a_realtime_socket.rb +1 -1
- data/spec/slack/real_time/event_handlers/bot_spec.rb +4 -2
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +1 -1
- data/spec/slack/real_time/event_handlers/user_spec.rb +4 -2
- data/spec/slack/web/api/endpoints/apps_permissions_spec.rb +15 -0
- data/spec/slack/web/api/endpoints/conversations_spec.rb +100 -0
- data/spec/slack/web/api/endpoints/custom_specs/chat_spec.rb +37 -1
- data/spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb +28 -0
- data/spec/slack/web/api/endpoints/custom_specs/users_spec.rb +16 -6
- data/spec/slack/web/api/endpoints/files_comments_spec.rb +8 -8
- data/spec/slack/web/api/endpoints/files_spec.rb +16 -5
- data/spec/slack/web/api/endpoints/migration_spec.rb +12 -0
- data/spec/slack/web/api/endpoints/oauth_spec.rb +11 -0
- data/spec/slack/web/api/endpoints/users_admin_spec.rb +17 -0
- data/spec/slack/web/api/endpoints/users_prefs_spec.rb +7 -0
- data/spec/slack/web/api/error_spec.rb +1 -1
- data/spec/slack/web/api/errors/slack_error_spec.rb +1 -1
- data/spec/slack/web/api/mixins/users_spec.rb +6 -4
- data/spec/slack/web/api/pagination/cursor_spec.rb +70 -0
- data/spec/support/queue_with_timeout.rb +1 -1
- data/spec/support/real_time/concurrency/mock.rb +1 -2
- metadata +47 -30
@@ -6,22 +6,21 @@ module Slack
|
|
6
6
|
module Endpoints
|
7
7
|
module Users
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# Delete the user profile photo
|
10
10
|
#
|
11
11
|
# @see https://api.slack.com/methods/users.deletePhoto
|
12
|
-
# @see https://github.com/
|
12
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.deletePhoto.json
|
13
13
|
def users_deletePhoto(options = {})
|
14
14
|
post('users.deletePhoto', options)
|
15
15
|
end
|
16
16
|
|
17
17
|
#
|
18
|
-
#
|
19
|
-
# Consult the presence documentation for more details.
|
18
|
+
# Gets user presence information.
|
20
19
|
#
|
21
20
|
# @option options [user] :user
|
22
21
|
# User to get presence info on. Defaults to the authed user.
|
23
22
|
# @see https://api.slack.com/methods/users.getPresence
|
24
|
-
# @see https://github.com/
|
23
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.getPresence.json
|
25
24
|
def users_getPresence(options = {})
|
26
25
|
throw ArgumentError.new('Required arguments :user missing') if options[:user].nil?
|
27
26
|
options = options.merge(user: users_id(options)['user']['id']) if options[:user]
|
@@ -29,21 +28,23 @@ module Slack
|
|
29
28
|
end
|
30
29
|
|
31
30
|
#
|
32
|
-
#
|
31
|
+
# Get a user's identity.
|
33
32
|
#
|
34
33
|
# @see https://api.slack.com/methods/users.identity
|
35
|
-
# @see https://github.com/
|
34
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.identity.json
|
36
35
|
def users_identity(options = {})
|
37
36
|
post('users.identity', options)
|
38
37
|
end
|
39
38
|
|
40
39
|
#
|
41
|
-
#
|
40
|
+
# Gets information about a user.
|
42
41
|
#
|
43
42
|
# @option options [user] :user
|
44
43
|
# User to get info on.
|
44
|
+
# @option options [Object] :include_locale
|
45
|
+
# Set this to true to receive the locale for this user. Defaults to false.
|
45
46
|
# @see https://api.slack.com/methods/users.info
|
46
|
-
# @see https://github.com/
|
47
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.info.json
|
47
48
|
def users_info(options = {})
|
48
49
|
throw ArgumentError.new('Required arguments :user missing') if options[:user].nil?
|
49
50
|
options = options.merge(user: users_id(options)['user']['id']) if options[:user]
|
@@ -51,53 +52,62 @@ module Slack
|
|
51
52
|
end
|
52
53
|
|
53
54
|
#
|
54
|
-
#
|
55
|
+
# Lists all users in a Slack team.
|
55
56
|
#
|
57
|
+
# @option options [Object] :cursor
|
58
|
+
# 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.
|
59
|
+
# @option options [Object] :include_locale
|
60
|
+
# Set this to true to receive the locale for users. Defaults to false.
|
61
|
+
# @option options [Object] :limit
|
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.
|
56
63
|
# @option options [Object] :presence
|
57
|
-
# Whether to include presence data in the output.
|
64
|
+
# Whether to include presence data in the output. Setting this to false improves performance, especially with large teams.
|
58
65
|
# @see https://api.slack.com/methods/users.list
|
59
|
-
# @see https://github.com/
|
66
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.list.json
|
60
67
|
def users_list(options = {})
|
61
|
-
|
68
|
+
if block_given?
|
69
|
+
Pagination::Cursor.new(self, :users_list, options).each do |page|
|
70
|
+
yield page
|
71
|
+
end
|
72
|
+
else
|
73
|
+
post('users.list', options)
|
74
|
+
end
|
62
75
|
end
|
63
76
|
|
64
77
|
#
|
65
|
-
#
|
66
|
-
# is currently active. Consult the presence documentation for
|
67
|
-
# more details.
|
78
|
+
# Marks a user as active.
|
68
79
|
#
|
69
80
|
# @see https://api.slack.com/methods/users.setActive
|
70
|
-
# @see https://github.com/
|
81
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.setActive.json
|
71
82
|
def users_setActive(options = {})
|
72
83
|
post('users.setActive', options)
|
73
84
|
end
|
74
85
|
|
75
86
|
#
|
76
|
-
#
|
87
|
+
# Set the user profile photo
|
77
88
|
#
|
78
89
|
# @option options [Object] :image
|
79
90
|
# File contents via multipart/form-data.
|
91
|
+
# @option options [Object] :crop_w
|
92
|
+
# Width/height of crop box (always square).
|
80
93
|
# @option options [Object] :crop_x
|
81
94
|
# X coordinate of top-left corner of crop box.
|
82
95
|
# @option options [Object] :crop_y
|
83
96
|
# Y coordinate of top-left corner of crop box.
|
84
|
-
# @option options [Object] :crop_w
|
85
|
-
# Width/height of crop box (always square).
|
86
97
|
# @see https://api.slack.com/methods/users.setPhoto
|
87
|
-
# @see https://github.com/
|
98
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.setPhoto.json
|
88
99
|
def users_setPhoto(options = {})
|
89
100
|
throw ArgumentError.new('Required arguments :image missing') if options[:image].nil?
|
90
101
|
post('users.setPhoto', options)
|
91
102
|
end
|
92
103
|
|
93
104
|
#
|
94
|
-
#
|
95
|
-
# Consult the presence documentation for more details.
|
105
|
+
# Manually sets user presence.
|
96
106
|
#
|
97
107
|
# @option options [Object] :presence
|
98
108
|
# Either auto or away.
|
99
109
|
# @see https://api.slack.com/methods/users.setPresence
|
100
|
-
# @see https://github.com/
|
110
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users/users.setPresence.json
|
101
111
|
def users_setPresence(options = {})
|
102
112
|
throw ArgumentError.new('Required arguments :presence missing') if options[:presence].nil?
|
103
113
|
post('users.setPresence', options)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# This file was auto-generated by lib/tasks/web.rake
|
2
|
+
|
3
|
+
module Slack
|
4
|
+
module Web
|
5
|
+
module Api
|
6
|
+
module Endpoints
|
7
|
+
module UsersAdmin
|
8
|
+
#
|
9
|
+
# Send an invitation to a new user by email (undocumented)
|
10
|
+
#
|
11
|
+
# @option options [Object] :email
|
12
|
+
# Email address of the new user
|
13
|
+
# @option options [Object] :channels
|
14
|
+
# Comma-separated list of IDs (not names!) for channels, which the new user will auto-join. Both channel IDs for public channels and group IDs for private chanels work.
|
15
|
+
# @option options [Object] :first_name
|
16
|
+
# Prefilled input for the "First name" field on the "new user registration" page.
|
17
|
+
# @option options [Object] :last_name
|
18
|
+
# Prefilled input for the "Last name" field on the "new user registration" page.
|
19
|
+
# @option options [Object] :resend
|
20
|
+
# Resend the invitation email if the user has already been invited and the email was sent some time ago.
|
21
|
+
# @option options [Object] :restricted
|
22
|
+
# Invite a guest that can use multiple channels
|
23
|
+
# @option options [Object] :ultra_restricted
|
24
|
+
# Invite a guest that can use one channel only
|
25
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/undocumented/users.admin/users.admin.invite.json
|
26
|
+
def users_admin_invite(options = {})
|
27
|
+
throw ArgumentError.new('Required arguments :email missing') if options[:email].nil?
|
28
|
+
post('users.admin.invite', options)
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Disable a user (undocumented)
|
33
|
+
#
|
34
|
+
# @option options [user] :user
|
35
|
+
# User to disable
|
36
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/undocumented/users.admin/users.admin.setInactive.json
|
37
|
+
def users_admin_setInactive(options = {})
|
38
|
+
throw ArgumentError.new('Required arguments :user missing') if options[:user].nil?
|
39
|
+
options = options.merge(user: users_id(options)['user']['id']) if options[:user]
|
40
|
+
post('users.admin.setInactive', options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was auto-generated by lib/tasks/web.rake
|
2
|
+
|
3
|
+
module Slack
|
4
|
+
module Web
|
5
|
+
module Api
|
6
|
+
module Endpoints
|
7
|
+
module UsersPrefs
|
8
|
+
#
|
9
|
+
# Returns the user's preferences (undocumented)
|
10
|
+
#
|
11
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/undocumented/users.prefs/users.prefs.get.json
|
12
|
+
def users_prefs_get(options = {})
|
13
|
+
post('users.prefs.get', options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -6,32 +6,32 @@ module Slack
|
|
6
6
|
module Endpoints
|
7
7
|
module UsersProfile
|
8
8
|
#
|
9
|
-
#
|
9
|
+
# Retrieves a user's profile information.
|
10
10
|
#
|
11
|
-
# @option options [user] :user
|
12
|
-
# User to retrieve profile info for.
|
13
11
|
# @option options [Object] :include_labels
|
14
12
|
# Include labels for each ID in custom profile fields.
|
13
|
+
# @option options [user] :user
|
14
|
+
# User to retrieve profile info for.
|
15
15
|
# @see https://api.slack.com/methods/users.profile.get
|
16
|
-
# @see https://github.com/
|
16
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users.profile/users.profile.get.json
|
17
17
|
def users_profile_get(options = {})
|
18
18
|
options = options.merge(user: users_id(options)['user']['id']) if options[:user]
|
19
19
|
post('users.profile.get', options)
|
20
20
|
end
|
21
21
|
|
22
22
|
#
|
23
|
-
#
|
23
|
+
# Set the profile information for a user.
|
24
24
|
#
|
25
|
-
# @option options [user] :user
|
26
|
-
# ID of user to change. This argument may only be specified by team admins on paid teams.
|
27
|
-
# @option options [Object] :profile
|
28
|
-
# Collection of key:value pairs presented as a URL-encoded JSON hash.
|
29
25
|
# @option options [Object] :name
|
30
26
|
# Name of a single key to set. Usable only if profile is not passed.
|
27
|
+
# @option options [Object] :profile
|
28
|
+
# Collection of key:value pairs presented as a URL-encoded JSON hash.
|
29
|
+
# @option options [user] :user
|
30
|
+
# ID of user to change. This argument may only be specified by team admins on paid teams.
|
31
31
|
# @option options [Object] :value
|
32
32
|
# Value to set a single key to. Usable only if profile is not passed.
|
33
33
|
# @see https://api.slack.com/methods/users.profile.set
|
34
|
-
# @see https://github.com/
|
34
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/users.profile/users.profile.set.json
|
35
35
|
def users_profile_set(options = {})
|
36
36
|
options = options.merge(user: users_id(options)['user']['id']) if options[:user]
|
37
37
|
post('users.profile.set', options)
|
@@ -1,16 +1,20 @@
|
|
1
1
|
# This file was auto-generated by lib/tasks/web.rake
|
2
2
|
|
3
3
|
require_relative 'endpoints/api'
|
4
|
+
require_relative 'endpoints/apps_permissions'
|
4
5
|
require_relative 'endpoints/auth'
|
5
6
|
require_relative 'endpoints/bots'
|
6
7
|
require_relative 'endpoints/channels'
|
7
8
|
require_relative 'endpoints/chat'
|
9
|
+
require_relative 'endpoints/conversations'
|
10
|
+
require_relative 'endpoints/dialog'
|
8
11
|
require_relative 'endpoints/dnd'
|
9
12
|
require_relative 'endpoints/emoji'
|
10
|
-
require_relative 'endpoints/files_comments'
|
11
13
|
require_relative 'endpoints/files'
|
14
|
+
require_relative 'endpoints/files_comments'
|
12
15
|
require_relative 'endpoints/groups'
|
13
16
|
require_relative 'endpoints/im'
|
17
|
+
require_relative 'endpoints/migration'
|
14
18
|
require_relative 'endpoints/mpim'
|
15
19
|
require_relative 'endpoints/oauth'
|
16
20
|
require_relative 'endpoints/pins'
|
@@ -24,6 +28,8 @@ require_relative 'endpoints/team_profile'
|
|
24
28
|
require_relative 'endpoints/usergroups'
|
25
29
|
require_relative 'endpoints/usergroups_users'
|
26
30
|
require_relative 'endpoints/users'
|
31
|
+
require_relative 'endpoints/users_admin'
|
32
|
+
require_relative 'endpoints/users_prefs'
|
27
33
|
require_relative 'endpoints/users_profile'
|
28
34
|
|
29
35
|
module Slack
|
@@ -35,16 +41,20 @@ module Slack
|
|
35
41
|
include Slack::Web::Api::Mixins::Groups
|
36
42
|
|
37
43
|
include Api
|
44
|
+
include AppsPermissions
|
38
45
|
include Auth
|
39
46
|
include Bots
|
40
47
|
include Channels
|
41
48
|
include Chat
|
49
|
+
include Conversations
|
50
|
+
include Dialog
|
42
51
|
include Dnd
|
43
52
|
include Emoji
|
44
|
-
include FilesComments
|
45
53
|
include Files
|
54
|
+
include FilesComments
|
46
55
|
include Groups
|
47
56
|
include Im
|
57
|
+
include Migration
|
48
58
|
include Mpim
|
49
59
|
include Oauth
|
50
60
|
include Pins
|
@@ -58,6 +68,8 @@ module Slack
|
|
58
68
|
include Usergroups
|
59
69
|
include UsergroupsUsers
|
60
70
|
include Users
|
71
|
+
include UsersAdmin
|
72
|
+
include UsersPrefs
|
61
73
|
include UsersProfile
|
62
74
|
end
|
63
75
|
end
|
@@ -1,43 +1,45 @@
|
|
1
|
-
|
2
|
-
module
|
3
|
-
module
|
4
|
-
module
|
5
|
-
module
|
6
|
-
|
1
|
+
if defined?(Picky)
|
2
|
+
module Slack
|
3
|
+
module Web
|
4
|
+
module Api
|
5
|
+
module Mixins
|
6
|
+
module Users
|
7
|
+
Member = Struct.new :id, :name, :first_name, :last_name, :real_name, :email
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
#
|
10
|
+
# This method searches for users.
|
11
|
+
#
|
12
|
+
# @option options [user] :user
|
13
|
+
# Free-formed text to search for.
|
14
|
+
def users_search(options = {})
|
15
|
+
query = options[:user]
|
16
|
+
throw ArgumentError.new('Required arguments :user missing') if query.nil?
|
17
|
+
index = Picky::Index.new(:users) do
|
18
|
+
category :name
|
19
|
+
category :first_name
|
20
|
+
category :last_name
|
21
|
+
category :real_name
|
22
|
+
category :email
|
23
|
+
end
|
24
|
+
members = users_list.members
|
25
|
+
members.each_with_index do |member, id|
|
26
|
+
user = Member.new(
|
27
|
+
id,
|
28
|
+
member.name,
|
29
|
+
member.profile.first_name,
|
30
|
+
member.profile.last_name,
|
31
|
+
member.profile.real_name,
|
32
|
+
member.profile.email
|
33
|
+
)
|
34
|
+
index.add(user)
|
35
|
+
end
|
36
|
+
ids = Picky::Search.new(index).search(query, 5, 0, unique: true).ids
|
37
|
+
results = ids.map { |id| members[id] }
|
38
|
+
Slack::Messages::Message.new('ok' => true, 'members' => results)
|
22
39
|
end
|
23
|
-
members = users_list.members
|
24
|
-
members.each_with_index do |member, id|
|
25
|
-
user = Member.new(
|
26
|
-
id,
|
27
|
-
member.name,
|
28
|
-
member.profile.first_name,
|
29
|
-
member.profile.last_name,
|
30
|
-
member.profile.real_name,
|
31
|
-
member.profile.email
|
32
|
-
)
|
33
|
-
index.add(user)
|
34
|
-
end
|
35
|
-
ids = Picky::Search.new(index).search(query, 5, 0, unique: true).ids
|
36
|
-
results = ids.map { |id| members[id] }
|
37
|
-
Slack::Messages::Message.new('ok' => true, 'members' => results)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
43
|
-
end
|
45
|
+
end
|
@@ -3,7 +3,7 @@ index 1f7a8d7..2ec4bed 100644
|
|
3
3
|
--- a/lib/slack/web/api/endpoints/chat.rb
|
4
4
|
+++ b/lib/slack/web/api/endpoints/chat.rb
|
5
5
|
@@ -49,7 +49,7 @@ module Slack
|
6
|
-
# @see https://github.com/
|
6
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/chat/chat.postMessage.json
|
7
7
|
def chat_postMessage(options = {})
|
8
8
|
throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
|
9
9
|
- throw ArgumentError.new('Required arguments :text missing') if options[:text].nil?
|
@@ -1,13 +1,14 @@
|
|
1
1
|
diff --git a/lib/slack/web/api/endpoints/chat.rb b/lib/slack/web/api/endpoints/chat.rb
|
2
|
-
index
|
2
|
+
index 5186416..490bc91 100644
|
3
3
|
--- a/lib/slack/web/api/endpoints/chat.rb
|
4
4
|
+++ b/lib/slack/web/api/endpoints/chat.rb
|
5
|
-
@@ -
|
5
|
+
@@ -154,9 +154,15 @@ module Slack
|
6
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/chat/chat.update.json
|
6
7
|
def chat_update(options = {})
|
7
|
-
throw ArgumentError.new('Required arguments :ts missing') if options[:ts].nil?
|
8
8
|
throw ArgumentError.new('Required arguments :channel missing') if options[:channel].nil?
|
9
9
|
- throw ArgumentError.new('Required arguments :text missing') if options[:text].nil?
|
10
10
|
+ throw ArgumentError.new('Required arguments :text or :attachments missing') if options[:text].nil? && options[:attachments].nil?
|
11
|
+
throw ArgumentError.new('Required arguments :ts missing') if options[:ts].nil?
|
11
12
|
options = options.merge(channel: channels_id(options)['channel']['id']) if options[:channel]
|
12
13
|
+ # attachments must be passed as an encoded JSON string
|
13
14
|
+ if options.key?(:attachments)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
diff --git a/lib/slack/web/api/endpoints/chat.rb b/lib/slack/web/api/endpoints/chat.rb
|
2
|
+
index 846126e..0c254c6 100644
|
3
|
+
--- a/lib/slack/web/api/endpoints/chat.rb
|
4
|
+
+++ b/lib/slack/web/api/endpoints/chat.rb
|
5
|
+
@@ -62,6 +62,12 @@ module Slack
|
6
|
+
throw ArgumentError.new('Required arguments :text missing') if options[:text].nil?
|
7
|
+
throw ArgumentError.new('Required arguments :user missing') if options[:user].nil?
|
8
|
+
options = options.merge(user: users_id(options)['user']['id']) if options[:user]
|
9
|
+
+ # attachments must be passed as an encoded JSON string
|
10
|
+
+ if options.key?(:attachments)
|
11
|
+
+ attachments = options[:attachments]
|
12
|
+
+ attachments = JSON.dump(attachments) unless attachments.is_a?(String)
|
13
|
+
+ options = options.merge(attachments: attachments)
|
14
|
+
+ end
|
15
|
+
post('chat.postEphemeral', options)
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
diff --git a/lib/slack/web/api/endpoints/dialog.rb b/lib/slack/web/api/endpoints/dialog.rb
|
2
|
+
index 01f9dfd..d017adf 100644
|
3
|
+
--- a/lib/slack/web/api/endpoints/dialog.rb
|
4
|
+
+++ b/lib/slack/web/api/endpoints/dialog.rb
|
5
|
+
@@ -17,6 +17,12 @@ module Slack
|
6
|
+
def dialog_open(options = {})
|
7
|
+
throw ArgumentError.new('Required arguments :dialog missing') if options[:dialog].nil?
|
8
|
+
throw ArgumentError.new('Required arguments :trigger_id missing') if options[:trigger_id].nil?
|
9
|
+
+ # dialog must be passed as an encoded JSON string
|
10
|
+
+ if options.key?(:dialog)
|
11
|
+
+ dialog = options[:dialog]
|
12
|
+
+ dialog = JSON.dump(dialog) unless dialog.is_a?(String)
|
13
|
+
+ options = options.merge(dialog: dialog)
|
14
|
+
+ end
|
15
|
+
post('dialog.open', options)
|
16
|
+
end
|
17
|
+
end
|
@@ -7,11 +7,12 @@ desc "<%= desc %>"
|
|
7
7
|
desc '<%= desc %>'
|
8
8
|
<% end %>
|
9
9
|
command '<%= group['name'].gsub(".", "_") %>' do |g|
|
10
|
-
<% names.each_with_index do |(name, data), index| %>
|
10
|
+
<% names.sort.each_with_index do |(name, data), index| %>
|
11
11
|
<% if index > 0 %>
|
12
12
|
|
13
13
|
<% end %>
|
14
14
|
<% short_desc = data["desc"].split("\n").first %>
|
15
|
+
<% short_desc += ' (undocumented)' if data['undocumented'] %>
|
15
16
|
<% if short_desc.include?("'") %>
|
16
17
|
g.desc "<%= short_desc %>"
|
17
18
|
<% else %>
|
@@ -20,8 +21,8 @@ command '<%= group['name'].gsub(".", "_") %>' do |g|
|
|
20
21
|
g.long_desc %( <%= data["desc"].split("\n").join(" ") %> )
|
21
22
|
g.command '<%= name %>' do |c|
|
22
23
|
<% data["args"].each do |arg_name, arg_v| %>
|
23
|
-
<% if arg_v["desc"].include?("'")
|
24
|
-
c.flag '<%= arg_name %>', desc: "<%= arg_v["desc"] %>"
|
24
|
+
<% if arg_v["desc"].include?("'") %>
|
25
|
+
c.flag '<%= arg_name %>', desc: "<%= arg_v["desc"].gsub('"', '\'') %>"
|
25
26
|
<% else %>
|
26
27
|
c.flag '<%= arg_name %>', desc: '<%= arg_v["desc"] %>'
|
27
28
|
<% end %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# This file was auto-generated by lib/tasks/web.rake
|
2
2
|
|
3
|
-
<% files.each do |f| %>
|
3
|
+
<% files.sort.each do |f| %>
|
4
4
|
require_relative 'endpoints/<%= f %>'
|
5
5
|
<% end %>
|
6
6
|
|
@@ -12,7 +12,7 @@ module Slack
|
|
12
12
|
include Slack::Web::Api::Mixins::Users
|
13
13
|
include Slack::Web::Api::Mixins::Groups
|
14
14
|
|
15
|
-
<% files.each do |f| %>
|
15
|
+
<% files.sort.each do |f| %>
|
16
16
|
include <%= f.camelize %>
|
17
17
|
<% end %>
|
18
18
|
end
|
@@ -5,13 +5,14 @@ module Slack
|
|
5
5
|
module Api
|
6
6
|
module Endpoints
|
7
7
|
module <%= group.gsub(".", "_").camelize %>
|
8
|
-
<% names.each_with_index do |(name, data), index| %>
|
8
|
+
<% names.sort.each_with_index do |(name, data), index| %>
|
9
9
|
<% next if data['mixin'] %>
|
10
10
|
<% if index > 0 %>
|
11
11
|
|
12
12
|
<% end %>
|
13
13
|
#
|
14
|
-
<% data['desc'].split("\n").
|
14
|
+
<% data['desc'].split("\n").each_with_index do |line, index| %>
|
15
|
+
<% line += ' (undocumented)' if data['undocumented'] && index == 0 %>
|
15
16
|
# <%= line %>
|
16
17
|
<% end %>
|
17
18
|
#
|
@@ -25,8 +26,12 @@ module Slack
|
|
25
26
|
<% end %>
|
26
27
|
<% end %>
|
27
28
|
<% end %>
|
29
|
+
<% if data['undocumented'] %>
|
30
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/undocumented/<%= group %>/<%= group %>.<%= name %>.json
|
31
|
+
<% else %>
|
28
32
|
# @see https://api.slack.com/methods/<%= group %>.<%= name %>
|
29
|
-
# @see https://github.com/
|
33
|
+
# @see https://github.com/slack-ruby/slack-api-ref/blob/master/methods/<%= group %>/<%= group %>.<%= name %>.json
|
34
|
+
<% end %>
|
30
35
|
def <%= group.gsub(".", "_") %>_<%= name %>(options = {})
|
31
36
|
<% data['args'].select{ |k, v| v['required'] }.each do |arg_name, arg_v| %>
|
32
37
|
throw ArgumentError.new('Required arguments :<%= arg_name %> missing') if options[:<%= arg_name %>].nil?
|
@@ -39,7 +44,17 @@ module Slack
|
|
39
44
|
<% if data['args']['user'] %>
|
40
45
|
options = options.merge(user: users_id(options)['user']['id']) if options[:user]
|
41
46
|
<% end %>
|
47
|
+
<% if data['args'].keys.include?('cursor') %>
|
48
|
+
if block_given?
|
49
|
+
Pagination::Cursor.new(self, :<%= group.gsub(".", "_") %>_<%= name %>, options).each do |page|
|
50
|
+
yield page
|
51
|
+
end
|
52
|
+
else
|
53
|
+
post('<%= group %>.<%= name %>', options)
|
54
|
+
end
|
55
|
+
<% else %>
|
42
56
|
post('<%= group %>.<%= name %>', options)
|
57
|
+
<% end %>
|
43
58
|
end
|
44
59
|
<% end %>
|
45
60
|
end
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe Slack::Web::Api::Endpoints::<%= group.gsub(".", "_").camelize %> do
|
6
6
|
let(:client) { Slack::Web::Client.new }
|
7
|
-
<% names.each_with_index do |(name, data), index| %>
|
7
|
+
<% names.sort.each_with_index do |(name, data), index| %>
|
8
8
|
<% next if data['mixin'] %>
|
9
9
|
<% required_params = data['args'].select{ |k, v| v['required'] } %>
|
10
10
|
<% next if required_params.none? %>
|
data/lib/slack/web/config.rb
CHANGED
@@ -3,16 +3,18 @@ module Slack
|
|
3
3
|
module Config
|
4
4
|
extend self
|
5
5
|
|
6
|
-
ATTRIBUTES = [
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
ATTRIBUTES = %i[
|
7
|
+
proxy
|
8
|
+
user_agent
|
9
|
+
ca_path
|
10
|
+
ca_file
|
11
|
+
logger
|
12
|
+
endpoint
|
13
|
+
token
|
14
|
+
timeout
|
15
|
+
open_timeout
|
16
|
+
default_page_size
|
17
|
+
default_max_retries
|
16
18
|
].freeze
|
17
19
|
|
18
20
|
attr_accessor(*Config::ATTRIBUTES)
|
@@ -20,13 +22,15 @@ module Slack
|
|
20
22
|
def reset
|
21
23
|
self.endpoint = 'https://slack.com/api/'
|
22
24
|
self.user_agent = "Slack Ruby Client/#{Slack::VERSION}"
|
23
|
-
self.ca_path =
|
24
|
-
self.ca_file =
|
25
|
+
self.ca_path = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_DIR : nil
|
26
|
+
self.ca_file = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_FILE : nil
|
25
27
|
self.token = nil
|
26
28
|
self.proxy = nil
|
27
29
|
self.logger = nil
|
28
30
|
self.timeout = nil
|
29
31
|
self.open_timeout = nil
|
32
|
+
self.default_page_size = 100
|
33
|
+
self.default_max_retries = 100
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
@@ -11,7 +11,7 @@ module Slack
|
|
11
11
|
|
12
12
|
options[:headers]['User-Agent'] = user_agent if user_agent
|
13
13
|
options[:proxy] = proxy if proxy
|
14
|
-
options[:ssl] = { ca_path: ca_path, ca_file: ca_file }
|
14
|
+
options[:ssl] = { ca_path: ca_path, ca_file: ca_file } if ca_path || ca_file
|
15
15
|
|
16
16
|
request_options = {}
|
17
17
|
request_options[:timeout] = timeout if timeout
|
@@ -5,11 +5,11 @@ module Slack
|
|
5
5
|
class RaiseError < ::Faraday::Response::Middleware
|
6
6
|
def on_complete(env)
|
7
7
|
if env.status == 429
|
8
|
-
|
8
|
+
raise Slack::Web::Api::Errors::TooManyRequestsError, env.response
|
9
9
|
elsif (body = env.body) && body['ok']
|
10
|
-
|
10
|
+
nil
|
11
11
|
else
|
12
|
-
|
12
|
+
raise Slack::Web::Api::Errors::SlackError.new(body['error'], env.response)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|