slack-web-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Guardfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +13 -0
- data/examples/basic.rb +35 -0
- data/lib/faraday/raise_http_exception.rb +51 -0
- data/lib/slack.rb +27 -0
- data/lib/slack/api.rb +24 -0
- data/lib/slack/client.rb +4 -0
- data/lib/slack/configuration.rb +76 -0
- data/lib/slack/connection.rb +29 -0
- data/lib/slack/endpoint.rb +43 -0
- data/lib/slack/endpoint/api.rb +23 -0
- data/lib/slack/endpoint/auth.rb +19 -0
- data/lib/slack/endpoint/channels.rb +236 -0
- data/lib/slack/endpoint/chat.rb +86 -0
- data/lib/slack/endpoint/emoji.rb +19 -0
- data/lib/slack/endpoint/files.rb +100 -0
- data/lib/slack/endpoint/groups.rb +262 -0
- data/lib/slack/endpoint/im.rb +90 -0
- data/lib/slack/endpoint/mpim.rb +90 -0
- data/lib/slack/endpoint/oauth.rb +31 -0
- data/lib/slack/endpoint/pins.rb +64 -0
- data/lib/slack/endpoint/presence.rb +22 -0
- data/lib/slack/endpoint/reactions.rb +94 -0
- data/lib/slack/endpoint/search.rb +80 -0
- data/lib/slack/endpoint/stars.rb +65 -0
- data/lib/slack/endpoint/team.rb +57 -0
- data/lib/slack/endpoint/usergroups.rb +122 -0
- data/lib/slack/endpoint/users.rb +78 -0
- data/lib/slack/error.rb +19 -0
- data/lib/slack/request.rb +41 -0
- data/lib/slack/version.rb +3 -0
- data/slack.gemspec +38 -0
- data/spec/api_spec.rb +23 -0
- data/spec/auth_spec.rb +22 -0
- data/spec/channels_spec.rb +247 -0
- data/spec/spec_helper.rb +86 -0
- metadata +313 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
# This file was auto-generated by lib/generators/tasks/generate.rb
|
2
|
+
|
3
|
+
module Slack
|
4
|
+
module Endpoint
|
5
|
+
module Users
|
6
|
+
#
|
7
|
+
# This method lets you find out information about a user's presence.
|
8
|
+
# Consult the presence documentation for more details.
|
9
|
+
#
|
10
|
+
# @option options [Object] :user
|
11
|
+
# User to get presence info on. Defaults to the authed user.
|
12
|
+
# @see https://api.slack.com/methods/users.getPresence
|
13
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.getPresence.md
|
14
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.getPresence.json
|
15
|
+
def users_getPresence(options={})
|
16
|
+
throw ArgumentError.new("Required arguments :user missing") if options[:user].nil?
|
17
|
+
options[:attachments] = options[:attachments].to_json if Hash === options[:attachments]
|
18
|
+
post("users.getPresence", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# This method returns information about a team member.
|
23
|
+
#
|
24
|
+
# @option options [Object] :user
|
25
|
+
# User to get info on
|
26
|
+
# @see https://api.slack.com/methods/users.info
|
27
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.info.md
|
28
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.info.json
|
29
|
+
def users_info(options={})
|
30
|
+
throw ArgumentError.new("Required arguments :user missing") if options[:user].nil?
|
31
|
+
options[:attachments] = options[:attachments].to_json if Hash === options[:attachments]
|
32
|
+
post("users.info", options)
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# This method returns a list of all users in the team. This includes deleted/deactivated users.
|
37
|
+
#
|
38
|
+
# @option options [Object] :presence
|
39
|
+
# Whether to include presence data in the output
|
40
|
+
# @see https://api.slack.com/methods/users.list
|
41
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.list.md
|
42
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.list.json
|
43
|
+
def users_list(options={})
|
44
|
+
options[:attachments] = options[:attachments].to_json if Hash === options[:attachments]
|
45
|
+
post("users.list", options)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# This method lets the slack messaging server know that the authenticated user
|
50
|
+
# is currently active. Consult the presence documentation for
|
51
|
+
# more details.
|
52
|
+
#
|
53
|
+
# @see https://api.slack.com/methods/users.setActive
|
54
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.setActive.md
|
55
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.setActive.json
|
56
|
+
def users_setActive(options={})
|
57
|
+
options[:attachments] = options[:attachments].to_json if Hash === options[:attachments]
|
58
|
+
post("users.setActive", options)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# This method lets you set the calling user's manual presence.
|
63
|
+
# Consult the presence documentation for more details.
|
64
|
+
#
|
65
|
+
# @option options [Object] :presence
|
66
|
+
# Either auto or away
|
67
|
+
# @see https://api.slack.com/methods/users.setPresence
|
68
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.setPresence.md
|
69
|
+
# @see https://github.com/aki017/slack-api-docs/blob/master/methods/users.setPresence.json
|
70
|
+
def users_setPresence(options={})
|
71
|
+
throw ArgumentError.new("Required arguments :presence missing") if options[:presence].nil?
|
72
|
+
options[:attachments] = options[:attachments].to_json if Hash === options[:attachments]
|
73
|
+
post("users.setPresence", options)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/slack/error.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Slack
|
2
|
+
# Custom error class for rescuing from all Slack errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when Slack returns the HTTP status code 400
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when Slack returns the HTTP status code 404
|
9
|
+
class NotFound < Error; end
|
10
|
+
|
11
|
+
# Raised when Slack returns the HTTP status code 500
|
12
|
+
class InternalServerError < Error; end
|
13
|
+
|
14
|
+
# Raised when Slack returns the HTTP status code 503
|
15
|
+
class ServiceUnavailable < Error; end
|
16
|
+
|
17
|
+
# Raised when a subscription payload hash is invalid
|
18
|
+
class InvalidSignature < Error; end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Slack
|
2
|
+
# Defines HTTP request methods
|
3
|
+
module Request
|
4
|
+
# Perform an HTTP GET request
|
5
|
+
def get(path, options={})
|
6
|
+
request(:get, path, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Perform an HTTP POST request
|
10
|
+
def post(path, options={})
|
11
|
+
request(:post, path, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Perform an HTTP PUT request
|
15
|
+
def put(path, options={})
|
16
|
+
request(:put, path, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Perform an HTTP DELETE request
|
20
|
+
def delete(path, options={})
|
21
|
+
request(:delete, path, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Perform an HTTP request
|
27
|
+
def request(method, path, options)
|
28
|
+
options = options.merge(token: token)
|
29
|
+
response = connection.send(method) do |request|
|
30
|
+
case method
|
31
|
+
when :get, :delete
|
32
|
+
request.url(path, options)
|
33
|
+
when :post, :put
|
34
|
+
request.path = path
|
35
|
+
request.body = options unless options.empty?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
return response.body
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/slack.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "slack/version"
|
5
|
+
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "slack-web-api"
|
9
|
+
spec.version = Slack::VERSION
|
10
|
+
spec.authors = ["keydunov"]
|
11
|
+
spec.email = ["artyom.keydunov@gmail.com"]
|
12
|
+
spec.summary = %q{A Ruby wrapper for the Slack Web API}
|
13
|
+
spec.description = %q{A Ruby wrapper for the Slack Web API}
|
14
|
+
spec.homepage = "https://github.com/keydunov/slack-web-api"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "simplecov"
|
24
|
+
spec.add_development_dependency "coveralls"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
spec.add_development_dependency "vcr"
|
28
|
+
spec.add_development_dependency "guard"
|
29
|
+
spec.add_development_dependency "guard-rspec"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
spec.add_development_dependency 'erubis', '~> 2.7.0'
|
32
|
+
spec.add_development_dependency "json-schema"
|
33
|
+
spec.add_development_dependency "pry"
|
34
|
+
|
35
|
+
spec.add_runtime_dependency "faraday", [">= 0.7", "< 0.10"]
|
36
|
+
spec.add_runtime_dependency "faraday_middleware", "~> 0.8"
|
37
|
+
spec.add_runtime_dependency "multi_json", ">= 1.0.3", "~> 1.0"
|
38
|
+
end
|
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative './spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Slack::Client, :vcr do
|
4
|
+
describe :api do
|
5
|
+
describe :test do
|
6
|
+
it "with valid token" do
|
7
|
+
expect(
|
8
|
+
valid_client.api_test
|
9
|
+
).to valid_response
|
10
|
+
end
|
11
|
+
|
12
|
+
it "with extra arguments" do
|
13
|
+
extra = {
|
14
|
+
"foo" => "bar",
|
15
|
+
"hello" => "world"
|
16
|
+
}
|
17
|
+
expect(
|
18
|
+
valid_client.api_test(extra)["args"]
|
19
|
+
).to include(extra)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/auth_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative './spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Slack::Client, :vcr do
|
4
|
+
describe :auth do
|
5
|
+
describe :test do
|
6
|
+
it "with valid token" do
|
7
|
+
expect(
|
8
|
+
valid_client.auth_test
|
9
|
+
).to valid_response
|
10
|
+
end
|
11
|
+
|
12
|
+
it "with invalid token" do
|
13
|
+
expect(
|
14
|
+
invalid_client.auth_test
|
15
|
+
).to include({
|
16
|
+
"ok" => false,
|
17
|
+
"error" => "invalid_auth"
|
18
|
+
})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,247 @@
|
|
1
|
+
require_relative './spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Slack::Client, :vcr do
|
4
|
+
describe :channels do
|
5
|
+
describe :archive do
|
6
|
+
it "without name" do
|
7
|
+
expect{valid_client.channels_archive}.to raise_error ArgumentError
|
8
|
+
end
|
9
|
+
|
10
|
+
it "with name" do
|
11
|
+
expect(
|
12
|
+
valid_client.channels_archive(channel: test_channel_id)
|
13
|
+
).to include({
|
14
|
+
"ok" => true
|
15
|
+
})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe :history do
|
20
|
+
it "without name" do
|
21
|
+
expect{valid_client.channels_history}.to raise_error ArgumentError
|
22
|
+
end
|
23
|
+
|
24
|
+
it "with name" do
|
25
|
+
expect(
|
26
|
+
valid_client.channels_history(channel: test_channel_id)
|
27
|
+
).to include({
|
28
|
+
"ok" => true
|
29
|
+
})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe :info do
|
34
|
+
it "without name" do
|
35
|
+
expect{valid_client.channels_info}.to raise_error ArgumentError
|
36
|
+
end
|
37
|
+
|
38
|
+
it "with name" do
|
39
|
+
expect(
|
40
|
+
valid_client.channels_info(channel: test_channel_id)
|
41
|
+
).to include({
|
42
|
+
"ok" => true
|
43
|
+
})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe :create do
|
48
|
+
it "without name" do
|
49
|
+
expect{valid_client.channels_create}.to raise_error ArgumentError
|
50
|
+
end
|
51
|
+
|
52
|
+
it "with test_channel_name" do
|
53
|
+
response = valid_client.channels_create name: test_channel_name
|
54
|
+
|
55
|
+
expect(response).to include({ "ok" => true })
|
56
|
+
expect(response["channel"]).to include({ "name" => test_channel_name })
|
57
|
+
end
|
58
|
+
|
59
|
+
it "with taken name" do
|
60
|
+
response = valid_client.channels_create name: "general"
|
61
|
+
|
62
|
+
expect(response).to include({
|
63
|
+
"ok" => false,
|
64
|
+
"error" => "name_taken"
|
65
|
+
})
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe :list do
|
70
|
+
it "with valid token" do
|
71
|
+
response = valid_client.channels_list
|
72
|
+
|
73
|
+
expect(response).to include({ "ok" => true })
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe :invite do
|
78
|
+
it "without arguments" do
|
79
|
+
expect{valid_client.channels_invite}.to raise_error ArgumentError
|
80
|
+
end
|
81
|
+
|
82
|
+
it "without argument(channel)" do
|
83
|
+
expect{valid_client.channels_invite(user: test_user_id)}.to raise_error ArgumentError
|
84
|
+
end
|
85
|
+
|
86
|
+
it "without argument(user)" do
|
87
|
+
expect{valid_client.channels_invite(channel: test_channel_id)}.to raise_error ArgumentError
|
88
|
+
end
|
89
|
+
|
90
|
+
it "with valid arguments" do
|
91
|
+
expect(
|
92
|
+
valid_client.channels_invite(user: another_user_id, channel: test_channel_id)
|
93
|
+
).to include({
|
94
|
+
"ok" => true
|
95
|
+
})
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe :leave do
|
100
|
+
it "without argument" do
|
101
|
+
expect{valid_client.channels_leave}.to raise_error ArgumentError
|
102
|
+
end
|
103
|
+
|
104
|
+
it "with channel" do
|
105
|
+
expect(
|
106
|
+
valid_client.channels_leave(channel: test_channel_id)
|
107
|
+
).to include({
|
108
|
+
"ok" => true
|
109
|
+
})
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe :join do
|
114
|
+
it "without :name" do
|
115
|
+
expect{valid_client.channels_join}.to raise_error ArgumentError
|
116
|
+
end
|
117
|
+
|
118
|
+
it "with :name" do
|
119
|
+
expect(
|
120
|
+
valid_client.channels_join(name: test_channel_name)
|
121
|
+
).to include({
|
122
|
+
"ok" => true
|
123
|
+
})
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe :kick do
|
128
|
+
it "without arguments" do
|
129
|
+
expect{valid_client.channels_kick}.to raise_error ArgumentError
|
130
|
+
end
|
131
|
+
it "without :channel" do
|
132
|
+
expect{valid_client.channels_kick(name: another_user_id)}.to raise_error ArgumentError
|
133
|
+
end
|
134
|
+
it "without :name" do
|
135
|
+
expect{valid_client.channels_kick(channel: test_channel_id)}.to raise_error ArgumentError
|
136
|
+
end
|
137
|
+
it "with arguments" do
|
138
|
+
expect(
|
139
|
+
valid_client.channels_kick(user: another_user_id, channel: test_channel_id)
|
140
|
+
).to include({
|
141
|
+
"ok" => true
|
142
|
+
})
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe :mark do
|
147
|
+
it "without arguments" do
|
148
|
+
expect{valid_client.channels_mark}.to raise_error ArgumentError
|
149
|
+
end
|
150
|
+
|
151
|
+
it "without ts" do
|
152
|
+
expect{valid_client.channels_mark(channel: test_channel_id)}.to raise_error ArgumentError
|
153
|
+
end
|
154
|
+
|
155
|
+
it "without channel" do
|
156
|
+
expect{valid_client.channels_mark(ts: 0)}.to raise_error ArgumentError
|
157
|
+
end
|
158
|
+
it "with argument" do
|
159
|
+
expect(
|
160
|
+
valid_client.channels_mark(channel: test_channel_id, ts: 0)
|
161
|
+
).to include({
|
162
|
+
"ok" => true
|
163
|
+
})
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe :rename do
|
168
|
+
it "without arguments" do
|
169
|
+
expect{valid_client.channels_rename}.to raise_error ArgumentError
|
170
|
+
end
|
171
|
+
|
172
|
+
it "without channel" do
|
173
|
+
expect{valid_client.channels_rename(name: another_channel_name)}.to raise_error ArgumentError
|
174
|
+
end
|
175
|
+
|
176
|
+
it "without name" do
|
177
|
+
expect{valid_client.channels_rename(channel: test_channel_id)}.to raise_error ArgumentError
|
178
|
+
end
|
179
|
+
|
180
|
+
it "with name" do
|
181
|
+
expect(
|
182
|
+
valid_client.channels_rename(channel: test_channel_id, name: another_channel_name)
|
183
|
+
).to include({
|
184
|
+
"ok" => true
|
185
|
+
})
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe :setPurpose do
|
190
|
+
it "without arguments" do
|
191
|
+
expect{valid_client.channels_setPurpose}.to raise_error ArgumentError
|
192
|
+
end
|
193
|
+
|
194
|
+
it "without channel" do
|
195
|
+
expect{valid_client.channels_setPurpose(purpose: "TestPurpose")}.to raise_error ArgumentError
|
196
|
+
end
|
197
|
+
|
198
|
+
it "without topic" do
|
199
|
+
expect{valid_client.channels_setPurpose(channel: test_channel_id)}.to raise_error ArgumentError
|
200
|
+
end
|
201
|
+
|
202
|
+
it "with arguments" do
|
203
|
+
expect(
|
204
|
+
valid_client.channels_setPurpose(channel: test_channel_id, purpose: "TestPurpose")
|
205
|
+
).to include({
|
206
|
+
"ok" => true
|
207
|
+
})
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe :setTopic do
|
212
|
+
it "without arguments" do
|
213
|
+
expect{valid_client.channels_setTopic}.to raise_error ArgumentError
|
214
|
+
end
|
215
|
+
|
216
|
+
it "without channel" do
|
217
|
+
expect{valid_client.channels_setTopic(topic: "TestTopic")}.to raise_error ArgumentError
|
218
|
+
end
|
219
|
+
|
220
|
+
it "without topic" do
|
221
|
+
expect{valid_client.channels_setTopic(channel: test_channel_id)}.to raise_error ArgumentError
|
222
|
+
end
|
223
|
+
|
224
|
+
it "with arguments" do
|
225
|
+
expect(
|
226
|
+
valid_client.channels_setTopic(channel: test_channel_id, topic: "TestTopic")
|
227
|
+
).to include({
|
228
|
+
"ok" => true
|
229
|
+
})
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe :unarchive do
|
234
|
+
it "without :channel" do
|
235
|
+
expect{valid_client.channels_join}.to raise_error ArgumentError
|
236
|
+
end
|
237
|
+
|
238
|
+
it "with :channel" do
|
239
|
+
expect(
|
240
|
+
valid_client.channels_unarchive(channel: test_channel_id)
|
241
|
+
).to include({
|
242
|
+
"ok" => true
|
243
|
+
})
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|