slack-ruby-client 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +19 -17
- data/.travis.yml +1 -0
- data/CHANGELOG.md +8 -0
- data/README.md +24 -4
- data/bin/commands/chat.rb +10 -9
- data/bin/commands/files.rb +19 -1
- data/examples/hi_real_time/hi.rb +2 -0
- data/lib/slack-ruby-client.rb +4 -2
- data/lib/slack/config.rb +4 -0
- data/lib/slack/logger.rb +13 -0
- data/lib/slack/messages/message.rb +6 -0
- data/lib/slack/real_time/api/schema/event.json +1 -0
- data/lib/slack/real_time/api/templates/event_handler.erb +4 -18
- data/lib/slack/real_time/client.rb +29 -5
- data/lib/slack/real_time/concurrency/celluloid.rb +6 -0
- data/lib/slack/real_time/concurrency/eventmachine.rb +22 -1
- data/lib/slack/real_time/config.rb +5 -1
- data/lib/slack/real_time/socket.rb +5 -0
- data/lib/slack/real_time/stores.rb +10 -0
- data/lib/slack/real_time/stores/base.rb +34 -0
- data/lib/slack/real_time/stores/starter.rb +361 -0
- data/lib/slack/real_time/stores/store.rb +479 -0
- data/lib/slack/version.rb +1 -1
- data/lib/slack/web/api/endpoints/api.rb +1 -1
- data/lib/slack/web/api/endpoints/auth.rb +1 -1
- data/lib/slack/web/api/endpoints/channels.rb +14 -14
- data/lib/slack/web/api/endpoints/chat.rb +15 -13
- data/lib/slack/web/api/endpoints/dnd.rb +5 -5
- data/lib/slack/web/api/endpoints/emoji.rb +1 -1
- data/lib/slack/web/api/endpoints/files.rb +30 -6
- data/lib/slack/web/api/endpoints/groups.rb +16 -16
- data/lib/slack/web/api/endpoints/im.rb +5 -5
- data/lib/slack/web/api/endpoints/mpim.rb +5 -5
- data/lib/slack/web/api/endpoints/oauth.rb +1 -1
- data/lib/slack/web/api/endpoints/pins.rb +3 -3
- data/lib/slack/web/api/endpoints/reactions.rb +4 -4
- data/lib/slack/web/api/endpoints/rtm.rb +1 -1
- data/lib/slack/web/api/endpoints/search.rb +3 -3
- data/lib/slack/web/api/endpoints/stars.rb +3 -3
- data/lib/slack/web/api/endpoints/team.rb +3 -3
- data/lib/slack/web/api/endpoints/usergroups.rb +6 -6
- data/lib/slack/web/api/endpoints/users.rb +5 -5
- data/lib/slack/web/api/patches/chat.1.text-attachments-required.patch +1 -1
- data/lib/slack/web/api/templates/method.erb +1 -1
- data/lib/slack/web/client.rb +1 -0
- data/lib/tasks/real_time.rake +27 -21
- data/slack-ruby-client.gemspec +1 -0
- data/spec/integration/integration_spec.rb +13 -1
- data/spec/slack/real_time/client_spec.rb +40 -5
- data/spec/slack/real_time/concurrency/celluloid_spec.rb +2 -1
- data/spec/slack/real_time/concurrency/eventmachine_spec.rb +3 -2
- data/spec/slack/real_time/event_handlers/event_handlers_spec.rb +15 -0
- data/spec/slack/real_time/event_handlers/team_spec.rb +54 -52
- data/spec/slack/web/api/endpoints/files_spec.rb +10 -0
- data/spec/slack/web/client_spec.rb +1 -1
- data/spec/support/real_time/connected_client.rb +3 -3
- metadata +23 -71
- data/lib/slack/real_time/api/templates/event_handlers.erb +0 -5
- data/lib/slack/real_time/event_handlers.rb +0 -66
- data/lib/slack/real_time/event_handlers/accounts_changed.rb +0 -18
- data/lib/slack/real_time/event_handlers/bot_added.rb +0 -16
- data/lib/slack/real_time/event_handlers/bot_changed.rb +0 -17
- data/lib/slack/real_time/event_handlers/channel_archive.rb +0 -17
- data/lib/slack/real_time/event_handlers/channel_created.rb +0 -17
- data/lib/slack/real_time/event_handlers/channel_deleted.rb +0 -16
- data/lib/slack/real_time/event_handlers/channel_history_changed.rb +0 -18
- data/lib/slack/real_time/event_handlers/channel_joined.rb +0 -22
- data/lib/slack/real_time/event_handlers/channel_left.rb +0 -17
- data/lib/slack/real_time/event_handlers/channel_marked.rb +0 -18
- data/lib/slack/real_time/event_handlers/channel_rename.rb +0 -17
- data/lib/slack/real_time/event_handlers/channel_unarchive.rb +0 -17
- data/lib/slack/real_time/event_handlers/commands_changed.rb +0 -18
- data/lib/slack/real_time/event_handlers/dnd_updated.rb +0 -18
- data/lib/slack/real_time/event_handlers/dnd_updated_user.rb +0 -18
- data/lib/slack/real_time/event_handlers/email_domain_changed.rb +0 -16
- data/lib/slack/real_time/event_handlers/emoji_changed.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_change.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_comment_added.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_comment_deleted.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_comment_edited.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_created.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_deleted.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_private.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_public.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_shared.rb +0 -18
- data/lib/slack/real_time/event_handlers/file_unshared.rb +0 -18
- data/lib/slack/real_time/event_handlers/group_archive.rb +0 -17
- data/lib/slack/real_time/event_handlers/group_close.rb +0 -16
- data/lib/slack/real_time/event_handlers/group_history_changed.rb +0 -18
- data/lib/slack/real_time/event_handlers/group_joined.rb +0 -16
- data/lib/slack/real_time/event_handlers/group_left.rb +0 -17
- data/lib/slack/real_time/event_handlers/group_marked.rb +0 -18
- data/lib/slack/real_time/event_handlers/group_open.rb +0 -16
- data/lib/slack/real_time/event_handlers/group_rename.rb +0 -17
- data/lib/slack/real_time/event_handlers/group_unarchive.rb +0 -17
- data/lib/slack/real_time/event_handlers/im_close.rb +0 -16
- data/lib/slack/real_time/event_handlers/im_created.rb +0 -16
- data/lib/slack/real_time/event_handlers/im_history_changed.rb +0 -18
- data/lib/slack/real_time/event_handlers/im_marked.rb +0 -18
- data/lib/slack/real_time/event_handlers/im_open.rb +0 -16
- data/lib/slack/real_time/event_handlers/manual_presence_change.rb +0 -16
- data/lib/slack/real_time/event_handlers/pin_added.rb +0 -18
- data/lib/slack/real_time/event_handlers/pin_removed.rb +0 -18
- data/lib/slack/real_time/event_handlers/pref_change.rb +0 -16
- data/lib/slack/real_time/event_handlers/presence_change.rb +0 -17
- data/lib/slack/real_time/event_handlers/reaction_added.rb +0 -18
- data/lib/slack/real_time/event_handlers/reaction_removed.rb +0 -18
- data/lib/slack/real_time/event_handlers/reconnect_url.rb +0 -18
- data/lib/slack/real_time/event_handlers/star_added.rb +0 -18
- data/lib/slack/real_time/event_handlers/star_removed.rb +0 -18
- data/lib/slack/real_time/event_handlers/subteam_created.rb +0 -18
- data/lib/slack/real_time/event_handlers/subteam_self_added.rb +0 -18
- data/lib/slack/real_time/event_handlers/subteam_self_removed.rb +0 -18
- data/lib/slack/real_time/event_handlers/subteam_updated.rb +0 -18
- data/lib/slack/real_time/event_handlers/team_domain_change.rb +0 -17
- data/lib/slack/real_time/event_handlers/team_join.rb +0 -16
- data/lib/slack/real_time/event_handlers/team_migration_started.rb +0 -18
- data/lib/slack/real_time/event_handlers/team_plan_change.rb +0 -16
- data/lib/slack/real_time/event_handlers/team_pref_change.rb +0 -16
- data/lib/slack/real_time/event_handlers/team_profile_change.rb +0 -18
- data/lib/slack/real_time/event_handlers/team_profile_delete.rb +0 -18
- data/lib/slack/real_time/event_handlers/team_profile_reorder.rb +0 -18
- data/lib/slack/real_time/event_handlers/team_rename.rb +0 -16
- data/lib/slack/real_time/event_handlers/user_change.rb +0 -16
- data/lib/slack/real_time/event_handlers/user_typing.rb +0 -18
- data/lib/slack/real_time/store.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0aaadcdcd3f329bb20548b8041a631bb8a28519
|
4
|
+
data.tar.gz: 27a9e84d26d1934ee603972453f370102554cdce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a26e4b6f75a481faa9ff2c2b1d45a0f6922aca6784fa88f0f5772a8ad24df56676cc694e595a7fbdeb6a21fdfcb7a74ed0d9c5b5a54cb76b6b5a8747fcf8490f
|
7
|
+
data.tar.gz: 70c7e4981a819f91e425a4ba19a1769aad0f5260b0b15a8a2b55085eea824bee75c50e18845e89e91265cbdc4b72e91aa34bb2592629a2b7047639ba988d6dbc
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-02-
|
3
|
+
# on 2016-02-29 14:50:42 -0500 using RuboCop version 0.35.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -21,26 +21,34 @@ Lint/UnusedBlockArgument:
|
|
21
21
|
Exclude:
|
22
22
|
- 'lib/slack/messages/formatting.rb'
|
23
23
|
|
24
|
-
# Offense count:
|
24
|
+
# Offense count: 14
|
25
25
|
Metrics/AbcSize:
|
26
|
-
Max:
|
26
|
+
Max: 44
|
27
27
|
|
28
|
-
# Offense count:
|
28
|
+
# Offense count: 2
|
29
29
|
# Configuration parameters: CountComments.
|
30
30
|
Metrics/ClassLength:
|
31
|
-
Max:
|
31
|
+
Max: 159
|
32
32
|
|
33
|
-
# Offense count:
|
33
|
+
# Offense count: 1
|
34
|
+
Metrics/CyclomaticComplexity:
|
35
|
+
Max: 9
|
36
|
+
|
37
|
+
# Offense count: 542
|
34
38
|
# Configuration parameters: AllowURI, URISchemes.
|
35
39
|
Metrics/LineLength:
|
36
40
|
Max: 288
|
37
41
|
|
38
|
-
# Offense count:
|
42
|
+
# Offense count: 8
|
39
43
|
# Configuration parameters: CountComments.
|
40
44
|
Metrics/MethodLength:
|
41
|
-
Max:
|
45
|
+
Max: 32
|
42
46
|
|
43
|
-
# Offense count:
|
47
|
+
# Offense count: 1
|
48
|
+
Metrics/PerceivedComplexity:
|
49
|
+
Max: 11
|
50
|
+
|
51
|
+
# Offense count: 52
|
44
52
|
# Configuration parameters: Exclude.
|
45
53
|
Style/Documentation:
|
46
54
|
Enabled: false
|
@@ -51,18 +59,12 @@ Style/FileName:
|
|
51
59
|
Exclude:
|
52
60
|
- 'lib/slack-ruby-client.rb'
|
53
61
|
|
54
|
-
# Offense count:
|
62
|
+
# Offense count: 92
|
55
63
|
# Configuration parameters: AllowedVariables.
|
56
64
|
Style/GlobalVars:
|
57
65
|
Enabled: false
|
58
66
|
|
59
|
-
# Offense count:
|
60
|
-
# Configuration parameters: MinBodyLength.
|
61
|
-
Style/GuardClause:
|
62
|
-
Exclude:
|
63
|
-
- 'lib/slack/real_time/store.rb'
|
64
|
-
|
65
|
-
# Offense count: 15
|
67
|
+
# Offense count: 17
|
66
68
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
67
69
|
Style/MethodName:
|
68
70
|
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### 0.7.0 (3/6/2016)
|
2
|
+
|
3
|
+
* [#68](https://github.com/dblock/slack-ruby-client/issues/68): The `Slack::RealTime::Config#store_class` is now globally configurable - [@dblock](https://github.com/dblock).
|
4
|
+
* [#67](https://github.com/dblock/slack-ruby-client/pull/67): Make `logger` configurable and log HTTP requests and responses as well as RealTime events and socket data - [@mikz](https://github.com/mikz), [@dblock](https://github.com/dblock).
|
5
|
+
* Added `Slack::RealTime::Stores::Store` and `Slack::RealTime::Stores::Starter` - [@dblock](https://github.com/dblock).
|
6
|
+
* Added `files_revokePublicURL` and `files_sharedPublicURL` to Web API - [@dblock](https://github.com/dblock).
|
7
|
+
* [#60](https://github.com/dblock/slack-ruby-client/issues/60): Exceptions in event handlers and commands are no longer fatal - [@dblock](https://github.com/dblock).
|
8
|
+
|
1
9
|
### 0.6.0 (2/4/2016)
|
2
10
|
|
3
11
|
* [#54](https://github.com/dblock/slack-ruby-client/issues/54): RealTime client maintains a local store of team data for `client.self`, `team`, `users`, `channels`, `groups`, `ims` and `bots` data - [@dblock](https://github.com/dblock).
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ A Ruby client for the Slack [Web](https://api.slack.com/web) and [RealTime Messa
|
|
18
18
|
|
19
19
|
## Stable Release
|
20
20
|
|
21
|
-
You're reading the documentation for the **stable** release of slack-ruby-client, 0.
|
21
|
+
You're reading the documentation for the **stable** release of slack-ruby-client, 0.7.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
|
22
22
|
|
23
23
|
## Installation
|
24
24
|
|
@@ -55,6 +55,15 @@ end
|
|
55
55
|
|
56
56
|
This sets a global default token. You can also pass a token into the initializer of both `Slack::Web::Client` and `Slack::RealTime::Client` or configure those separately via `Slack::Web::Config.configure` and `Slack::RealTime::Config.configure`. The instance token will be used over the client type token over the global default.
|
57
57
|
|
58
|
+
### Global Settings
|
59
|
+
|
60
|
+
The following global settings are supported via `Slack.configure`.
|
61
|
+
|
62
|
+
setting | description
|
63
|
+
-------------|-------------------------------------------------------------------------------------------------
|
64
|
+
token | Slack API token.
|
65
|
+
logger | An optional logger, defaults to `::Logger.new(STDOUT)` at `Logger::WARN` level.
|
66
|
+
|
58
67
|
### Web Client
|
59
68
|
|
60
69
|
The Slack Web API allows you to build applications that interact with Slack.
|
@@ -215,7 +224,17 @@ bots | Details of the integrations set up on this team.
|
|
215
224
|
|
216
225
|
It also tracks changes, such as users being renamed, added or deleted, therefore `client.users` is always up-to-date.
|
217
226
|
|
218
|
-
Tracking with a local store can be disabled with `Slack::RealTime::Client.new(store_class: nil)
|
227
|
+
Tracking with a local store can be disabled with `Slack::RealTime::Client.new(store_class: nil)`. Other stores are also available.
|
228
|
+
|
229
|
+
#### Slack::RealTime::Stores::Store
|
230
|
+
|
231
|
+
The default store that tracks all changes.
|
232
|
+
|
233
|
+
#### Slack::RealTime::Stores::Starter
|
234
|
+
|
235
|
+
A smaller store that only stores and tracks information about the bot user, but not channels, users, groups, ims or bots.
|
236
|
+
|
237
|
+
### Configuring Slack::RealTime::Client
|
219
238
|
|
220
239
|
You can configure the RealTime client either globally or via the initializer.
|
221
240
|
|
@@ -236,10 +255,11 @@ setting | description
|
|
236
255
|
token | Slack API token.
|
237
256
|
websocket_ping | The number of seconds that indicates how often the WebSocket should send ping frames, default is 30.
|
238
257
|
websocket_proxy | Connect via proxy, include `:origin` and `:headers`.
|
239
|
-
store_class | Local store class name, default is an in-memory `Slack::RealTime::Store`.
|
258
|
+
store_class | Local store class name, default is an in-memory `Slack::RealTime::Stores::Store`.
|
240
259
|
start_options | Options to pass into `rtm.start`, default is `{}`.
|
260
|
+
logger | Optional `Logger` instance that logs RealTime requests and socket data.
|
241
261
|
|
242
|
-
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start), configure Web client options via `Slack::Web::Client.configure` as described above.
|
262
|
+
Note that the RealTime client uses a Web client to obtain the WebSocket URL via [rtm.start](https://api.slack.com/methods/rtm.start). While `token` and `logger` options are passed down from the RealTime client, you may also configure Web client options via `Slack::Web::Client.configure` as described above.
|
243
263
|
|
244
264
|
See a fully working example in [examples/hi_real_time](examples/hi_real_time/hi.rb).
|
245
265
|
|
data/bin/commands/chat.rb
CHANGED
@@ -17,29 +17,30 @@ command 'chat' do |g|
|
|
17
17
|
g.command 'postMessage' do |c|
|
18
18
|
c.flag 'channel', desc: 'Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name. See below for more details.'
|
19
19
|
c.flag 'text', desc: 'Text of the message to send. See below for an explanation of formatting.'
|
20
|
-
c.flag '
|
21
|
-
c.flag 'as_user', desc: 'Pass true to post the message as the authed user, instead of as a bot.'
|
22
|
-
c.flag 'parse', desc: 'Change how messages are treated. See below.'
|
20
|
+
c.flag 'parse', desc: 'Change how messages are treated. Defaults to none. See below.'
|
23
21
|
c.flag 'link_names', desc: 'Find and link channel names and usernames.'
|
24
22
|
c.flag 'attachments', desc: 'Structured message attachments.'
|
25
23
|
c.flag 'unfurl_links', desc: 'Pass true to enable unfurling of primarily text-based content.'
|
26
24
|
c.flag 'unfurl_media', desc: 'Pass false to disable unfurling of media content.'
|
27
|
-
c.flag '
|
28
|
-
c.flag '
|
25
|
+
c.flag 'username', desc: "Set your bot's user name. Must be used in conjunction with as_user set to false, otherwise ignored. See authorship below."
|
26
|
+
c.flag 'as_user', desc: 'Pass true to post the message as the authed user, instead of as a bot. Defaults to false. See authorship below.'
|
27
|
+
c.flag 'icon_url', desc: 'URL to an image to use as the icon for this message. Must be used in conjunction with as_user set to false, otherwise ignored. See authorship below.'
|
28
|
+
c.flag 'icon_emoji', desc: 'emoji to use as the icon for this message. Overrides icon_url. Must be used in conjunction with as_user set to false, otherwise ignored. See authorship below.'
|
29
29
|
c.action do |_global_options, options, _args|
|
30
30
|
puts JSON.dump($client.chat_postMessage(options))
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
g.desc 'This method updates a message in a channel.'
|
35
|
-
g.long_desc %( This method updates a message in a channel. )
|
34
|
+
g.desc 'This method updates a message in a channel. Though related to chat.postMessage, some parameters of chat.update are handled differently.'
|
35
|
+
g.long_desc %( This method updates a message in a channel. Though related to chat.postMessage, some parameters of chat.update are handled differently. )
|
36
36
|
g.command 'update' do |c|
|
37
37
|
c.flag 'ts', desc: 'Timestamp of the message to be updated.'
|
38
38
|
c.flag 'channel', desc: 'Channel containing the message to be updated.'
|
39
39
|
c.flag 'text', desc: 'New text for the message, using the default formatting rules.'
|
40
40
|
c.flag 'attachments', desc: 'Structured message attachments.'
|
41
|
-
c.flag 'parse', desc: 'Change how messages are treated. See below.'
|
42
|
-
c.flag 'link_names', desc: 'Find and link channel names and usernames.'
|
41
|
+
c.flag 'parse', desc: 'Change how messages are treated. Defaults to client, unlike chat.postMessage. See below.'
|
42
|
+
c.flag 'link_names', desc: 'Find and link channel names and usernames. Defaults to none. This parameter should be used in conjunction with parse. To set link_names to 1, specify a parse mode of full.'
|
43
|
+
c.flag 'as_user', desc: 'Pass true to update the message as the authed user. Bot users in this context are considered authed users.'
|
43
44
|
c.action do |_global_options, options, _args|
|
44
45
|
puts JSON.dump($client.chat_update(options))
|
45
46
|
end
|
data/bin/commands/files.rb
CHANGED
@@ -25,7 +25,7 @@ command 'files' do |g|
|
|
25
25
|
g.desc 'This method returns information about a file in your team.'
|
26
26
|
g.long_desc %( This method returns information about a file in your team. )
|
27
27
|
g.command 'info' do |c|
|
28
|
-
c.flag 'file', desc: '
|
28
|
+
c.flag 'file', desc: 'Specify a file by providing its ID.'
|
29
29
|
c.action do |_global_options, options, _args|
|
30
30
|
puts JSON.dump($client.files_info(options))
|
31
31
|
end
|
@@ -56,6 +56,24 @@ You can pass multiple values in the types argument, like types=posts,snippets.Th
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
g.desc 'This method disables public/external sharing for a file.'
|
60
|
+
g.long_desc %( This method disables public/external sharing for a file. )
|
61
|
+
g.command 'revokePublicURL' do |c|
|
62
|
+
c.flag 'file', desc: 'File to revoke.'
|
63
|
+
c.action do |_global_options, options, _args|
|
64
|
+
puts JSON.dump($client.files_revokePublicURL(options))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
g.desc 'This method enables public/external sharing for a file.'
|
69
|
+
g.long_desc %( This method enables public/external sharing for a file. )
|
70
|
+
g.command 'sharedPublicURL' do |c|
|
71
|
+
c.flag 'file', desc: 'File to share.'
|
72
|
+
c.action do |_global_options, options, _args|
|
73
|
+
puts JSON.dump($client.files_sharedPublicURL(options))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
59
77
|
g.desc 'This method allows you to create or upload an existing file.'
|
60
78
|
g.long_desc %( This method allows you to create or upload an existing file. )
|
61
79
|
g.command 'upload' do |c|
|
data/examples/hi_real_time/hi.rb
CHANGED
data/lib/slack-ruby-client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'slack/version'
|
2
|
+
require 'slack/logger'
|
2
3
|
require 'slack/config'
|
3
4
|
|
4
5
|
# Messages
|
@@ -26,6 +27,8 @@ require 'slack/web/api/endpoints'
|
|
26
27
|
require 'slack/web/client'
|
27
28
|
|
28
29
|
# RealTime API
|
30
|
+
require 'active_support'
|
31
|
+
require 'active_support/core_ext'
|
29
32
|
require 'slack/real_time/concurrency'
|
30
33
|
require 'slack/real_time/socket'
|
31
34
|
require 'slack/real_time/api/message_id'
|
@@ -33,7 +36,6 @@ require 'slack/real_time/api/ping'
|
|
33
36
|
require 'slack/real_time/api/message'
|
34
37
|
require 'slack/real_time/api/typing'
|
35
38
|
require 'slack/real_time/models'
|
39
|
+
require 'slack/real_time/stores'
|
36
40
|
require 'slack/real_time/config'
|
37
41
|
require 'slack/real_time/client'
|
38
|
-
require 'slack/real_time/store'
|
39
|
-
require 'slack/real_time/event_handlers'
|
data/lib/slack/config.rb
CHANGED
data/lib/slack/logger.rb
ADDED
@@ -1,18 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# module EventHandlers
|
6
|
-
# module <%= class_name %>
|
7
|
-
# # <%= desc %>
|
8
|
-
# # @see https://api.slack.com/events/<%= name %>
|
9
|
-
# # @see https://github.com/dblock/slack-api-ref/blob/master/events/<%= name %>.json
|
10
|
-
# def self.call(_client, _data)
|
11
|
-
# # TODO
|
12
|
-
# end
|
13
|
-
# end
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
|
18
|
-
# Slack::RealTime::Client.events['<%= name %>'] = Slack::RealTime::EventHandlers::<%= class_name %>
|
1
|
+
# <%= desc %>
|
2
|
+
# @see https://api.slack.com/events/<%= name %>
|
3
|
+
# @see https://github.com/dblock/slack-api-ref/blob/master/events/<%= name %>.json
|
4
|
+
# on :<%= name %> do |data|
|
@@ -20,14 +20,17 @@ module Slack
|
|
20
20
|
attr_accessor :url
|
21
21
|
attr_accessor(*Config::ATTRIBUTES)
|
22
22
|
|
23
|
+
protected :logger, :logger=
|
24
|
+
protected :store_class, :store_class=
|
25
|
+
|
23
26
|
def initialize(options = {})
|
24
27
|
@callbacks = Hash.new { |h, k| h[k] = [] }
|
25
28
|
Slack::RealTime::Config::ATTRIBUTES.each do |key|
|
26
|
-
send("#{key}=", options[key]
|
29
|
+
send("#{key}=", options.key?(key) ? options[key] : Slack::RealTime.config.send(key))
|
27
30
|
end
|
28
|
-
@store_class = options.key?(:store_class) ? options[:store_class] : Slack::RealTime::Store
|
29
31
|
@token ||= Slack.config.token
|
30
|
-
@
|
32
|
+
@logger ||= (Slack::Config.logger || Slack::Logger.default)
|
33
|
+
@web_client = Slack::Web::Client.new(token: token, logger: logger)
|
31
34
|
end
|
32
35
|
|
33
36
|
[:users, :self, :channels, :team, :teams, :groups, :ims, :bots].each do |store_method|
|
@@ -91,6 +94,7 @@ module Slack
|
|
91
94
|
socket_options = {}
|
92
95
|
socket_options[:ping] = websocket_ping if websocket_ping
|
93
96
|
socket_options[:proxy] = websocket_proxy if websocket_proxy
|
97
|
+
socket_options[:logger] = logger
|
94
98
|
socket_options
|
95
99
|
end
|
96
100
|
|
@@ -101,15 +105,18 @@ module Slack
|
|
101
105
|
yield driver if block_given?
|
102
106
|
|
103
107
|
driver.on :open do |event|
|
108
|
+
logger.debug("#{self.class}##{__method__}") { event.class.name }
|
104
109
|
open(event)
|
105
110
|
callback(event, :open)
|
106
111
|
end
|
107
112
|
|
108
113
|
driver.on :message do |event|
|
114
|
+
logger.debug("#{self.class}##{__method__}") { "#{event.class}, #{event.data}" }
|
109
115
|
dispatch(event)
|
110
116
|
end
|
111
117
|
|
112
118
|
driver.on :close do |event|
|
119
|
+
logger.debug("#{self.class}##{__method__}") { event.class.name }
|
113
120
|
callback(event, :close)
|
114
121
|
close(event)
|
115
122
|
end
|
@@ -123,6 +130,7 @@ module Slack
|
|
123
130
|
|
124
131
|
def send_json(data)
|
125
132
|
fail ClientNotStartedError unless started?
|
133
|
+
logger.debug("#{self.class}##{__method__}") { data }
|
126
134
|
@socket.send_data(data.to_json)
|
127
135
|
end
|
128
136
|
|
@@ -144,6 +152,10 @@ module Slack
|
|
144
152
|
callbacks.each do |c|
|
145
153
|
c.call(event)
|
146
154
|
end
|
155
|
+
true
|
156
|
+
rescue StandardError => e
|
157
|
+
logger.error e
|
158
|
+
false
|
147
159
|
end
|
148
160
|
|
149
161
|
def dispatch(event)
|
@@ -152,13 +164,22 @@ module Slack
|
|
152
164
|
type = data.type
|
153
165
|
return false unless type
|
154
166
|
type = type.to_s
|
167
|
+
logger.debug("#{self.class}##{__method__}") { data.to_s }
|
155
168
|
run_handlers(type, data) if @store
|
156
169
|
run_callbacks(type, data)
|
170
|
+
rescue StandardError => e
|
171
|
+
logger.error e
|
172
|
+
false
|
157
173
|
end
|
158
174
|
|
159
175
|
def run_handlers(type, data)
|
160
|
-
|
161
|
-
|
176
|
+
handlers = store.class.events[type.to_s]
|
177
|
+
handlers.each do |handler|
|
178
|
+
store.instance_exec(data, &handler)
|
179
|
+
end if handlers
|
180
|
+
rescue StandardError => e
|
181
|
+
logger.error e
|
182
|
+
false
|
162
183
|
end
|
163
184
|
|
164
185
|
def run_callbacks(type, data)
|
@@ -168,6 +189,9 @@ module Slack
|
|
168
189
|
c.call(data)
|
169
190
|
end
|
170
191
|
true
|
192
|
+
rescue StandardError => e
|
193
|
+
logger.error e
|
194
|
+
false
|
171
195
|
end
|
172
196
|
end
|
173
197
|
end
|
@@ -41,9 +41,15 @@ module Slack
|
|
41
41
|
|
42
42
|
def read
|
43
43
|
buffer = socket.readpartial(BLOCK_SIZE)
|
44
|
+
logger.debug("#{self.class}##{__method__}") { buffer }
|
44
45
|
driver.parse buffer
|
45
46
|
end
|
46
47
|
|
48
|
+
def write(data)
|
49
|
+
logger.debug("#{self.class}##{__method__}") { data }
|
50
|
+
socket.write(data)
|
51
|
+
end
|
52
|
+
|
47
53
|
def start_async
|
48
54
|
future = yield self if block_given?
|
49
55
|
|