slack-api-wrapper 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,29 +1,82 @@
1
+ # Copyright (c) 2015 Gustavo Bazan
2
+ # MIT License
3
+
1
4
  module Slack
2
5
  module Web
6
+ # Module for the chat methods.
7
+ # Post chat messages to Slack.
3
8
  module Chat
9
+ # Endpoint scope
4
10
  SCOPE = "chat"
5
11
 
6
12
  # Deletes a message.
7
- def chat_delete(params = {})
8
- throw ArgumentError.new("Required arguments :ts missing") if params['ts'].nil?
9
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
13
+ #
14
+ # @param [Hash] params
15
+ # API call arguments
16
+ # @option params [Object] 'ts'
17
+ # Timestamp of the message to be deleted.
18
+ # @option params [channel] 'channel'
19
+ # Channel containing the message to be deleted.
20
+ #
21
+ # @see https://api.slack.com/methods/chat.delete
22
+ def chat_delete(params={})
23
+ raise ArgumentError.new("Required arguments 'ts' missing") if params['ts'].nil?
24
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
10
25
  response = @session.do_get "#{SCOPE}.delete", params
11
26
  Slack::parse_response(response)
12
27
  end
13
28
 
14
29
  # Sends a message to a channel.
15
- def chat_post_message(params = {})
16
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
17
- throw ArgumentError.new("Required arguments :text missing") if params['text'].nil?
30
+ #
31
+ # @param [Hash] params
32
+ # API call arguments
33
+ # @option params [channel] 'channel'
34
+ # Channel to send message to. Can be a public channel, private group or IM channel. Can be an encoded ID, or a name.
35
+ # @option params [Object] 'text'
36
+ # Text of the message to send.
37
+ # @option params [Object] 'username'
38
+ # Name of bot.
39
+ # @option params [Object] 'as_user'
40
+ # Pass true to post the message as the authed user, instead of as a bot
41
+ # @option params [Object] 'parse'
42
+ # Change how messages are treated.
43
+ # @option params [Object] 'link_names'
44
+ # Find and link channel names and usernames.
45
+ # @option params [Object] 'attachments'
46
+ # Structured message attachments.
47
+ # @option params [Object] 'unfurl_links'
48
+ # Pass true to enable unfurling of primarily text-based content.
49
+ # @option params [Object] 'unfurl_media'
50
+ # Pass false to disable unfurling of media content.
51
+ # @option params [Object] 'icon_url'
52
+ # URL to an image to use as the icon for this message
53
+ # @option params [Object] 'icon_emoji'
54
+ # emoji to use as the icon for this message. Overrides `icon_url`.
55
+ #
56
+ # @see https://api.slack.com/methods/chat.postMessage
57
+ def chat_post_message(params={})
58
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
59
+ raise ArgumentError.new("Required arguments 'text' missing") if params['text'].nil?
18
60
  response = @session.do_get "#{SCOPE}.postMessage", params
19
61
  Slack::parse_response(response)
20
62
  end
21
63
 
22
64
  # Updates a message.
23
- def chat_update(params = {})
24
- throw ArgumentError.new("Required arguments :ts missing") if params['ts'].nil?
25
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
26
- throw ArgumentError.new("Required arguments :text missing") if params['text'].nil?
65
+ #
66
+ # @param [Hash] params
67
+ # API call arguments
68
+ # @option params [Object] 'ts'
69
+ # Timestamp of the message to be updated.
70
+ # @option params [channel] 'channel'
71
+ # Channel containing the message to be updated.
72
+ # @option params [Object] 'text'
73
+ # New text for the message, using the default formatting rules.
74
+ #
75
+ # @see https://api.slack.com/methods/chat.update
76
+ def chat_update(params={})
77
+ raise ArgumentError.new("Required arguments 'ts' missing") if params['ts'].nil?
78
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
79
+ raise ArgumentError.new("Required arguments 'text' missing") if params['text'].nil?
27
80
  response = @session.do_get "#{SCOPE}.update", params
28
81
  Slack::parse_response(response)
29
82
  end
@@ -1,9 +1,19 @@
1
+ # Copyright (c) 2015 Gustavo Bazan
2
+ # MIT License
3
+
1
4
  module Slack
2
5
  module Web
6
+ # Module for the emoji methods.
3
7
  module Emoji
8
+ # Endpoint scope
4
9
  SCOPE = "emoji"
5
10
 
6
11
  # Lists custom emoji for a team.
12
+ #
13
+ # @param [Hash] params
14
+ # API call arguments
15
+ #
16
+ # @see https://api.slack.com/methods/emoji.list
7
17
  def emoji_list(params={})
8
18
  response = @session.do_get "#{SCOPE}.list", params
9
19
  Slack::parse_response(response)
@@ -1,29 +1,98 @@
1
+ # Copyright (c) 2015 Gustavo Bazan
2
+ # MIT License
3
+
1
4
  module Slack
2
5
  module Web
6
+ # Module for the files methods.
7
+ # Get info on files uploaded to Slack, upload new files to Slack.
3
8
  module Files
9
+ # Endpoint scope
4
10
  SCOPE = "files"
5
11
 
6
- #Deletes a file.
12
+ # Deletes a file.
13
+ #
14
+ # @param [Hash] params
15
+ # API call arguments
16
+ # @option params [file] 'file'
17
+ # ID of file to delete.
18
+ #
19
+ # @see https://api.slack.com/methods/files.delete
7
20
  def files_delete(params={})
8
- throw ArgumentError.new("Required arguments :file missing") if params['file'].nil?
21
+ raise ArgumentError.new("Required arguments 'file' missing") if params['file'].nil?
9
22
  response = @session.do_get "#{SCOPE}.delete", params
10
23
  Slack::parse_response(response)
11
24
  end
12
25
 
13
26
  # Gets information about a team file.
27
+ #
28
+ # @param [Hash] params
29
+ # API call arguments
30
+ # @option params [file] 'file'
31
+ # File to fetch info for
32
+ # @option params [Object] 'count'
33
+ # Number of items to return per page.
34
+ # @option params [Object] 'page'
35
+ # Page number of results to return.
36
+ #
37
+ # @see https://api.slack.com/methods/files.info
14
38
  def files_info(params={})
15
- throw ArgumentError.new("Required arguments :file missing") if params['file'].nil
39
+ raise ArgumentError.new("Required arguments :file missing") if params['file'].nil
16
40
  response = @session.do_get "#{SCOPE}.info", params
17
41
  Slack::parse_response(response)
18
42
  end
19
43
 
20
44
  # Lists & filters team files.
45
+ #
46
+ # @param [Hash] params
47
+ # API call arguments
48
+ # @option params [user] 'user'
49
+ # Filter files created by a single user.
50
+ # @option params [Object] 'ts_from'
51
+ # Filter files created after this timestamp (inclusive).
52
+ # @option params [Object] 'ts_to'
53
+ # Filter files created before this timestamp (inclusive).
54
+ # @option params [Object] 'types'
55
+ # Filter files by type:
56
+ #
57
+ # * `all` - All files
58
+ # * `posts` - Posts
59
+ # * `snippets` - Snippets
60
+ # * `images` - Image files
61
+ # * `gdocs` - Google docs
62
+ # * `zips` - Zip files
63
+ # * `pdfs` - PDF files
64
+ #
65
+ # You can pass multiple values in the types argument, like `types=posts,snippets`.The default value is `all`, which does not filter the list.
66
+ # @option params [Object] 'count'
67
+ # Number of items to return per page.
68
+ # @option params [Object] 'page'
69
+ # Page number of results to return.
70
+ #
71
+ # @see https://api.slack.com/methods/files.list
21
72
  def files_list(params={})
22
73
  response = @session.do_get "#{SCOPE}.list", params
23
74
  Slack::parse_response(response)
24
75
  end
25
76
 
26
77
  # Uploads or creates a file.
78
+ #
79
+ # @param [Hash] params
80
+ # API call arguments
81
+ # @option params [Object] 'file'
82
+ # File contents via `multipart/form-data`.
83
+ # @option params [Object] 'content'
84
+ # File contents via a POST var.
85
+ # @option params [Object] 'filetype'
86
+ # Slack-internal file type identifier.
87
+ # @option params [Object] 'filename'
88
+ # Filename of file.
89
+ # @option options [Object] 'title'
90
+ # Title of file.
91
+ # @option params [Object] 'initial_comment'
92
+ # Initial comment to add to file.
93
+ # @option params [channel] 'channels'
94
+ # Comma separated list of channels to share the file into.
95
+ # @see https://api.slack.com/methods/files.upload
27
96
  def files_upload(params={})
28
97
  response = @session.do_get "#{SCOPE}.upload", params
29
98
  Slack::parse_response(response)
@@ -1,114 +1,244 @@
1
+ # Copyright (c) 2015 Gustavo Bazan
2
+ # MIT License
3
+
1
4
  module Slack
2
5
  module Web
6
+ # Module for the groups methods.
7
+ # Get info on your team's private groups.
3
8
  module Groups
9
+ # Endpoint scope
4
10
  SCOPE = "groups"
5
11
 
6
12
  # Archives a private group.
13
+ #
14
+ # @param [Hash] params
15
+ # API call arguments
16
+ # @option params [group] 'channel'
17
+ # Private group to archive
18
+ #
19
+ # @see https://api.slack.com/methods/groups.archive
7
20
  def groups_archive(params={})
8
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
21
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
9
22
  response = @session.do_get "#{SCOPE}.archive", params
10
23
  Slack::parse_response(response)
11
24
  end
12
25
 
13
26
  # Closes a private group.
27
+ #
28
+ # @param [Hash] params
29
+ # API call arguments
30
+ # @option params [group] 'channel'
31
+ # Group to close.
32
+ #
33
+ # @see https://api.slack.com/methods/groups.close
14
34
  def groups_close(params={})
15
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
35
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
16
36
  response = @session.do_get "#{SCOPE}.close", params
17
37
  Slack::parse_response(response)
18
38
  end
19
39
 
20
40
  # Creates a private group.
41
+ #
42
+ # @param [Hash] params
43
+ # API call arguments
44
+ # @option params [Object] 'name'
45
+ # Name of group to create
46
+ #
47
+ # @see https://api.slack.com/methods/groups.create
21
48
  def groups_create(params={})
22
- throw ArgumentError.new("Required arguments :name missing") if params['name'].nil?
49
+ raise ArgumentError.new("Required arguments 'name' missing") if params['name'].nil?
23
50
  response = @session.do_get "#{SCOPE}.create", params
24
51
  Slack::parse_response(response)
25
52
  end
26
53
 
27
54
  # Clones and archives a private group.
55
+ #
56
+ # @param [Hash] params
57
+ # API call arguments
58
+ # @option params [Object] 'channel'
59
+ # Group to clone and archive.
60
+ #
61
+ # @see https://api.slack.com/methods/groups.createChild
28
62
  def groups_create_child(params={})
29
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
63
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
30
64
  response = @session.do_get "#{SCOPE}.createChild", params
31
65
  Slack::parse_response(response)
32
66
  end
33
67
 
34
68
  # Fetches history of messages and events from a private group.
69
+ #
70
+ # @param [Hash] params
71
+ # API call arguments
72
+ # @option params [group] 'channel'
73
+ # Group to fetch history for.
74
+ # @option params [timestamp] 'latest'
75
+ # Latest message timestamp to include in results.
76
+ # @option params [timestamp] 'oldest'
77
+ # Oldest message timestamp to include in results.
78
+ # @option params [Object] 'inclusive'
79
+ # Include messages with latest or oldest timestamp in results.
80
+ # @option params [Object] 'count'
81
+ # Number of messages to return, between 1 and 1000.
82
+ #
83
+ # @see https://api.slack.com/methods/groups.history
35
84
  def groups_history(params={})
36
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
85
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
37
86
  response = @session.do_get "#{SCOPE}.history", params
38
87
  Slack::parse_response(response)
39
88
  end
40
89
 
41
90
  # Invites a user to a private group.
91
+ #
92
+ # @param [Hash] params
93
+ # API call arguments
94
+ # @option params [group] 'channel'
95
+ # Private group to invite user to.
96
+ # @option params [user] 'user'
97
+ # User to invite.
98
+ #
99
+ # @see https://api.slack.com/methods/groups.invite
42
100
  def groups_invite(params={})
43
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
44
- throw ArgumentError.new("Required arguments :user missing") if params['user'].nil?
101
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
102
+ raise ArgumentError.new("Required arguments 'user' missing") if params['user'].nil?
45
103
  response = @session.do_get "#{SCOPE}.invite", params
46
104
  Slack::parse_response(response)
47
105
  end
48
106
 
49
107
  # Removes a user from a private group.
108
+ #
109
+ # @param [Hash] params
110
+ # API call arguments
111
+ # @option params [group] 'channel'
112
+ # Group to remove user from.
113
+ # @option params [user] 'user'
114
+ # User to remove from group.
115
+ #
116
+ # @see https://api.slack.com/methods/groups.kick
50
117
  def groups_kick(params={})
51
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
52
- throw ArgumentError.new("Required arguments :user missing") if params['user'].nil?
118
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
119
+ raise ArgumentError.new("Required arguments 'user' missing") if params['user'].nil?
53
120
  response = @session.do_get "#{SCOPE}.kick", params
54
121
  Slack::parse_response(response)
55
122
  end
56
123
 
57
124
  # Leaves a private group.
125
+ # @param [Hash] params
126
+ # API call arguments
127
+ # @option params [group] 'channel'
128
+ # Group to leave
129
+ #
130
+ # @see https://api.slack.com/methods/groups.leave
58
131
  def groups_leave(params={})
59
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
132
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
60
133
  response = @session.do_get "#{SCOPE}.leave", params
61
134
  Slack::parse_response(response)
62
135
  end
63
136
 
64
- # Lists private groups that the calling user has access to..
137
+ # Lists private groups that the calling user has access to.
138
+ #
139
+ # @param [Hash] params
140
+ # API call arguments
141
+ # @option params [Object] 'exclude_archived'
142
+ # Don't return archived groups.
143
+ #
144
+ # @see https://api.slack.com/methods/groups.list
65
145
  def groups_list(params={})
66
146
  response = @session.do_get "#{SCOPE}.list", params
67
147
  Slack::parse_response(response)
68
148
  end
69
149
 
70
150
  # Sets the read cursor in a private group.
151
+ #
152
+ # @param [Hash] params
153
+ # API call arguments
154
+ # @option params [group] 'channel'
155
+ # Group to set reading cursor in.
156
+ # @option params [timestamp] 'ts'
157
+ # Timestamp of the most recently seen message.
158
+ #
159
+ # @see https://api.slack.com/methods/groups.mark
71
160
  def groups_mark(params={})
72
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
73
- throw ArgumentError.new("Required arguments :ts missing") if params['ts'].nil?
161
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
162
+ raise ArgumentError.new("Required arguments 'ts' missing") if params['ts'].nil?
74
163
  response = @session.do_get "#{SCOPE}.mark", params
75
164
  Slack::parse_response(response)
76
165
  end
77
166
 
78
167
  # Opens a private group.
168
+ #
169
+ # @param [Hash] params
170
+ # API call arguments
171
+ # @option params [group] 'channel'
172
+ # Group to open.
173
+ #
174
+ # @see https://api.slack.com/methods/groups.open
79
175
  def groups_open(params={})
80
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
176
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
81
177
  response = @session.do_get "#{SCOPE}.open", params
82
178
  Slack::parse_response(response)
83
179
  end
84
180
 
85
181
  # Renames a private group.
182
+ #
183
+ # @param [Hash] params
184
+ # API call arguments
185
+ # @option params [group] 'channel'
186
+ # Group to rename
187
+ # @option params [Object] 'name'
188
+ # New name for group.
189
+ #
190
+ # @see https://api.slack.com/methods/groups.rename
86
191
  def groups_rename(params={})
87
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
88
- throw ArgumentError.new("Required arguments :name missing") if params['name'].nil?
192
+ raise ArgumentError.new("Required arguments 'channel' missing") if params['channel'].nil?
193
+ raise ArgumentError.new("Required arguments 'name' missing") if params['name'].nil?
89
194
  response = @session.do_get "#{SCOPE}.rename", params
90
195
  Slack::parse_response(response)
91
196
  end
92
197
 
93
198
  # Sets the purpose for a private group.
199
+ #
200
+ # @param [Hash] params
201
+ # API call arguments
202
+ # @option params [group] 'channel'
203
+ # Private group to set the purpose of
204
+ # @option params [Object] 'purpose'
205
+ # The new purpose
206
+ #
207
+ # @see https://api.slack.com/methods/groups.setPurpose
94
208
  def groups_set_purpose(params={})
95
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
96
- throw ArgumentError.new("Required arguments :pupose missing") if params['purpos'].nil?
209
+ raise ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
210
+ raise ArgumentError.new("Required arguments :pupose missing") if params['purpos'].nil?
97
211
  response = @session.do_get "#{SCOPE}.setPurpose", params
98
212
  Slack::parse_response(response)
99
213
  end
100
214
 
101
215
  # Sets the topic for a private group.
216
+ #
217
+ # @param [Hash] params
218
+ # API call arguments
219
+ # @option params [group] 'channel'
220
+ # Private group to set the purpose of
221
+ # @option params [Object] 'topic'
222
+ # The new topic
223
+ #
224
+ # @see https://api.slack.com/methods/groups.setTopic
102
225
  def groups_set_topic(params={})
103
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
104
- throw ArgumentError.new("Required arguments :topic missing") if params['topic'].nil?
226
+ raise ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
227
+ raise ArgumentError.new("Required arguments :topic missing") if params['topic'].nil?
105
228
  response = @session.do_get "#{SCOPE}.setTopic", params
106
229
  Slack::parse_response(response)
107
230
  end
108
231
 
109
232
  # Unarchives a private group.
233
+ #
234
+ # @param [Hash] params
235
+ # API call arguments
236
+ # @option params [group] 'channel'
237
+ # Group to unarchive
238
+ # @raise [ArgumentError] if 'channel' is not present
239
+ # @see https://api.slack.com/methods/groups.unarchive
110
240
  def groups_unarchive(params={})
111
- throw ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
241
+ raise ArgumentError.new("Required arguments :channel missing") if params['channel'].nil?
112
242
  response = @session.do_get "#{SCOPE}.unarchive", params
113
243
  Slack::parse_response(response)
114
244
  end