slack-api-wrapper 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +2 -0
- data/.coveralls.yml +1 -0
- data/{spec/slack/oauth2/flow_base_spec.rb → .simplecov} +0 -0
- data/.travis.yml +18 -1
- data/.yardopts +9 -0
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/{LICENSE.txt → MIT-LICENSE} +0 -0
- data/README.md +50 -11
- data/Rakefile +3 -4
- data/lib/slack-api-wrapper.rb +15 -92
- data/lib/slack/client.rb +5 -6
- data/lib/slack/error.rb +1 -9
- data/lib/slack/request.rb +56 -0
- data/lib/slack/session.rb +20 -55
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api.rb +4 -5
- data/lib/slack/web/auth.rb +4 -4
- data/lib/slack/web/channels.rb +60 -61
- data/lib/slack/web/chat.rb +17 -18
- data/lib/slack/web/emoji.rb +4 -4
- data/lib/slack/web/files.rb +16 -16
- data/lib/slack/web/groups.rb +81 -68
- data/lib/slack/web/im.rb +21 -22
- data/lib/slack/web/pins.rb +65 -0
- data/lib/slack/web/reactions.rb +97 -0
- data/lib/slack/web/search.rb +17 -18
- data/lib/slack/web/stars.rb +4 -5
- data/lib/slack/web/team.rb +12 -4
- data/lib/slack/web/users.rb +22 -23
- data/slack-api-wrapper.gemspec +13 -11
- data/spec/slack/client_spec.rb +2 -3
- data/spec/slack/session_spec.rb +21 -0
- data/spec/slack_spec.rb +0 -19
- data/spec/spec_helper.rb +81 -1
- metadata +52 -16
- data/lib/slack/oauth2.rb +0 -10
- data/lib/slack/oauth2/flow.rb +0 -165
- data/lib/slack/oauth2/flow_base.rb +0 -81
- data/spec/slack/oauth2/flow_spec.rb +0 -0
- data/spec/slack/oauth2_spec.rb +0 -7
data/lib/slack/web/im.rb
CHANGED
@@ -7,7 +7,7 @@ module Slack
|
|
7
7
|
# Get info on your direct messages.
|
8
8
|
module Im
|
9
9
|
# Endpoint scope
|
10
|
-
SCOPE =
|
10
|
+
SCOPE = 'im'
|
11
11
|
|
12
12
|
# Close a direct message channel.
|
13
13
|
#
|
@@ -17,10 +17,10 @@ module Slack
|
|
17
17
|
# Direct message channel to close.
|
18
18
|
#
|
19
19
|
# @see https://api.slack.com/methods/im.close
|
20
|
-
def im_close(params={})
|
21
|
-
|
22
|
-
response = @session.
|
23
|
-
Slack
|
20
|
+
def im_close(params = {})
|
21
|
+
fail ArgumentError, "Required arguments 'channel' missing" if params['channel'].nil?
|
22
|
+
response = @session.do_post "#{SCOPE}.close", params
|
23
|
+
Slack.parse_response(response)
|
24
24
|
end
|
25
25
|
|
26
26
|
# Fetches history of messages and events from direct message channel.
|
@@ -39,10 +39,10 @@ module Slack
|
|
39
39
|
# Number of messages to return, between 1 and 1000.
|
40
40
|
#
|
41
41
|
# @see https://api.slack.com/methods/im.history
|
42
|
-
def im_history(params={})
|
43
|
-
|
44
|
-
response = @session.
|
45
|
-
Slack
|
42
|
+
def im_history(params = {})
|
43
|
+
fail ArgumentError, "Required arguments 'channel' missing" if params['channel'].nil?
|
44
|
+
response = @session.do_post "#{SCOPE}.history", params
|
45
|
+
Slack.parse_response(response)
|
46
46
|
end
|
47
47
|
|
48
48
|
# Lists direct message channels for the calling user.
|
@@ -51,9 +51,9 @@ module Slack
|
|
51
51
|
# API call arguments
|
52
52
|
#
|
53
53
|
# @see https://api.slack.com/methods/im.list
|
54
|
-
def im_list(params={})
|
55
|
-
response = @session.
|
56
|
-
Slack
|
54
|
+
def im_list(params = {})
|
55
|
+
response = @session.do_post "#{SCOPE}.list", params
|
56
|
+
Slack.parse_response(response)
|
57
57
|
end
|
58
58
|
|
59
59
|
# Sets the read cursor in a direct message channel.
|
@@ -66,11 +66,11 @@ module Slack
|
|
66
66
|
# Timestamp of the most recently seen message.
|
67
67
|
#
|
68
68
|
# @see https://api.slack.com/methods/im.mark
|
69
|
-
def im_mark(params={})
|
70
|
-
|
71
|
-
|
72
|
-
response = @session.
|
73
|
-
Slack
|
69
|
+
def im_mark(params = {})
|
70
|
+
fail ArgumentError, "Required arguments 'channel' missing" if params['channel'].nil?
|
71
|
+
fail ArgumentError, "Required arguments 'ts' missing" if params['ts'].nil?
|
72
|
+
response = @session.do_post "#{SCOPE}.mark", params
|
73
|
+
Slack.parse_response(response)
|
74
74
|
end
|
75
75
|
|
76
76
|
# Opens a direct message channel.
|
@@ -81,12 +81,11 @@ module Slack
|
|
81
81
|
# User to open a direct message channel with.
|
82
82
|
#
|
83
83
|
# @see https://api.slack.com/methods/im.open
|
84
|
-
def im_open(params={})
|
85
|
-
|
86
|
-
response = @session.
|
87
|
-
Slack
|
84
|
+
def im_open(params = {})
|
85
|
+
fail ArgumentError, "Required arguments 'user' missing" if params['user'].nil?
|
86
|
+
response = @session.do_post "#{SCOPE}.open", params
|
87
|
+
Slack.parse_response(response)
|
88
88
|
end
|
89
|
-
|
90
89
|
end
|
91
90
|
end
|
92
91
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Slack
|
2
|
+
module Web
|
3
|
+
# Module for the pins methods.
|
4
|
+
module Pins
|
5
|
+
# Endpoint scope
|
6
|
+
SCOPE = 'pins'
|
7
|
+
|
8
|
+
# This method pins an item (file, file comment, channel message,
|
9
|
+
# or group message) to a particular channel.
|
10
|
+
#
|
11
|
+
# @param [Hash] params
|
12
|
+
# API call arguments
|
13
|
+
# @option params [Object] 'channel'
|
14
|
+
# Channel to pin the item in.
|
15
|
+
# @option params [Object] 'file'
|
16
|
+
# File to pin.
|
17
|
+
# @option params [Object] 'file_comment'
|
18
|
+
# File comment to pin.
|
19
|
+
# @option params [Object] 'timestamp'
|
20
|
+
# Timestamp of the message to pin.
|
21
|
+
#
|
22
|
+
# @see https://api.slack.com/methods/pins.add
|
23
|
+
def pins_add(params = {})
|
24
|
+
fail ArgumentError, "Required arguments 'channel' missing" if params['channel'].nil?
|
25
|
+
response = @session.do_post "#{SCOPE}.add", params
|
26
|
+
Slack.parse_response(response)
|
27
|
+
end
|
28
|
+
|
29
|
+
# This method lists the items pinned to a channel.
|
30
|
+
#
|
31
|
+
# @param [Hash] params
|
32
|
+
# API call arguments
|
33
|
+
# @option params [Object] 'channel'
|
34
|
+
# Channel to get pinned items for.
|
35
|
+
#
|
36
|
+
# @see https://api.slack.com/methods/pins.list
|
37
|
+
def pins_list(params = {})
|
38
|
+
fail ArgumentError, "Required arguments 'channel' missing" if params['channel'].nil?
|
39
|
+
response = @session.do_post "#{SCOPE}.list", params
|
40
|
+
Slack.parse_response(response)
|
41
|
+
end
|
42
|
+
|
43
|
+
# This method un-pins an item (file, file comment, channel message,
|
44
|
+
# or group message) from a channel.
|
45
|
+
#
|
46
|
+
# @param [Hash] params
|
47
|
+
# API call arguments
|
48
|
+
# @option params [Object] 'channel'
|
49
|
+
# Channel to pin the item in.
|
50
|
+
# @option params [Object] 'file'
|
51
|
+
# File to pin.
|
52
|
+
# @option params [Object] 'file_comment'
|
53
|
+
# File comment to pin.
|
54
|
+
# @option params [Object] 'timestamp'
|
55
|
+
# Timestamp of the message to pin.
|
56
|
+
#
|
57
|
+
# @see https://api.slack.com/methods/pins.remove
|
58
|
+
def pins_remove(params = {})
|
59
|
+
fail ArgumentError, "Required arguments 'channel' missing" if params['channel'].nil?
|
60
|
+
response = @session.do_post "#{SCOPE}.remove", params
|
61
|
+
Slack.parse_response(response)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Slack
|
2
|
+
module Web
|
3
|
+
# Module for the ractions methods.
|
4
|
+
module Reactions
|
5
|
+
# Endpoint scope
|
6
|
+
SCOPE = 'reactions'
|
7
|
+
|
8
|
+
# This method adds a reaction (emoji) to an item
|
9
|
+
# (file, file comment, channel message, group message, or direct message).
|
10
|
+
#
|
11
|
+
# @param [Hash] params
|
12
|
+
# API call arguments
|
13
|
+
# @option params [Object] 'name'
|
14
|
+
# Reaction (emoji) name.
|
15
|
+
# @option params [Object] 'file'
|
16
|
+
# File to add reaction to.
|
17
|
+
# @option params [Object] 'file_comment'
|
18
|
+
# File comment to add reaction to.
|
19
|
+
# @option params [Object] 'channel'
|
20
|
+
# Channel where the message to add reaction to was posted.
|
21
|
+
# @option params [Object] 'timestamp'
|
22
|
+
# Timestamp of the message to add reaction to.
|
23
|
+
#
|
24
|
+
# @see https://api.slack.com/methods/reactions.add
|
25
|
+
def reactions_add(params = {})
|
26
|
+
fail ArgumentError, "Required arguments 'name' missing" if params['name'].nil?
|
27
|
+
response = @session.do_post "#{SCOPE}.add", params
|
28
|
+
Slack.parse_response(response)
|
29
|
+
end
|
30
|
+
|
31
|
+
# This method returns a list of all reactions for a single item
|
32
|
+
# (file, file comment, channel message, group message, or direct message).
|
33
|
+
#
|
34
|
+
# @param [Hash] params
|
35
|
+
# API call arguments
|
36
|
+
# @option params [Object] 'file'
|
37
|
+
# File to get reactions for.
|
38
|
+
# @option params [Object] 'file_comment'
|
39
|
+
# File comment to get reactions for.
|
40
|
+
# @option params [Object] 'channel'
|
41
|
+
# Channel where the message to get reactions for was posted.
|
42
|
+
# @option params [Object] 'timestamp'
|
43
|
+
# Timestamp of the message to get reactions for.
|
44
|
+
# @option params [Object] 'full'
|
45
|
+
# If true always return the complete reaction list.
|
46
|
+
#
|
47
|
+
# @see https://api.slack.com/methods/reactions.get
|
48
|
+
def reactions_get(params = {})
|
49
|
+
response = @session.do_post "#{SCOPE}.add", params
|
50
|
+
Slack.parse_response(response)
|
51
|
+
end
|
52
|
+
|
53
|
+
# This method returns a list of all items (file, file comment,
|
54
|
+
# channel message, group message, or direct message) reacted to by a user.
|
55
|
+
#
|
56
|
+
# @param [Hash] params
|
57
|
+
# API call arguments
|
58
|
+
# @option params [Object] 'user'
|
59
|
+
# Show reactions made by this user. Defaults to the authed user.
|
60
|
+
# @option params [Object] 'full'
|
61
|
+
# If true always return the complete reaction list.
|
62
|
+
# @option params [Object] 'count'
|
63
|
+
# Number of items to return per page.
|
64
|
+
# @option params [Object] 'page'
|
65
|
+
# Page number of results to return.
|
66
|
+
#
|
67
|
+
# @see https://api.slack.com/methods/reactions.list
|
68
|
+
def reactions_list(params = {})
|
69
|
+
response = @session.do_post "#{SCOPE}.list", params
|
70
|
+
Slack.parse_response(response)
|
71
|
+
end
|
72
|
+
|
73
|
+
# This method removes a reaction (emoji) from an item (file, file comment,
|
74
|
+
# channel message, group message, or direct message)
|
75
|
+
#
|
76
|
+
# @param [Hash] params
|
77
|
+
# API call arguments
|
78
|
+
# @option params [Object] 'name'
|
79
|
+
# Reaction (emoji) name.
|
80
|
+
# @option params [Object] 'file'
|
81
|
+
# File to remove reaction from.
|
82
|
+
# @option params [Object] 'file_comment'
|
83
|
+
# File comment to remove reaction from.
|
84
|
+
# @option params [Object] 'channel'
|
85
|
+
# Channel where the message to remove reaction from was posted.
|
86
|
+
# @option params [Object] 'timestamp'
|
87
|
+
# Timestamp of the message to remove reaction from.
|
88
|
+
#
|
89
|
+
# @see https://api.slack.com/methods/reactions.remove
|
90
|
+
def reactions_remove(params = {})
|
91
|
+
fail ArgumentError, "Required arguments 'name' missing" if params['name'].nil?
|
92
|
+
response = @session.do_post "#{SCOPE}.remove", params
|
93
|
+
Slack.parse_response(response)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/slack/web/search.rb
CHANGED
@@ -7,19 +7,19 @@ module Slack
|
|
7
7
|
# Search your team's files and messages.
|
8
8
|
module Search
|
9
9
|
# Endpoint scope
|
10
|
-
SCOPE =
|
10
|
+
SCOPE = 'search'
|
11
11
|
|
12
12
|
# Searches for messages and files matching a query.
|
13
13
|
#
|
14
14
|
# @param [Hash] params
|
15
15
|
# API call arguments
|
16
|
-
# @option
|
16
|
+
# @option params [Object] 'query'
|
17
17
|
# Search query. May contains booleans, etc.
|
18
|
-
# @option
|
18
|
+
# @option params [Object] 'sort'
|
19
19
|
# Return matches sorted by either `score` or `timestamp`.
|
20
|
-
# @option
|
20
|
+
# @option params [Object] 'sort_dir'
|
21
21
|
# Change sort direction to ascending (`asc`) or descending (`desc`).
|
22
|
-
# @option
|
22
|
+
# @option params [Object] 'highlight'
|
23
23
|
# Pass a value of `1` to enable query highlight markers.
|
24
24
|
# @option params [Object] 'count'
|
25
25
|
# Number of items to return per page.
|
@@ -27,10 +27,10 @@ module Slack
|
|
27
27
|
# Page number of results to return.
|
28
28
|
#
|
29
29
|
# @see https://api.slack.com/methods/search.all
|
30
|
-
def search_all(params={})
|
31
|
-
|
32
|
-
response = @session.
|
33
|
-
Slack
|
30
|
+
def search_all(params = {})
|
31
|
+
fail ArgumentError, "Required arguments 'query' missing" if params['query'].nil?
|
32
|
+
response = @session.do_post "#{SCOPE}.all", params
|
33
|
+
Slack.parse_response(response)
|
34
34
|
end
|
35
35
|
|
36
36
|
# Searches for files matching a query.
|
@@ -51,10 +51,10 @@ module Slack
|
|
51
51
|
# Page number of results to return.
|
52
52
|
#
|
53
53
|
# @see https://api.slack.com/methods/search.files
|
54
|
-
def search_files(params={})
|
55
|
-
|
56
|
-
response = @session.
|
57
|
-
Slack
|
54
|
+
def search_files(params = {})
|
55
|
+
fail ArgumentError, "Required arguments 'query' missing" if params['query'].nil?
|
56
|
+
response = @session.do_post "#{SCOPE}.files", params
|
57
|
+
Slack.parse_response(response)
|
58
58
|
end
|
59
59
|
|
60
60
|
# Searches for messages matching a query.
|
@@ -75,12 +75,11 @@ module Slack
|
|
75
75
|
# Page number of results to return.
|
76
76
|
#
|
77
77
|
# @see https://api.slack.com/methods/search.messages
|
78
|
-
def search_messages(params={})
|
79
|
-
|
80
|
-
response = @session.
|
81
|
-
Slack
|
78
|
+
def search_messages(params = {})
|
79
|
+
fail ArgumentError, "Required arguments 'query' missing" if params['query'].nil?
|
80
|
+
response = @session.do_post "#{SCOPE}.messages", params
|
81
|
+
Slack.parse_response(response)
|
82
82
|
end
|
83
|
-
|
84
83
|
end
|
85
84
|
end
|
86
85
|
end
|
data/lib/slack/web/stars.rb
CHANGED
@@ -6,7 +6,7 @@ module Slack
|
|
6
6
|
# Module for the stars methods.
|
7
7
|
module Stars
|
8
8
|
# Endpoint scope
|
9
|
-
SCOPE =
|
9
|
+
SCOPE = 'stars'
|
10
10
|
|
11
11
|
# Lists stars for a user.
|
12
12
|
#
|
@@ -20,11 +20,10 @@ module Slack
|
|
20
20
|
# Page number of results to return.
|
21
21
|
#
|
22
22
|
# @see https://api.slack.com/methods/stars.list
|
23
|
-
def stars_list(params={})
|
24
|
-
response = @session.
|
25
|
-
Slack
|
23
|
+
def stars_list(params = {})
|
24
|
+
response = @session.do_post "#{SCOPE}.list", params
|
25
|
+
Slack.parse_response(response)
|
26
26
|
end
|
27
|
-
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
data/lib/slack/web/team.rb
CHANGED
@@ -6,7 +6,7 @@ module Slack
|
|
6
6
|
# Module for the teams methods.
|
7
7
|
module Team
|
8
8
|
# Endpoint scope
|
9
|
-
SCOPE =
|
9
|
+
SCOPE = 'team'
|
10
10
|
|
11
11
|
# Gets the access logs for a team.
|
12
12
|
#
|
@@ -18,11 +18,19 @@ module Slack
|
|
18
18
|
# Page number of results to return.
|
19
19
|
#
|
20
20
|
# @see https://api.slack.com/methods/team.access_logs
|
21
|
-
def team_access_logs(params={})
|
22
|
-
response = @session.
|
23
|
-
Slack
|
21
|
+
def team_access_logs(params = {})
|
22
|
+
response = @session.do_post "#{SCOPE}.accessLogs", params
|
23
|
+
Slack.parse_response(response)
|
24
24
|
end
|
25
25
|
|
26
|
+
# This method provides information about your team.
|
27
|
+
#
|
28
|
+
# @param [Hash] params
|
29
|
+
# API call arguments
|
30
|
+
def team_info(params = {})
|
31
|
+
response = @session.do_post "#{SCOPE}.info", params
|
32
|
+
Slack.parse_response(response)
|
33
|
+
end
|
26
34
|
end
|
27
35
|
end
|
28
36
|
end
|
data/lib/slack/web/users.rb
CHANGED
@@ -7,34 +7,34 @@ module Slack
|
|
7
7
|
# Get info on members of your Slack team.
|
8
8
|
module Users
|
9
9
|
# Endpoint scope
|
10
|
-
SCOPE =
|
10
|
+
SCOPE = 'users'
|
11
11
|
|
12
12
|
# Gets user presence information.
|
13
13
|
#
|
14
14
|
# @param [Hash] params
|
15
15
|
# API call arguments
|
16
|
-
# @option
|
16
|
+
# @option params [user] 'user'
|
17
17
|
# User to get presence info on. Defaults to the authed user.
|
18
18
|
#
|
19
19
|
# @see https://api.slack.com/methods/users.messages
|
20
|
-
def users_get_presence(params={})
|
21
|
-
|
22
|
-
response = @session.
|
23
|
-
Slack
|
20
|
+
def users_get_presence(params = {})
|
21
|
+
fail ArgumentError, "Required arguments 'user' missing" if params['user'].nil?
|
22
|
+
response = @session.do_post "#{SCOPE}.getPresence", params
|
23
|
+
Slack.parse_response(response)
|
24
24
|
end
|
25
25
|
|
26
26
|
# Gets information about a user.
|
27
27
|
#
|
28
28
|
# @param [Hash] params
|
29
29
|
# API call arguments
|
30
|
-
# @option
|
30
|
+
# @option params [user] 'user'
|
31
31
|
# User to get info on
|
32
32
|
#
|
33
33
|
# @see https://api.slack.com/methods/users.info
|
34
|
-
def users_info(params={})
|
35
|
-
|
36
|
-
response = @session.
|
37
|
-
Slack
|
34
|
+
def users_info(params = {})
|
35
|
+
fail ArgumentError, "Required arguments 'user' missing" if params['user'].nil?
|
36
|
+
response = @session.do_post "#{SCOPE}.info", params
|
37
|
+
Slack.parse_response(response)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Lists all users in a Slack team.
|
@@ -43,9 +43,9 @@ module Slack
|
|
43
43
|
# API call arguments
|
44
44
|
#
|
45
45
|
# @see https://api.slack.com/methods/users.list
|
46
|
-
def users_list(params={})
|
47
|
-
response = @session.
|
48
|
-
Slack
|
46
|
+
def users_list(params = {})
|
47
|
+
response = @session.do_post "#{SCOPE}.list", params
|
48
|
+
Slack.parse_response(response)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Marks a user as active.
|
@@ -54,25 +54,24 @@ module Slack
|
|
54
54
|
# API call arguments
|
55
55
|
#
|
56
56
|
# @see https://api.slack.com/methods/users.setActive
|
57
|
-
def users_set_active(params={})
|
58
|
-
response = @session.
|
59
|
-
Slack
|
57
|
+
def users_set_active(params = {})
|
58
|
+
response = @session.do_post "#{SCOPE}.setActive", params
|
59
|
+
Slack.parse_response(response)
|
60
60
|
end
|
61
61
|
|
62
62
|
# Manually sets user presence.
|
63
63
|
#
|
64
64
|
# @param [Hash] params
|
65
65
|
# API call arguments
|
66
|
-
# @option
|
66
|
+
# @option params [Object] 'presence'
|
67
67
|
# Either `auto` or `away`
|
68
68
|
#
|
69
69
|
# @see https://api.slack.com/methods/users.setPresence
|
70
|
-
def users_set_presence(params={})
|
71
|
-
|
72
|
-
response = @session.
|
73
|
-
Slack
|
70
|
+
def users_set_presence(params = {})
|
71
|
+
fail ArgumentError, "Required arguments 'presence' missing" if params['presence'].nil?
|
72
|
+
response = @session.do_post "#{SCOPE}.setPresence", params
|
73
|
+
Slack.parse_response(response)
|
74
74
|
end
|
75
|
-
|
76
75
|
end
|
77
76
|
end
|
78
77
|
end
|