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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17f671256581c72171b3a58c97fc77da2da06320
4
- data.tar.gz: 0183ff7477014ba33ed88078c0f222af1a12a52c
3
+ metadata.gz: 5b2a45e6db655ab14f14b63df3c0c62a2a1921b2
4
+ data.tar.gz: 51da96868d68f148d4f618585439ef39b176f6c5
5
5
  SHA512:
6
- metadata.gz: b4504c86920010d1e1f1d94c53ad7aad13df93d66d64db291b3bef15562e013a9283dd1610fc1754fb970d12c034869249a9ac4a5c2ef98ff237d9808c10966c
7
- data.tar.gz: f530c30d2241548e823075f287ab60389c982738db526f0a8c05e95a6c4134b73ee3a301b8fb37727851645d2f43686781e60a8a3004f20d8cdda763b2f18d77
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
  ```
@@ -29,7 +29,7 @@ module SlackRTMReceiver
29
29
 
30
30
  # Create a new handler instance
31
31
  # @param type [String] event type
32
- def initialize(type = 'message', &block)
32
+ def initialize(type = :message, &block)
33
33
  @type = type
34
34
  @block = block if block_given?
35
35
  end
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  module SlackRTMReceiver
2
2
 
3
- Version = '0.0.2'
3
+ Version = '0.1.0'
4
4
 
5
5
  end
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.2
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-02-04 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine