slack_chatter 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/method_config.yml +338 -0
- data/lib/slack_chatter/api/api.rb +12 -0
- data/lib/slack_chatter/api/auth.rb +12 -0
- data/lib/slack_chatter/api/base.rb +25 -0
- data/lib/slack_chatter/api/channels.rb +79 -0
- data/lib/slack_chatter/api/chat.rb +18 -0
- data/lib/slack_chatter/api/emoji.rb +11 -0
- data/lib/slack_chatter/api/files.rb +22 -0
- data/lib/slack_chatter/api/groups.rb +84 -0
- data/lib/slack_chatter/api/im.rb +34 -0
- data/lib/slack_chatter/api/namespaces.rb +81 -0
- data/lib/slack_chatter/api/oauth.rb +14 -0
- data/lib/slack_chatter/api/rtm.rb +8 -0
- data/lib/slack_chatter/api/search.rb +21 -0
- data/lib/slack_chatter/api/stars.rb +11 -0
- data/lib/slack_chatter/api/team.rb +14 -0
- data/lib/slack_chatter/api/users.rb +28 -0
- data/lib/slack_chatter/client.rb +102 -0
- data/lib/slack_chatter/response.rb +23 -0
- data/lib/slack_chatter/version.rb +3 -0
- data/lib/slack_chatter.rb +14 -0
- data/slack_chatter.gemspec +32 -0
- metadata +235 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
module SlackChatter
|
2
|
+
module Api
|
3
|
+
class Base
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def call_method(name_space, slack_method, params, http_method=:get)
|
11
|
+
path = "#{name_space}.#{slack_method}"
|
12
|
+
if http_method.to_sym == :get
|
13
|
+
client.get(path, params)
|
14
|
+
else
|
15
|
+
client.post(path, params)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def bool_as_i(bool)
|
20
|
+
bool ? 1 : 0
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative "./base"
|
2
|
+
module SlackChatter
|
3
|
+
module Api
|
4
|
+
class Channels < SlackChatter::Api::Base
|
5
|
+
|
6
|
+
def find_by_name name
|
7
|
+
list.channels.detect do |channel|
|
8
|
+
channel["name"] == name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def archive channel_id
|
13
|
+
call_method("channels", "archive", {"channel" => channel_id})
|
14
|
+
end
|
15
|
+
|
16
|
+
def create channel_name
|
17
|
+
# channel_name - name of channel to recreate
|
18
|
+
call_method("channels", "create", {"name" => channel_name})
|
19
|
+
end
|
20
|
+
|
21
|
+
def history channel_id, opts={}
|
22
|
+
# latest - End of time range of messages to include in results
|
23
|
+
# oldest - Start of time range of messages to include in results
|
24
|
+
# inclusive - Include messages with latest or oldest timestamp in results (send 0/1)
|
25
|
+
# count - Number of messages to return, between 1 and 1000
|
26
|
+
call_method("channels", "history", {"channel" => channel_id}.merge(opts))
|
27
|
+
end
|
28
|
+
|
29
|
+
def info channel_id
|
30
|
+
call_method("channels", "info", {"channel" => channel_id})
|
31
|
+
end
|
32
|
+
|
33
|
+
def invite channel_id, user_id
|
34
|
+
call_method("channels", "invite", {"channel" => channel_id, "user" => user_id})
|
35
|
+
end
|
36
|
+
|
37
|
+
def join channel_name
|
38
|
+
call_method("channels", "join", {"name" => channel_name})
|
39
|
+
end
|
40
|
+
|
41
|
+
def kick channel_id, user_id
|
42
|
+
call_method("channels", "kick", {"channel" => channel_id, "user" => user_id})
|
43
|
+
end
|
44
|
+
|
45
|
+
def leave channel_id
|
46
|
+
call_method("channels", "leave", {"channel" => channel_id})
|
47
|
+
end
|
48
|
+
|
49
|
+
def list exclude_archived=false
|
50
|
+
# exclude_archives - Don't return archived channels (send 0/1)
|
51
|
+
call_method("channels", "list", {"exclude_archived" => bool_as_i(exclude_archived)})
|
52
|
+
end
|
53
|
+
|
54
|
+
def mark channel_id, epoch_time_stamp
|
55
|
+
# ts - Timestamp of the most recently seen message
|
56
|
+
call_method("channels", "mark", {"channel" => channel_id, "ts" => epoch_time_stamp})
|
57
|
+
end
|
58
|
+
|
59
|
+
def rename channel_id, new_name
|
60
|
+
# new_name - New name for channel
|
61
|
+
call_method("channels", "rename", {"channel" => channel_id, "name" => new_name})
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_purpose channel_id, purpose
|
65
|
+
# purpose - The new purpose for the channel
|
66
|
+
call_method("channels", "setPurpose", {"channel" => channel_id, "purpose" => purpose})
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_topic channel_id, topic
|
70
|
+
# topic - The new topic for the channel
|
71
|
+
call_method("channels", "setTopic", {"channel" => channel_id, "topic" => topic})
|
72
|
+
end
|
73
|
+
|
74
|
+
def unarchive channel_id
|
75
|
+
call_method("channels", "unarchive", {"channel"=> channel_id})
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "./base"
|
2
|
+
module SlackChatter
|
3
|
+
module Api
|
4
|
+
class Chat < SlackChatter::Api::Base
|
5
|
+
def post_message channel_id, text, opts={}
|
6
|
+
call_method("chat", "postMessage", {"channel" => channel_id, "text" => text}.merge(opts))
|
7
|
+
end
|
8
|
+
|
9
|
+
def delete timestamp, channel_id
|
10
|
+
call_method("chat", "delete", {"channel" => channel_id, "ts" => timestamp})
|
11
|
+
end
|
12
|
+
|
13
|
+
def update timestamp, channel_id, text
|
14
|
+
call_method("chat", "update", {"channel" => channel_id, "ts" => timestamp, "text" => text})
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "./base"
|
2
|
+
module SlackChatter
|
3
|
+
module Api
|
4
|
+
class Files < SlackChatter::Api::Base
|
5
|
+
def delete file_id
|
6
|
+
call_method("files", "delete", {"file" => file_id})
|
7
|
+
end
|
8
|
+
|
9
|
+
def info file_id, opts={}
|
10
|
+
call_method("files", "info", {"file" => file_id}.merge(opts))
|
11
|
+
end
|
12
|
+
|
13
|
+
def list opts={}
|
14
|
+
call_method("files", "list", opts)
|
15
|
+
end
|
16
|
+
|
17
|
+
def upload
|
18
|
+
raise "not implemented"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require_relative "./base"
|
2
|
+
module SlackChatter
|
3
|
+
module Api
|
4
|
+
class Groups < SlackChatter::Api::Base
|
5
|
+
|
6
|
+
def archive channel_id
|
7
|
+
params = {"channel" => channel_id}
|
8
|
+
call_method("groups", "archive", params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def close channel_id
|
12
|
+
params = {"channel" => channel_id}
|
13
|
+
call_method("groups", "close", params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create channel_name
|
17
|
+
# channel_name - name of channel to recreate
|
18
|
+
params = {"name" => channel_name}
|
19
|
+
call_method("groups", "create", params)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_child channel_id
|
23
|
+
call_method("groups", "createChild", {"channel" => channel_id})
|
24
|
+
end
|
25
|
+
|
26
|
+
def history channel_id, opts={}
|
27
|
+
# latest - End of time range of messages to include in results
|
28
|
+
# oldest - Start of time range of messages to include in results
|
29
|
+
# inclusive - Include messages with latest or oldest timestamp in results (send 0/1)
|
30
|
+
# count - Number of messages to return, between 1 and 1000
|
31
|
+
call_method("groups", "history", {"channel" => channel_id}.merge(opts))
|
32
|
+
end
|
33
|
+
|
34
|
+
def info channel_id
|
35
|
+
call_method("groups", "info", {"channel" => channel_id})
|
36
|
+
end
|
37
|
+
|
38
|
+
def invite channel_id, user_id
|
39
|
+
call_method("groups", "invite", {"channel" => channel_id, "user" => user_id})
|
40
|
+
end
|
41
|
+
|
42
|
+
def kick channel_id, user_id
|
43
|
+
call_method("groups", "kick", {"channel" => channel_id, "user" => user_id})
|
44
|
+
end
|
45
|
+
|
46
|
+
def leave channel_id
|
47
|
+
call_method("groups", "leave", {"channel" => channel_id})
|
48
|
+
end
|
49
|
+
|
50
|
+
def list exclude_archived=false
|
51
|
+
# exclude_archives - Don't return archived groups (send 0/1)
|
52
|
+
call_method("groups", "list", {"exclude_archived" => bool_as_i(exclude_archived)})
|
53
|
+
end
|
54
|
+
|
55
|
+
def mark channel_id, epoch_time_stamp
|
56
|
+
# ts - Timestamp of the most recently seen message
|
57
|
+
call_method("groups", "mark", {"channel" => channel_id, "ts" => epoch_time_stamp})
|
58
|
+
end
|
59
|
+
|
60
|
+
def open channel_id
|
61
|
+
call_method("groups", "open", {"channel" => channel_id})
|
62
|
+
end
|
63
|
+
|
64
|
+
def rename channel_id, new_name
|
65
|
+
# new_name - New name for channel
|
66
|
+
call_method("groups", "rename", {"channel" => channel_id, "name" => new_name})
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_purpose channel_id, purpose
|
70
|
+
# purpose - The new purpose for the channel
|
71
|
+
call_method("groups", "setPurpose", {"channel" => channel_id, "purpose" => purpose})
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_topic channel_id, topic
|
75
|
+
# topic - The new topic for the channel
|
76
|
+
call_method("groups", "setTopic", {"channel" => channel_id, "topic" => topic})
|
77
|
+
end
|
78
|
+
|
79
|
+
def unarchive channel_id
|
80
|
+
call_method("groups", "unarchive", {"channel"=> channel_id})
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative "./base"
|
2
|
+
module SlackChatter
|
3
|
+
module Api
|
4
|
+
class Im < SlackChatter::Api::Base
|
5
|
+
|
6
|
+
|
7
|
+
def close channel_id
|
8
|
+
call_method("im", "close", {"channel" => channel_id})
|
9
|
+
end
|
10
|
+
|
11
|
+
def history channel_id, opts={}
|
12
|
+
# latest - End of time range of messages to include in results
|
13
|
+
# oldest - Start of time range of messages to include in results
|
14
|
+
# inclusive - Include messages with latest or oldest timestamp in results (send 0/1)
|
15
|
+
# count - Number of messages to return, between 1 and 1000
|
16
|
+
call_method("im", "history", {"channel" => channel_id}.merge(opts))
|
17
|
+
end
|
18
|
+
|
19
|
+
def list
|
20
|
+
# exclude_archives - Don't return archived im (send 0/1)
|
21
|
+
call_method("im", "list", {})
|
22
|
+
end
|
23
|
+
|
24
|
+
def mark channel_id, epoch_time_stamp
|
25
|
+
# ts - Timestamp of the most recently seen message
|
26
|
+
call_method("im", "mark", {"channel" => channel_id, "ts" => epoch_time_stamp})
|
27
|
+
end
|
28
|
+
|
29
|
+
def open channel_id
|
30
|
+
call_method("im", "open", {"channel" => channel_id})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require_relative './api.rb'
|
2
|
+
require_relative './auth.rb'
|
3
|
+
require_relative './channels.rb'
|
4
|
+
require_relative './chat.rb'
|
5
|
+
require_relative './emoji.rb'
|
6
|
+
require_relative './files.rb'
|
7
|
+
require_relative './groups.rb'
|
8
|
+
require_relative './im.rb'
|
9
|
+
require_relative './oauth.rb'
|
10
|
+
require_relative './rtm.rb'
|
11
|
+
require_relative './search.rb'
|
12
|
+
require_relative './stars.rb'
|
13
|
+
require_relative './team.rb'
|
14
|
+
require_relative './users.rb'
|
15
|
+
|
16
|
+
module SlackChatter
|
17
|
+
module Api
|
18
|
+
module Namespaces
|
19
|
+
extend ActiveSupport::Concern
|
20
|
+
|
21
|
+
included do
|
22
|
+
def api
|
23
|
+
@api ||= SlackChatter::Api::Api.new(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def auth
|
27
|
+
@auth ||= SlackChatter::Api::Auth.new(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def channels
|
31
|
+
@channels ||= SlackChatter::Api::Channels.new(self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def chat
|
35
|
+
@chat ||= SlackChatter::Api::Chat.new(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def emoji
|
39
|
+
@emoji ||= SlackChatter::Api::Emoji.new(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
def files
|
43
|
+
@files ||= SlackChatter::Api::Files.new(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def groups
|
47
|
+
@groups ||= SlackChatter::Api::Groups.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def im
|
51
|
+
@im ||= SlackChatter::Api::Im.new(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
def oauth
|
55
|
+
@oath ||= SlackChatter::Api::Oauth.new(self)
|
56
|
+
end
|
57
|
+
|
58
|
+
def rtm
|
59
|
+
@rtm ||= SlackChatter::Api::Rtm.new(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
def search
|
63
|
+
@search ||= SlackChatter::Api::Search.new(self)
|
64
|
+
end
|
65
|
+
|
66
|
+
def stars
|
67
|
+
@stars ||= SlackChatter::Api::Stars.new(self)
|
68
|
+
end
|
69
|
+
|
70
|
+
def team
|
71
|
+
@team ||= SlackChatter::Api::Team.new(self)
|
72
|
+
end
|
73
|
+
|
74
|
+
def users
|
75
|
+
@users ||= SlackChatter::Api::Users.new(self)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "./base"
|
2
|
+
module SlackChatter
|
3
|
+
module Api
|
4
|
+
class Oauth < SlackChatter::Api::Base
|
5
|
+
def access client_id, client_secret, code, opts={}
|
6
|
+
opts.merge!({
|
7
|
+
"client_id" => client_id,
|
8
|
+
"client_secret" => client_secret,
|
9
|
+
"code" => code})
|
10
|
+
call_method("oauth", "access", opts)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative "./base"
|
2
|
+
module SlackChatter
|
3
|
+
module Api
|
4
|
+
class Search < SlackChatter::Api::Base
|
5
|
+
def all query, opts={}
|
6
|
+
opts = {"query" => query}.reverse_merge(opts)
|
7
|
+
call_method("search", "all", opts)
|
8
|
+
end
|
9
|
+
|
10
|
+
def files query, opts={}
|
11
|
+
opts = {"query" => query}.reverse_merge(opts)
|
12
|
+
call_method("search", "files", opts)
|
13
|
+
end
|
14
|
+
|
15
|
+
def messages query, opts={}
|
16
|
+
opts = {"query" => query}.reverse_merge(opts)
|
17
|
+
call_method("search", "messages", opts)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|