slack-api 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +2 -0
  3. data/.rspec +1 -1
  4. data/.travis.yml +5 -0
  5. data/Guardfile +13 -0
  6. data/README.md +4 -0
  7. data/Rakefile +11 -0
  8. data/lib/slack/request.rb +1 -1
  9. data/lib/slack/version.rb +1 -1
  10. data/slack.gemspec +7 -2
  11. data/spec/api_spec.rb +23 -0
  12. data/spec/auth_spec.rb +22 -0
  13. data/spec/channels_spec.rb +247 -0
  14. data/spec/spec_helper.rb +81 -2
  15. data/spec/vcr/Slack_Client/api/test/with_extra_arguments.yml +56 -0
  16. data/spec/vcr/Slack_Client/api/test/with_valid_token.yml +56 -0
  17. data/spec/vcr/Slack_Client/auth/test/with_invalid_token.yml +48 -0
  18. data/spec/vcr/Slack_Client/auth/test/with_valid_token.yml +58 -0
  19. data/spec/vcr/Slack_Client/channels/archive/with_name.yml +58 -0
  20. data/spec/vcr/Slack_Client/channels/create/with_taken_name.yml +58 -0
  21. data/spec/vcr/Slack_Client/channels/create/with_test_channel_name.yml +58 -0
  22. data/spec/vcr/Slack_Client/channels/history/with_name.yml +71 -0
  23. data/spec/vcr/Slack_Client/channels/info/with_name.yml +59 -0
  24. data/spec/vcr/Slack_Client/channels/invite/with_valid_arguments.yml +59 -0
  25. data/spec/vcr/Slack_Client/channels/invite/without_argument_channel_.yml +58 -0
  26. data/spec/vcr/Slack_Client/channels/join/with_name.yml +58 -0
  27. data/spec/vcr/Slack_Client/channels/kick/with_arguments.yml +58 -0
  28. data/spec/vcr/Slack_Client/channels/leave/with_channel.yml +58 -0
  29. data/spec/vcr/Slack_Client/channels/list/with_valid_token.yml +63 -0
  30. data/spec/vcr/Slack_Client/channels/mark/with_argument.yml +58 -0
  31. data/spec/vcr/Slack_Client/channels/rename/with_name.yml +58 -0
  32. data/spec/vcr/Slack_Client/channels/setPurpose/with_arguments.yml +58 -0
  33. data/spec/vcr/Slack_Client/channels/setTopic/with_arguments.yml +58 -0
  34. data/spec/vcr/Slack_Client/channels/unarchive/with_channel.yml +58 -0
  35. metadata +129 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ab8f375e0cdb00b0c0780a8b9596651b1aa6c35
4
- data.tar.gz: 5c3f9059587cb8e50c546950bb91b5e6de93bdf9
3
+ metadata.gz: 841242a07455c9fe43175c96551000c156daae4e
4
+ data.tar.gz: c371473964ac40799fead68a389f52162d1ad8ea
5
5
  SHA512:
6
- metadata.gz: bb854eacfe009d2a01ca08a2e51d72cbddd1a0ebee24d7931bb5da2b8b2323c3dfb91c96c50eabaaf194e4520c436c4086dbd171f77c19dd4f1d26b3f3582699
7
- data.tar.gz: e5b2963399ed3496e1f3cf6d33479de7a55da94f84769a621eb32bb7f4e1969d2c27ab1f8431ff1fd0866aefef8ae61b5d0efad8f3ec946076af4c47a12a3399
6
+ metadata.gz: 57afaef0b98185fc93f72fba6b54c7244349de5fd8d61d35102f2901a0f72e8ee0d2814f0d667cb4a5e6c3e8632901680579557451be073540374c1fa916c9f9
7
+ data.tar.gz: aa79615d31b8a232403ee7c6daf64ee8fd2718cf4e10c4a45afaa7373caf97e9b61f7e952695b6624e6c477b3deec251229727ff789cf981c2f75f492b0574be
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-pro
2
+ repo_token: PuedicWJBfk5ghyEc9wUOhloMzBfCeOsL
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format progress
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 2.1.2
3
+
4
+ git:
5
+ submodules: false
data/Guardfile ADDED
@@ -0,0 +1,13 @@
1
+ clearing true
2
+ guard :rspec, cmd: "bundle exec rspec" do
3
+ require "guard/rspec/dsl"
4
+ dsl = Guard::RSpec::Dsl.new(self)
5
+
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ ruby = dsl.ruby
12
+ dsl.watch_spec_files_for(ruby.lib_files)
13
+ end
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Slack
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/slack-api.svg)](http://badge.fury.io/rb/slack-api)
4
+ [![Build Status](https://travis-ci.org/aki017/slack-ruby-gem.svg)](https://travis-ci.org/aki017/slack-ruby-gem)
5
+ [![Coverage Status](https://coveralls.io/repos/aki017/slack-ruby-gem/badge.svg?branch=spec)](https://coveralls.io/r/aki017/slack-ruby-gem?branch=spec)
6
+
3
7
  A Ruby wrapper for the Slack API
4
8
 
5
9
  ## Installation
data/Rakefile CHANGED
@@ -1,2 +1,13 @@
1
1
  require "bundler/gem_tasks"
2
2
  require_relative "./lib/generators/tasks/generate"
3
+
4
+ Bundler.setup :default, :development
5
+
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = FileList['spec/**/*_spec.rb']
11
+ end
12
+
13
+ task default: [:spec]
data/lib/slack/request.rb CHANGED
@@ -25,7 +25,7 @@ module Slack
25
25
 
26
26
  # Perform an HTTP request
27
27
  def request(method, path, options)
28
- options.merge!(token: token)
28
+ options = options.merge(token: token)
29
29
  response = connection.send(method) do |request|
30
30
  case method
31
31
  when :get, :delete
data/lib/slack/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slack
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
data/slack.gemspec CHANGED
@@ -19,8 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
- spec.add_development_dependency "rspec", "~> 2.4"
23
- spec.add_development_dependency "webmock", "~> 1.6"
22
+ spec.add_development_dependency "simplecov"
23
+ spec.add_development_dependency "coveralls"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "guard"
28
+ spec.add_development_dependency "guard-rspec"
24
29
  spec.add_development_dependency "rake"
25
30
  spec.add_development_dependency 'erubis', '~> 2.7.0'
26
31
  spec.add_development_dependency "json-schema"
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
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,86 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start do
9
+ add_filter '.bundle/'
10
+ end
11
+
12
+ require 'slack'
13
+ require 'webmock/rspec'
14
+ require 'vcr'
15
+ WebMock.disable_net_connect!(allow_localhost: true)
16
+
17
+ # this helper is not good
18
+ module Helpers
19
+ def valid_token
20
+ $stderr.puts "Please set valid_token to ENV['TOKEN']" if ENV['TOKEN'].nil?
21
+ @token ||= ENV['TOKEN'] || (print "Token: "; gets.strip)
22
+ end
23
+
24
+ def valid_client
25
+ @valid_client ||= Slack::Client.new(token: valid_token)
26
+ end
27
+
28
+ def invalid_token
29
+ "dummy_token"
30
+ end
31
+
32
+ def invalid_client
33
+ @invalid_client ||= Slack::Client.new(token: invalid_token)
34
+ end
35
+
36
+ def test_user_id
37
+ @test_user_id ||= valid_client.auth_test["user_id"]
38
+ end
39
+
40
+ def test_user_name
41
+ @test_user_name ||= valid_client.auth_test["user"]
42
+ end
43
+
44
+ def another_user_name
45
+ @another_user_name ||= "aki017"
46
+ end
47
+
48
+
49
+ def another_user_id
50
+ @another_user_id ||= "U0399SL90" #valid_client.
51
+ end
52
+
53
+ def test_channel_name
54
+ @ntest_channel_name ||= "gem_testroom"
55
+ end
56
+
57
+ def test_channel_id
58
+ @test_channel_id ||= "C04NL1FKT"
59
+ end
60
+
61
+ def another_channel_name
62
+ @another_channel_name ||= "gem_testroom2"
63
+ end
64
+
65
+ def valid_response
66
+ include({ "ok" => true })
67
+ end
68
+ end
69
+
70
+ include Helpers
1
71
  RSpec.configure do |config|
2
- config.treat_symbols_as_metadata_keys_with_true_values = true
3
72
  config.run_all_when_everything_filtered = true
4
- config.filter_run :focus
73
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
74
 
6
75
  config.order = 'random'
76
+ config.include Helpers
77
+ end
78
+
79
+ VCR.configure do |c|
80
+ c.cassette_library_dir = 'spec/vcr'
81
+ c.hook_into :webmock
82
+ c.allow_http_connections_when_no_cassette = true
83
+ c.default_cassette_options = { :record => :new_episodes }
84
+ c.configure_rspec_metadata!
85
+ c.filter_sensitive_data("<TOKEN>") { valid_token }
7
86
  end