slack-rtm-receiver 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/lib/slack-rtm-receiver/event-handler.rb +1 -1
- data/lib/slack-rtm-receiver/session.rb +11 -1
- data/lib/slack-rtm-receiver/version.rb +1 -1
- 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: 5b2a45e6db655ab14f14b63df3c0c62a2a1921b2
|
4
|
+
data.tar.gz: 51da96868d68f148d4f618585439ef39b176f6c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc23e5c7e4fd47a2dc423e8be078452f854d72f1f3580cebbbd1a2b81d4c62f484296c904aa8af693adab9830b43498baf4c62c8f8d7fa68a84ce93ec91e9be5
|
7
|
+
data.tar.gz: 3fa12806141ee97b024c3e70ec243d155868ae79de26cb3c145c0456111e3810e014a10a92087ca52985862ab85c886666b823407b06a6c331e0d5d7fb6636af
|
data/README.md
CHANGED
@@ -19,12 +19,13 @@ $ gem install slack-rtm-receiver
|
|
19
19
|
|
20
20
|
### Use
|
21
21
|
|
22
|
-
```
|
22
|
+
```ruby
|
23
23
|
require 'slack-rtm-receiver'
|
24
24
|
```
|
25
25
|
|
26
26
|
Create an object to respond to received events. You can subclass **EventHandler**.
|
27
|
-
|
27
|
+
|
28
|
+
```ruby
|
28
29
|
class MyHandler < SlackRTMReceiver::EventHandler
|
29
30
|
def process_event(event, session)
|
30
31
|
if event[:text] == 'hi'
|
@@ -39,8 +40,10 @@ class MyHandler < SlackRTMReceiver::EventHandler
|
|
39
40
|
end
|
40
41
|
SlackRTMReceiver.add_event_handler(MyHandler.new)
|
41
42
|
```
|
43
|
+
|
42
44
|
Or, you can pass a block. The following works the same as above.
|
43
|
-
|
45
|
+
|
46
|
+
```ruby
|
44
47
|
SlackRTMReceiver::EventHandler.add_type('message') do |event, session|
|
45
48
|
if event[:text] == 'hi'
|
46
49
|
res_event = {
|
@@ -54,7 +57,8 @@ end
|
|
54
57
|
```
|
55
58
|
|
56
59
|
Start the reactor to connect to Slack.
|
57
|
-
|
60
|
+
|
61
|
+
```ruby
|
58
62
|
opts = {token: 'xoxb-1234abcd5678efgh'}
|
59
63
|
SlackRTMReceiver::Reactor.run(opts)
|
60
64
|
```
|
@@ -154,9 +154,19 @@ module SlackRTMReceiver
|
|
154
154
|
|
155
155
|
def parse_rtm_start_res(json)
|
156
156
|
hash = JSON.parse(json, {symbolize_names: true})
|
157
|
+
rtmstart_handler(hash)
|
157
158
|
return {url: hash[:url], self_id: hash[:self][:id]}
|
158
159
|
end
|
159
160
|
|
161
|
+
# Handle RTM start response
|
162
|
+
def rtmstart_handler(hash)
|
163
|
+
logger.info 'Processing RTM.start response...'
|
164
|
+
handlers = SlackRTMReceiver.event_handlers
|
165
|
+
handlers.each do |handler|
|
166
|
+
handler.process_event(hash, self) if handler.type == :rtmstart
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
160
170
|
# Handle RTM hello
|
161
171
|
def hello_handler(event)
|
162
172
|
@stats[:hello_time] = Time.now
|
@@ -184,7 +194,7 @@ module SlackRTMReceiver
|
|
184
194
|
return unless event[:type]
|
185
195
|
handlers = SlackRTMReceiver.event_handlers
|
186
196
|
handlers.each do |handler|
|
187
|
-
handler.process_event(event, self) if handler.type == event[:type]
|
197
|
+
handler.process_event(event, self) if handler.type == event[:type].to_sym
|
188
198
|
end
|
189
199
|
end
|
190
200
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-rtm-receiver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken J.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|