slack-ruby 1.0.1 → 1.1.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/README.md +5 -1
- data/lib/slack/rpc/client.rb +31 -15
- data/lib/slack/rpc/connection.rb +4 -0
- data/lib/slack/version.rb +1 -1
- data/spec/slack/rpc/client_spec.rb +27 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e68fcd16be5769b5eae186f1cdf3e0dfba4cb71f
|
4
|
+
data.tar.gz: d1236f5db46fd7d9c899757d52adc3baaae540a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 640f155a2531637845966161bc71ff6f0d5c9f3c9bd4ebb2ebf841c8e472e481290e6214dcbfce4437cf8ce9f6d4878533d52deec647425b4d9e24d026043abe
|
7
|
+
data.tar.gz: 69d24276197c67f7d76f2729321632e3d6e17646bf362996825fb24d3dad012d78abff187cb4014fb27beac52e4949ec4bd9650b18fa2a51b29d39cbed4480ae
|
data/README.md
CHANGED
@@ -28,13 +28,17 @@ require "slack"
|
|
28
28
|
# create RPC client object with OAuth token
|
29
29
|
client = Slack::RPC::Client.new("xxxx-xxxxxxxxx-xxxx")
|
30
30
|
|
31
|
+
# or you can set OAuth token after initialization
|
32
|
+
client = Slack::RPC::Client.new()
|
33
|
+
client.token = "yyyy-yyyyyyyyy-yyyy"
|
34
|
+
|
31
35
|
# execute RPC command and retrieve response
|
32
36
|
client.channels.archive(:channel => "C1234567890") do |response|
|
33
37
|
# your own code
|
34
38
|
end
|
35
39
|
|
36
40
|
# or you can get response as returned object
|
37
|
-
response = client.channels.
|
41
|
+
response = client.channels.archive(:channel => "C1234567890")
|
38
42
|
# your own code
|
39
43
|
```
|
40
44
|
|
data/lib/slack/rpc/client.rb
CHANGED
@@ -13,23 +13,39 @@ module Slack
|
|
13
13
|
# Creates a new instance of `Slack::RPC::Client` class
|
14
14
|
#
|
15
15
|
def initialize(token = nil)
|
16
|
-
conn = Connection.new(token)
|
17
|
-
define_command(conn, "api", %w{test})
|
18
|
-
define_command(conn, "auth", %w{test})
|
19
|
-
define_command(conn, "channels", %w{archive create history info invite join kick leave list mark rename setPurpose setTopic unarchive})
|
20
|
-
define_command(conn, "chat", %w{delete postMessage update})
|
21
|
-
define_command(conn, "emoji", %w{list})
|
22
|
-
define_command(conn, "files", %w{info list upload})
|
23
|
-
define_command(conn, "groups", %w{archive close create createChild history invite kick leave list mark open rename setPurpose setTopic unarchive})
|
24
|
-
define_command(conn, "im", %w{close history list mark open})
|
25
|
-
define_command(conn, "oauth", %w{access})
|
26
|
-
define_command(conn, "rtm", %w{start})
|
27
|
-
define_command(conn, "search", %w{all files messages})
|
28
|
-
define_command(conn, "stars", %w{list})
|
29
|
-
define_command(conn, "users", %w{getPresence info list setActive setPresence})
|
16
|
+
@conn = Connection.new(token)
|
17
|
+
define_command(@conn, "api", %w{test})
|
18
|
+
define_command(@conn, "auth", %w{test})
|
19
|
+
define_command(@conn, "channels", %w{archive create history info invite join kick leave list mark rename setPurpose setTopic unarchive})
|
20
|
+
define_command(@conn, "chat", %w{delete postMessage update})
|
21
|
+
define_command(@conn, "emoji", %w{list})
|
22
|
+
define_command(@conn, "files", %w{info list upload})
|
23
|
+
define_command(@conn, "groups", %w{archive close create createChild history invite kick leave list mark open rename setPurpose setTopic unarchive})
|
24
|
+
define_command(@conn, "im", %w{close history list mark open})
|
25
|
+
define_command(@conn, "oauth", %w{access})
|
26
|
+
define_command(@conn, "rtm", %w{start})
|
27
|
+
define_command(@conn, "search", %w{all files messages})
|
28
|
+
define_command(@conn, "stars", %w{list})
|
29
|
+
define_command(@conn, "users", %w{getPresence info list setActive setPresence})
|
30
30
|
end
|
31
31
|
|
32
|
-
# ### Slack::RPC::Client
|
32
|
+
# ### Slack::RPC::Client.token()
|
33
|
+
# get current token
|
34
|
+
#
|
35
|
+
def token
|
36
|
+
@conn.token
|
37
|
+
end
|
38
|
+
|
39
|
+
# ### Slack::RPC::Client.token=(token)
|
40
|
+
# set new token
|
41
|
+
#
|
42
|
+
def token=(token)
|
43
|
+
@conn.token = token
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# ### Slack::RPC::Client.define_command(conn, name, sub_commands)
|
33
49
|
# Create `Slack::RPC::Command` object and store it as instance variable and expose it
|
34
50
|
#
|
35
51
|
def define_command(conn, name, sub_commands)
|
data/lib/slack/rpc/connection.rb
CHANGED
@@ -10,6 +10,8 @@ module Slack
|
|
10
10
|
#
|
11
11
|
class Connection
|
12
12
|
|
13
|
+
attr_accessor :token
|
14
|
+
|
13
15
|
# ### Slack::RPC::Connection.BASE_URL
|
14
16
|
# A base url to invoke Slack RPC-Style command
|
15
17
|
#
|
@@ -44,6 +46,8 @@ module Slack
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
49
|
+
private
|
50
|
+
|
47
51
|
# ### Slack::RPC::Connection.connection
|
48
52
|
# retrieve Faraday Connection object
|
49
53
|
#
|
data/lib/slack/version.rb
CHANGED
@@ -2,8 +2,12 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Slack::RPC::Client do
|
4
4
|
|
5
|
+
before do
|
6
|
+
@base_url = "https://slack.com/api/api.test"
|
7
|
+
end
|
8
|
+
|
5
9
|
it "should have requested with Accept header" do
|
6
|
-
stub = stub_request(:get,
|
10
|
+
stub = stub_request(:get, @base_url)
|
7
11
|
client = Slack::RPC::Client.new()
|
8
12
|
client.api.test()
|
9
13
|
expect(stub.
|
@@ -11,7 +15,7 @@ describe Slack::RPC::Client do
|
|
11
15
|
end
|
12
16
|
|
13
17
|
it "should have requested with User-Agent header" do
|
14
|
-
stub = stub_request(:get,
|
18
|
+
stub = stub_request(:get, @base_url)
|
15
19
|
client = Slack::RPC::Client.new()
|
16
20
|
client.api.test()
|
17
21
|
expect(stub.
|
@@ -19,15 +23,32 @@ describe Slack::RPC::Client do
|
|
19
23
|
end
|
20
24
|
|
21
25
|
it "should have requested with URL-encoded query parameter" do
|
22
|
-
stub = stub_request(:get, "
|
26
|
+
stub = stub_request(:get, @base_url).with(:query => {"foo" => "this is test & spec"})
|
23
27
|
client = Slack::RPC::Client.new()
|
24
|
-
client.api.test(:foo => "this is test")
|
28
|
+
client.api.test(:foo => "this is test & spec")
|
25
29
|
expect(stub).to have_been_made
|
26
30
|
end
|
27
31
|
|
32
|
+
it "can set token at initialization" do
|
33
|
+
client = Slack::RPC::Client.new("0123456789")
|
34
|
+
expect(client.token).to eq("0123456789")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "can set token after initialization" do
|
38
|
+
client = Slack::RPC::Client.new()
|
39
|
+
expect(client.token).to eq(nil)
|
40
|
+
client.token = "0123456789"
|
41
|
+
expect(client.token).to eq("0123456789")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can get token" do
|
45
|
+
client = Slack::RPC::Client.new("0123456789")
|
46
|
+
expect(client.token).to eq("0123456789")
|
47
|
+
end
|
48
|
+
|
28
49
|
context "with token" do
|
29
50
|
it "should have requested with token" do
|
30
|
-
stub = stub_request(:get, "
|
51
|
+
stub = stub_request(:get, @base_url).with(:query => {"token" => "0123456789"})
|
31
52
|
client = Slack::RPC::Client.new("0123456789")
|
32
53
|
client.api.test()
|
33
54
|
expect(stub).to have_been_made
|
@@ -36,7 +57,7 @@ describe Slack::RPC::Client do
|
|
36
57
|
|
37
58
|
context "without token" do
|
38
59
|
it "should have requested without token" do
|
39
|
-
stub = stub_request(:get,
|
60
|
+
stub = stub_request(:get, @base_url)
|
40
61
|
client = Slack::RPC::Client.new()
|
41
62
|
client.api.test()
|
42
63
|
expect(stub).to have_been_made
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- morou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|