tjplurker 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tjplurker.rb +21 -14
- metadata +5 -7
data/lib/tjplurker.rb
CHANGED
@@ -95,6 +95,9 @@ class TJPlurker
|
|
95
95
|
rescue Timeout::Error => ex
|
96
96
|
$tjpLog.warn(self.class){"Request timeout, retry."}
|
97
97
|
retry
|
98
|
+
rescue Errno::ECONNRESET => ex
|
99
|
+
$tjpLog.warn(self.class){"Connection reset, retry."}
|
100
|
+
retry
|
98
101
|
rescue => ex
|
99
102
|
$tjpLog.fatal(self.class){"Unknown error, skip."}
|
100
103
|
puts ex.class, ex.message, ex.backtrace
|
@@ -139,6 +142,9 @@ class TJPlurker
|
|
139
142
|
rescue Timeout::Error => ex
|
140
143
|
$tjpLog.warn(self.class){"Request timeout, retrying."}
|
141
144
|
retry
|
145
|
+
rescue Errno::ECONNRESET => ex
|
146
|
+
$tjpLog.warn(self.class){"Connection reset, retry."}
|
147
|
+
retry
|
142
148
|
rescue JSON::ParserError => ex
|
143
149
|
$tjpLog.error(self.class){"JSON parse error, request failed."}
|
144
150
|
rescue => ex
|
@@ -149,8 +155,8 @@ class TJPlurker
|
|
149
155
|
return json
|
150
156
|
end
|
151
157
|
|
158
|
+
# Format the json from the comet server. See TJPlurker#comet_channel
|
152
159
|
class NotificationData
|
153
|
-
|
154
160
|
# Can be +new_plurk+ or +new_response+.
|
155
161
|
attr_reader :type
|
156
162
|
attr_reader :response_count
|
@@ -200,6 +206,7 @@ class TJPlurker
|
|
200
206
|
@services = []
|
201
207
|
end
|
202
208
|
|
209
|
+
# Starting a loop and invokes services when a notification was listened.
|
203
210
|
def start
|
204
211
|
$tjpLog.info(self.class){"Start robot."}
|
205
212
|
Thread.new{
|
@@ -221,6 +228,7 @@ class TJPlurker
|
|
221
228
|
}
|
222
229
|
end
|
223
230
|
|
231
|
+
# +service+:: Can be instance TJPlurker::Service or class TJPlurker::Service or it's descendant classes.
|
224
232
|
def add_service service
|
225
233
|
if service.is_a? Service
|
226
234
|
@services << service
|
@@ -244,24 +252,28 @@ class TJPlurker
|
|
244
252
|
end
|
245
253
|
end
|
246
254
|
|
255
|
+
# Invoke when listened a new plurk.
|
247
256
|
def decide tjplurker, data
|
248
257
|
true
|
249
258
|
end
|
250
259
|
|
251
260
|
def action tjplurker, data
|
252
|
-
p data
|
253
|
-
end
|
254
|
-
|
255
|
-
def serve tjplurker, data
|
256
261
|
if @serve_proc
|
257
262
|
@serve_proc[tjplurker, data]
|
258
263
|
else
|
259
|
-
|
264
|
+
p data
|
260
265
|
end
|
261
266
|
end
|
267
|
+
|
268
|
+
def serve tjplurker, data
|
269
|
+
action(tjplurker, data) if decide(tjplurker, data)
|
270
|
+
end
|
262
271
|
end
|
263
272
|
|
264
273
|
class ThreadService < Service
|
274
|
+
# +lasting+:: How long in second will a thread lives. If one plurk just be responsed, then it will live another +lasting+ time.
|
275
|
+
#
|
276
|
+
# +refresh+:: Interval that checks if thread should terminate.
|
265
277
|
def initialize name=self.class.to_s, lasting=60, refresh=1, &proc
|
266
278
|
super name
|
267
279
|
@lasting = lasting
|
@@ -270,16 +282,12 @@ class TJPlurker
|
|
270
282
|
@mutex = Mutex.new
|
271
283
|
end
|
272
284
|
|
273
|
-
|
274
|
-
|
275
|
-
|
285
|
+
# Invoke after thread termination.
|
286
|
+
# You can use this to tell users this service just terminate.
|
287
|
+
def final tjplurker, data
|
276
288
|
|
277
|
-
def action tjplurker, data
|
278
|
-
@serve_proc[tjplurker, data]
|
279
289
|
end
|
280
290
|
|
281
|
-
def final tjplurker, data
|
282
|
-
end
|
283
291
|
def serve tjplurker, data
|
284
292
|
if data.type=='new_plurk' && decide(tjplurker, data)
|
285
293
|
@plurk_id_hash[data.plurk_id] = Thread.new(data.plurk_id){|plurk_id|
|
@@ -311,7 +319,6 @@ class TJPlurker
|
|
311
319
|
end
|
312
320
|
end
|
313
321
|
end
|
314
|
-
|
315
322
|
end
|
316
323
|
|
317
324
|
if __FILE__ == $0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tjplurker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-05-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-05-27 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: json
|
17
|
-
requirement: &
|
16
|
+
requirement: &15370380 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,7 +21,7 @@ dependencies:
|
|
22
21
|
version: 1.4.2
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *15370380
|
26
25
|
description: A safe Plurk API wrapper based on Ruby and mainly designed for easily
|
27
26
|
making plurk robot.
|
28
27
|
email: tonytonyjan.cs97@g2.nctu.edu.tw
|
@@ -31,7 +30,6 @@ extensions: []
|
|
31
30
|
extra_rdoc_files: []
|
32
31
|
files:
|
33
32
|
- lib/tjplurker.rb
|
34
|
-
has_rdoc: true
|
35
33
|
homepage: http://code.google.com/p/tjplurker
|
36
34
|
licenses: []
|
37
35
|
post_install_message:
|
@@ -52,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
50
|
version: '0'
|
53
51
|
requirements: []
|
54
52
|
rubyforge_project:
|
55
|
-
rubygems_version: 1.
|
53
|
+
rubygems_version: 1.8.4
|
56
54
|
signing_key:
|
57
55
|
specification_version: 3
|
58
56
|
summary: A safe Plurk API wrapper based on Ruby and mainly designed for easily making
|