safubot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.md +19 -0
  4. data/README.md +43 -0
  5. data/Rakefile +1 -0
  6. data/doc/Gemfile.html +119 -0
  7. data/doc/Object.html +171 -0
  8. data/doc/Rakefile.html +117 -0
  9. data/doc/Safubot.html +173 -0
  10. data/doc/Safubot/Bot.html +827 -0
  11. data/doc/Safubot/Evented.html +346 -0
  12. data/doc/Safubot/KnownUser.html +344 -0
  13. data/doc/Safubot/Log.html +254 -0
  14. data/doc/Safubot/Query.html +217 -0
  15. data/doc/Safubot/Request.html +201 -0
  16. data/doc/Safubot/Response.html +174 -0
  17. data/doc/Safubot/Test.html +244 -0
  18. data/doc/Safubot/Twitter.html +153 -0
  19. data/doc/Safubot/Twitter/Bot.html +591 -0
  20. data/doc/Safubot/Twitter/DirectMessage.html +327 -0
  21. data/doc/Safubot/Twitter/Tweet.html +522 -0
  22. data/doc/Safubot/XMPP.html +153 -0
  23. data/doc/Safubot/XMPP/Bot.html +403 -0
  24. data/doc/Safubot/XMPP/Message.html +298 -0
  25. data/doc/created.rid +14 -0
  26. data/doc/foo_rb.html +115 -0
  27. data/doc/images/add.png +0 -0
  28. data/doc/images/brick.png +0 -0
  29. data/doc/images/brick_link.png +0 -0
  30. data/doc/images/bug.png +0 -0
  31. data/doc/images/bullet_black.png +0 -0
  32. data/doc/images/bullet_toggle_minus.png +0 -0
  33. data/doc/images/bullet_toggle_plus.png +0 -0
  34. data/doc/images/date.png +0 -0
  35. data/doc/images/delete.png +0 -0
  36. data/doc/images/find.png +0 -0
  37. data/doc/images/loadingAnimation.gif +0 -0
  38. data/doc/images/macFFBgHack.png +0 -0
  39. data/doc/images/package.png +0 -0
  40. data/doc/images/page_green.png +0 -0
  41. data/doc/images/page_white_text.png +0 -0
  42. data/doc/images/page_white_width.png +0 -0
  43. data/doc/images/plugin.png +0 -0
  44. data/doc/images/ruby.png +0 -0
  45. data/doc/images/tag_blue.png +0 -0
  46. data/doc/images/tag_green.png +0 -0
  47. data/doc/images/transparent.png +0 -0
  48. data/doc/images/wrench.png +0 -0
  49. data/doc/images/wrench_orange.png +0 -0
  50. data/doc/images/zoom.png +0 -0
  51. data/doc/index.html +112 -0
  52. data/doc/js/darkfish.js +153 -0
  53. data/doc/js/jquery.js +18 -0
  54. data/doc/js/navigation.js +142 -0
  55. data/doc/js/search.js +94 -0
  56. data/doc/js/search_index.js +1 -0
  57. data/doc/js/searcher.js +228 -0
  58. data/doc/lib/safubot/bot_rb.html +115 -0
  59. data/doc/lib/safubot/evented_rb.html +115 -0
  60. data/doc/lib/safubot/known_user_rb.html +115 -0
  61. data/doc/lib/safubot/log_rb.html +115 -0
  62. data/doc/lib/safubot/safubot_rb.html +115 -0
  63. data/doc/lib/safubot/spec/bot_spec_rb.html +115 -0
  64. data/doc/lib/safubot/spec/twitter_spec_rb.html +137 -0
  65. data/doc/lib/safubot/test_helper_rb.html +115 -0
  66. data/doc/lib/safubot/twitter_rb.html +115 -0
  67. data/doc/lib/safubot/version_rb.html +115 -0
  68. data/doc/lib/safubot/xmpp_rb.html +115 -0
  69. data/doc/lib/safubot_rb.html +115 -0
  70. data/doc/rdoc.css +543 -0
  71. data/doc/table_of_contents.html +224 -0
  72. data/lib/safubot.rb +20 -0
  73. data/lib/safubot/bot.rb +177 -0
  74. data/lib/safubot/evented.rb +52 -0
  75. data/lib/safubot/known_user.rb +27 -0
  76. data/lib/safubot/log.rb +21 -0
  77. data/lib/safubot/test_helper.rb +62 -0
  78. data/lib/safubot/twitter.rb +279 -0
  79. data/lib/safubot/version.rb +3 -0
  80. data/lib/safubot/xmpp.rb +144 -0
  81. data/safubot.gemspec +32 -0
  82. data/spec/fixtures/twitter/direct_message +1 -0
  83. data/spec/fixtures/twitter/tweet +1 -0
  84. data/spec/fixtures/xmpp/message +3 -0
  85. data/spec/helper.rb +12 -0
  86. data/spec/safubot/bot_spec.rb +41 -0
  87. data/spec/safubot/evented_spec.rb +45 -0
  88. data/spec/safubot/known_user_spec.rb +22 -0
  89. data/spec/safubot/twitter_spec.rb +60 -0
  90. data/spec/safubot/xmpp_spec.rb +35 -0
  91. metadata +260 -0
data/doc/Safubot.html ADDED
@@ -0,0 +1,173 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>Module: Safubot</title>
8
+
9
+ <link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "./";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
21
+
22
+
23
+ <body id="top" class="module">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="./index.html">Home</a>
28
+ <a href="./table_of_contents.html#classes">Classes</a>
29
+ <a href="./table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="file-metadata">
47
+ <nav id="file-list-section" class="section">
48
+ <h3 class="section-header">Defined In</h3>
49
+ <ul>
50
+ <li>lib/safubot/xmpp.rb
51
+ <li>lib/safubot/evented.rb
52
+ <li>lib/safubot/bot.rb
53
+ <li>lib/safubot/known_user.rb
54
+ <li>lib/safubot/test_helper.rb
55
+ <li>lib/safubot/twitter.rb
56
+ <li>lib/safubot/version.rb
57
+ <li>lib/safubot/log.rb
58
+ </ul>
59
+ </nav>
60
+
61
+
62
+ </div>
63
+
64
+ <div id="class-metadata">
65
+
66
+
67
+
68
+
69
+ </div>
70
+
71
+ <div id="project-metadata">
72
+ <nav id="fileindex-section" class="section project-section">
73
+ <h3 class="section-header">Pages</h3>
74
+
75
+ <ul>
76
+
77
+ <li class="file"><a href="./Gemfile.html">Gemfile</a>
78
+
79
+ <li class="file"><a href="./Rakefile.html">Rakefile</a>
80
+
81
+ </ul>
82
+ </nav>
83
+
84
+ <nav id="classindex-section" class="section project-section">
85
+ <h3 class="section-header">Class and Module Index</h3>
86
+
87
+ <ul class="link-list">
88
+
89
+ <li><a href="./Safubot.html">Safubot</a>
90
+
91
+ <li><a href="./Safubot/Bot.html">Safubot::Bot</a>
92
+
93
+ <li><a href="./Safubot/Evented.html">Safubot::Evented</a>
94
+
95
+ <li><a href="./Safubot/KnownUser.html">Safubot::KnownUser</a>
96
+
97
+ <li><a href="./Safubot/Log.html">Safubot::Log</a>
98
+
99
+ <li><a href="./Safubot/Query.html">Safubot::Query</a>
100
+
101
+ <li><a href="./Safubot/Request.html">Safubot::Request</a>
102
+
103
+ <li><a href="./Safubot/Response.html">Safubot::Response</a>
104
+
105
+ <li><a href="./Safubot/Test.html">Safubot::Test</a>
106
+
107
+ <li><a href="./Safubot/Twitter.html">Safubot::Twitter</a>
108
+
109
+ <li><a href="./Safubot/Twitter/Bot.html">Safubot::Twitter::Bot</a>
110
+
111
+ <li><a href="./Safubot/Twitter/DirectMessage.html">Safubot::Twitter::DirectMessage</a>
112
+
113
+ <li><a href="./Safubot/Twitter/Tweet.html">Safubot::Twitter::Tweet</a>
114
+
115
+ <li><a href="./Safubot/XMPP.html">Safubot::XMPP</a>
116
+
117
+ <li><a href="./Safubot/XMPP/Bot.html">Safubot::XMPP::Bot</a>
118
+
119
+ <li><a href="./Safubot/XMPP/Message.html">Safubot::XMPP::Message</a>
120
+
121
+ <li><a href="./Object.html">Object</a>
122
+
123
+ </ul>
124
+ </nav>
125
+
126
+ </div>
127
+ </nav>
128
+
129
+ <div id="documentation">
130
+ <h1 class="module">module Safubot</h1>
131
+
132
+ <div id="description" class="description">
133
+
134
+ </div><!-- description -->
135
+
136
+
137
+
138
+
139
+ <section id="5Buntitled-5D" class="documentation-section">
140
+
141
+
142
+
143
+
144
+
145
+ <!-- Constants -->
146
+ <section id="constants-list" class="section">
147
+ <h3 class="section-header">Constants</h3>
148
+ <dl>
149
+
150
+ <dt id="VERSION">VERSION
151
+
152
+ <dd class="description">
153
+
154
+
155
+ </dl>
156
+ </section>
157
+
158
+
159
+
160
+
161
+ <!-- Methods -->
162
+
163
+ </section><!-- 5Buntitled-5D -->
164
+
165
+ </div><!-- documentation -->
166
+
167
+
168
+ <footer id="validator-badges">
169
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
170
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
171
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
172
+ </footer>
173
+
@@ -0,0 +1,827 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>Class: Safubot::Bot</title>
8
+
9
+ <link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "../";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>
21
+
22
+
23
+ <body id="top" class="class">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="../index.html">Home</a>
28
+ <a href="../table_of_contents.html#classes">Classes</a>
29
+ <a href="../table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="file-metadata">
47
+ <nav id="file-list-section" class="section">
48
+ <h3 class="section-header">Defined In</h3>
49
+ <ul>
50
+ <li>lib/safubot/bot.rb
51
+ <li>lib/safubot/test_helper.rb
52
+ </ul>
53
+ </nav>
54
+
55
+
56
+ </div>
57
+
58
+ <div id="class-metadata">
59
+
60
+ <nav id="parent-class-section" class="section">
61
+ <h3 class="section-header">Parent</h3>
62
+
63
+ <p class="link"><a href="../Object.html">Object</a>
64
+
65
+ </nav>
66
+
67
+ <!-- Included Modules -->
68
+ <nav id="includes-section" class="section">
69
+ <h3 class="section-header">Included Modules</h3>
70
+
71
+ <ul class="link-list">
72
+
73
+
74
+ <li><a class="include" href="Evented.html">Safubot::Evented</a>
75
+
76
+
77
+ </ul>
78
+ </nav>
79
+
80
+ <!-- Method Quickref -->
81
+ <nav id="method-list-section" class="section">
82
+ <h3 class="section-header">Methods</h3>
83
+
84
+ <ul class="link-list">
85
+
86
+ <li><a href="#method-c-new">::new</a>
87
+
88
+ <li><a href="#method-i-answer">#answer</a>
89
+
90
+ <li><a href="#method-i-concurrently">#concurrently</a>
91
+
92
+ <li><a href="#method-i-cycle">#cycle</a>
93
+
94
+ <li><a href="#method-i-dispatch">#dispatch</a>
95
+
96
+ <li><a href="#method-i-enable_twitter">#enable_twitter</a>
97
+
98
+ <li><a href="#method-i-enable_xmpp">#enable_xmpp</a>
99
+
100
+ <li><a href="#method-i-process">#process</a>
101
+
102
+ <li><a href="#method-i-process_request">#process_request</a>
103
+
104
+ <li><a href="#method-i-pull">#pull</a>
105
+
106
+ <li><a href="#method-i-push">#push</a>
107
+
108
+ <li><a href="#method-i-request_error">#request_error</a>
109
+
110
+ <li><a href="#method-i-respond">#respond</a>
111
+
112
+ <li><a href="#method-i-respond_now">#respond_now</a>
113
+
114
+ <li><a href="#method-i-run">#run</a>
115
+
116
+ <li><a href="#method-i-stop">#stop</a>
117
+
118
+ </ul>
119
+ </nav>
120
+
121
+ </div>
122
+
123
+ <div id="project-metadata">
124
+ <nav id="fileindex-section" class="section project-section">
125
+ <h3 class="section-header">Pages</h3>
126
+
127
+ <ul>
128
+
129
+ <li class="file"><a href="../Gemfile.html">Gemfile</a>
130
+
131
+ <li class="file"><a href="../Rakefile.html">Rakefile</a>
132
+
133
+ </ul>
134
+ </nav>
135
+
136
+ <nav id="classindex-section" class="section project-section">
137
+ <h3 class="section-header">Class and Module Index</h3>
138
+
139
+ <ul class="link-list">
140
+
141
+ <li><a href="../Safubot.html">Safubot</a>
142
+
143
+ <li><a href="../Safubot/Bot.html">Safubot::Bot</a>
144
+
145
+ <li><a href="../Safubot/Evented.html">Safubot::Evented</a>
146
+
147
+ <li><a href="../Safubot/KnownUser.html">Safubot::KnownUser</a>
148
+
149
+ <li><a href="../Safubot/Log.html">Safubot::Log</a>
150
+
151
+ <li><a href="../Safubot/Query.html">Safubot::Query</a>
152
+
153
+ <li><a href="../Safubot/Request.html">Safubot::Request</a>
154
+
155
+ <li><a href="../Safubot/Response.html">Safubot::Response</a>
156
+
157
+ <li><a href="../Safubot/Test.html">Safubot::Test</a>
158
+
159
+ <li><a href="../Safubot/Twitter.html">Safubot::Twitter</a>
160
+
161
+ <li><a href="../Safubot/Twitter/Bot.html">Safubot::Twitter::Bot</a>
162
+
163
+ <li><a href="../Safubot/Twitter/DirectMessage.html">Safubot::Twitter::DirectMessage</a>
164
+
165
+ <li><a href="../Safubot/Twitter/Tweet.html">Safubot::Twitter::Tweet</a>
166
+
167
+ <li><a href="../Safubot/XMPP.html">Safubot::XMPP</a>
168
+
169
+ <li><a href="../Safubot/XMPP/Bot.html">Safubot::XMPP::Bot</a>
170
+
171
+ <li><a href="../Safubot/XMPP/Message.html">Safubot::XMPP::Message</a>
172
+
173
+ <li><a href="../Object.html">Object</a>
174
+
175
+ </ul>
176
+ </nav>
177
+
178
+ </div>
179
+ </nav>
180
+
181
+ <div id="documentation">
182
+ <h1 class="class">class Safubot::Bot</h1>
183
+
184
+ <div id="description" class="description">
185
+
186
+ <p>Here’s where we define the main <a href="../Safubot.html">Safubot</a>
187
+ instance.</p>
188
+
189
+ </div><!-- description -->
190
+
191
+
192
+
193
+
194
+ <section id="5Buntitled-5D" class="documentation-section">
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+ <!-- Attributes -->
203
+ <section id="attribute-method-details" class="method-section section">
204
+ <h3 class="section-header">Attributes</h3>
205
+
206
+
207
+ <div id="attribute-i-opts" class="method-detail">
208
+ <div class="method-heading attribute-method-heading">
209
+ <span class="method-name">opts</span><span
210
+ class="attribute-access-type">[R]</span>
211
+ </div>
212
+
213
+ <div class="method-description">
214
+
215
+
216
+
217
+ </div>
218
+ </div>
219
+
220
+ <div id="attribute-i-twitter" class="method-detail">
221
+ <div class="method-heading attribute-method-heading">
222
+ <span class="method-name">twitter</span><span
223
+ class="attribute-access-type">[R]</span>
224
+ </div>
225
+
226
+ <div class="method-description">
227
+
228
+
229
+
230
+ </div>
231
+ </div>
232
+
233
+ <div id="attribute-i-xmpp" class="method-detail">
234
+ <div class="method-heading attribute-method-heading">
235
+ <span class="method-name">xmpp</span><span
236
+ class="attribute-access-type">[R]</span>
237
+ </div>
238
+
239
+ <div class="method-description">
240
+
241
+
242
+
243
+ </div>
244
+ </div>
245
+
246
+ </section><!-- attribute-method-details -->
247
+
248
+
249
+ <!-- Methods -->
250
+
251
+ <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
252
+ <h3 class="section-header">Public Class Methods</h3>
253
+
254
+
255
+ <div id="method-c-new" class="method-detail ">
256
+
257
+ <div class="method-heading">
258
+ <span class="method-name">new</span><span
259
+ class="method-args">(options={})</span>
260
+ <span class="method-click-advice">click to toggle source</span>
261
+ </div>
262
+
263
+
264
+ <div class="method-description">
265
+
266
+
267
+
268
+
269
+
270
+ <div class="method-source-code" id="new-source">
271
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 165</span>
272
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
273
+ <span class="ruby-identifier">defaults</span> = { <span class="ruby-value">:database</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&quot;safubot&quot;</span> }
274
+ <span class="ruby-ivar">@opts</span> = <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
275
+ <span class="ruby-constant">MongoMapper</span>.<span class="ruby-identifier">database</span> = <span class="ruby-ivar">@opts</span>[<span class="ruby-value">:database</span>]
276
+ <span class="ruby-constant">MongoMapper</span>.<span class="ruby-identifier">connection</span> = <span class="ruby-constant">Mongo</span><span class="ruby-operator">::</span><span class="ruby-constant">Connection</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">'localhost'</span>, <span class="ruby-value">27017</span>, <span class="ruby-value">:pool_size</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">5</span>)
277
+ <span class="ruby-ivar">@handlers</span> = {}
278
+ <span class="ruby-keyword">end</span></pre>
279
+ </div><!-- new-source -->
280
+
281
+ </div>
282
+
283
+
284
+
285
+
286
+ </div><!-- new-method -->
287
+
288
+
289
+ </section><!-- public-class-method-details -->
290
+
291
+ <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
292
+ <h3 class="section-header">Public Instance Methods</h3>
293
+
294
+
295
+ <div id="method-i-answer" class="method-detail ">
296
+
297
+ <div class="method-heading">
298
+ <span class="method-name">answer</span><span
299
+ class="method-args">(text, user=nil)</span>
300
+ <span class="method-click-advice">click to toggle source</span>
301
+ </div>
302
+
303
+
304
+ <div class="method-description">
305
+
306
+
307
+
308
+
309
+
310
+ <div class="method-source-code" id="answer-source">
311
+ <pre><span class="ruby-comment"># File lib/safubot/test_helper.rb, line 46</span>
312
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">answer</span>(<span class="ruby-identifier">text</span>, <span class="ruby-identifier">user</span>=<span class="ruby-keyword">nil</span>)
313
+ <span class="ruby-comment"># A generic &quot;respond immediately&quot; interface.</span>
314
+ <span class="ruby-identifier">user</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">KnownUser</span>.<span class="ruby-identifier">by_name</span>(<span class="ruby-string">'testing'</span>)
315
+ <span class="ruby-identifier">query</span> = <span class="ruby-constant">Query</span>.<span class="ruby-identifier">create</span>(<span class="ruby-value">:user</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">user</span>, <span class="ruby-value">:text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">text</span>)
316
+ <span class="ruby-identifier">req</span> = <span class="ruby-identifier">query</span>.<span class="ruby-identifier">make_request</span>
317
+ <span class="ruby-identifier">process_request</span>(<span class="ruby-identifier">req</span>)
318
+ <span class="ruby-identifier">req</span>.<span class="ruby-identifier">responses</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">text</span>
319
+ <span class="ruby-keyword">end</span></pre>
320
+ </div><!-- answer-source -->
321
+
322
+ </div>
323
+
324
+
325
+
326
+
327
+ </div><!-- answer-method -->
328
+
329
+
330
+ <div id="method-i-concurrently" class="method-detail ">
331
+
332
+ <div class="method-heading">
333
+ <span class="method-name">concurrently</span><span
334
+ class="method-args">(req, &blk)</span>
335
+ <span class="method-click-advice">click to toggle source</span>
336
+ </div>
337
+
338
+
339
+ <div class="method-description">
340
+
341
+ <p>Wraps EM::defer with error handling and response pushing for the given
342
+ request. @param req The <a href="Request.html">Request</a> being processed.
343
+ @param blk The operation to be performed in a separate thread.</p>
344
+
345
+
346
+
347
+ <div class="method-source-code" id="concurrently-source">
348
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 115</span>
349
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">concurrently</span>(<span class="ruby-identifier">req</span>, &amp;<span class="ruby-identifier">blk</span>)
350
+ <span class="ruby-constant">EventMachine</span><span class="ruby-operator">::</span><span class="ruby-identifier">defer</span> <span class="ruby-keyword">do</span>
351
+ <span class="ruby-keyword">begin</span>
352
+ <span class="ruby-identifier">blk</span>.<span class="ruby-identifier">call</span>
353
+ <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
354
+ <span class="ruby-identifier">request_error</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">e</span>)
355
+ <span class="ruby-keyword">end</span>
356
+
357
+ <span class="ruby-identifier">push</span>
358
+ <span class="ruby-keyword">end</span>
359
+ <span class="ruby-keyword">end</span></pre>
360
+ </div><!-- concurrently-source -->
361
+
362
+ </div>
363
+
364
+
365
+
366
+
367
+ </div><!-- concurrently-method -->
368
+
369
+
370
+ <div id="method-i-cycle" class="method-detail ">
371
+
372
+ <div class="method-heading">
373
+ <span class="method-name">cycle</span><span
374
+ class="method-args">()</span>
375
+ <span class="method-click-advice">click to toggle source</span>
376
+ </div>
377
+
378
+
379
+ <div class="method-description">
380
+
381
+
382
+
383
+
384
+
385
+ <div class="method-source-code" id="cycle-source">
386
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 108</span>
387
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">cycle</span>
388
+ <span class="ruby-identifier">pull</span>; <span class="ruby-identifier">process</span>; <span class="ruby-identifier">push</span>
389
+ <span class="ruby-keyword">end</span></pre>
390
+ </div><!-- cycle-source -->
391
+
392
+ </div>
393
+
394
+
395
+
396
+
397
+ </div><!-- cycle-method -->
398
+
399
+
400
+ <div id="method-i-dispatch" class="method-detail ">
401
+
402
+ <div class="method-heading">
403
+ <span class="method-name">dispatch</span><span
404
+ class="method-args">(resp)</span>
405
+ <span class="method-click-advice">click to toggle source</span>
406
+ </div>
407
+
408
+
409
+ <div class="method-description">
410
+
411
+
412
+
413
+
414
+
415
+ <div class="method-source-code" id="dispatch-source">
416
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 58</span>
417
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">dispatch</span>(<span class="ruby-identifier">resp</span>)
418
+ <span class="ruby-comment"># Performs appropriate dispatch operation for response type.</span>
419
+ <span class="ruby-keyword">begin</span>
420
+ <span class="ruby-identifier">source</span> = <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">source</span>
421
+ <span class="ruby-keyword">if</span> <span class="ruby-ivar">@twitter</span> <span class="ruby-operator">&amp;&amp;</span> [<span class="ruby-constant">Twitter</span><span class="ruby-operator">::</span><span class="ruby-constant">Tweet</span>, <span class="ruby-constant">Twitter</span><span class="ruby-operator">::</span><span class="ruby-constant">DirectMessage</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">source</span>.<span class="ruby-identifier">class</span>)
422
+ <span class="ruby-ivar">@twitter</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">resp</span>)
423
+ <span class="ruby-keyword">elsif</span> <span class="ruby-ivar">@xmpp</span> <span class="ruby-operator">&amp;&amp;</span> [<span class="ruby-constant">XMPP</span><span class="ruby-operator">::</span><span class="ruby-constant">Message</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">source</span>.<span class="ruby-identifier">class</span>)
424
+ <span class="ruby-ivar">@xmpp</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">resp</span>)
425
+ <span class="ruby-keyword">else</span>
426
+ <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-node">&quot;Don't know how to send response to a #{source.class}!&quot;</span>
427
+ <span class="ruby-keyword">end</span>
428
+
429
+ <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">dispatched</span> = <span class="ruby-keyword">true</span>
430
+ <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">save</span>
431
+ <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
432
+ <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-node">&quot;Error dispatching #{source.class} '#{resp.text}': #{e}&quot;</span>
433
+ <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">errors</span>[<span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>] = <span class="ruby-identifier">e</span>
434
+ <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">save</span>
435
+ <span class="ruby-identifier">emit</span>(<span class="ruby-value">:dispatch_error</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">e</span>)
436
+ <span class="ruby-keyword">end</span>
437
+ <span class="ruby-keyword">end</span></pre>
438
+ </div><!-- dispatch-source -->
439
+
440
+ </div>
441
+
442
+
443
+
444
+
445
+ </div><!-- dispatch-method -->
446
+
447
+
448
+ <div id="method-i-enable_twitter" class="method-detail ">
449
+
450
+ <div class="method-heading">
451
+ <span class="method-name">enable_twitter</span><span
452
+ class="method-args">(opts={})</span>
453
+ <span class="method-click-advice">click to toggle source</span>
454
+ </div>
455
+
456
+
457
+ <div class="method-description">
458
+
459
+
460
+
461
+
462
+
463
+ <div class="method-source-code" id="enable_twitter-source">
464
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 150</span>
465
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">enable_twitter</span>(<span class="ruby-identifier">opts</span>={})
466
+ <span class="ruby-ivar">@twitter</span> = <span class="ruby-constant">Twitter</span><span class="ruby-operator">::</span><span class="ruby-constant">Bot</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">opts</span>)
467
+ <span class="ruby-ivar">@twitter</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value">:request</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">req</span><span class="ruby-operator">|</span>
468
+ <span class="ruby-identifier">process</span>; <span class="ruby-identifier">push</span>
469
+ <span class="ruby-keyword">end</span>
470
+ <span class="ruby-keyword">end</span></pre>
471
+ </div><!-- enable_twitter-source -->
472
+
473
+ </div>
474
+
475
+
476
+
477
+
478
+ </div><!-- enable_twitter-method -->
479
+
480
+
481
+ <div id="method-i-enable_xmpp" class="method-detail ">
482
+
483
+ <div class="method-heading">
484
+ <span class="method-name">enable_xmpp</span><span
485
+ class="method-args">(options={})</span>
486
+ <span class="method-click-advice">click to toggle source</span>
487
+ </div>
488
+
489
+
490
+ <div class="method-description">
491
+
492
+
493
+
494
+
495
+
496
+ <div class="method-source-code" id="enable_xmpp-source">
497
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 157</span>
498
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">enable_xmpp</span>(<span class="ruby-identifier">options</span>={})
499
+ <span class="ruby-identifier">defaults</span> = { <span class="ruby-value">:jid</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">:password</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">nil</span> }
500
+ <span class="ruby-ivar">@xmpp</span> = <span class="ruby-constant">XMPP</span><span class="ruby-operator">::</span><span class="ruby-constant">Bot</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>))
501
+ <span class="ruby-ivar">@xmpp</span>.<span class="ruby-identifier">on</span>(<span class="ruby-value">:request</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">req</span><span class="ruby-operator">|</span>
502
+ <span class="ruby-identifier">process</span>; <span class="ruby-identifier">push</span>
503
+ <span class="ruby-keyword">end</span>
504
+ <span class="ruby-keyword">end</span></pre>
505
+ </div><!-- enable_xmpp-source -->
506
+
507
+ </div>
508
+
509
+
510
+
511
+
512
+ </div><!-- enable_xmpp-method -->
513
+
514
+
515
+ <div id="method-i-process" class="method-detail ">
516
+
517
+ <div class="method-heading">
518
+ <span class="method-name">process</span><span
519
+ class="method-args">()</span>
520
+ <span class="method-click-advice">click to toggle source</span>
521
+ </div>
522
+
523
+
524
+ <div class="method-description">
525
+
526
+
527
+
528
+
529
+
530
+ <div class="method-source-code" id="process-source">
531
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 84</span>
532
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">process</span>
533
+ <span class="ruby-constant">Request</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value">:processed</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">false</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">req</span><span class="ruby-operator">|</span>
534
+ <span class="ruby-identifier">concurrently</span>(<span class="ruby-identifier">req</span>) { <span class="ruby-identifier">process_request</span>(<span class="ruby-identifier">req</span>) }
535
+ <span class="ruby-keyword">end</span>
536
+ <span class="ruby-keyword">end</span></pre>
537
+ </div><!-- process-source -->
538
+
539
+ </div>
540
+
541
+
542
+
543
+
544
+ </div><!-- process-method -->
545
+
546
+
547
+ <div id="method-i-process_request" class="method-detail ">
548
+
549
+ <div class="method-heading">
550
+ <span class="method-name">process_request</span><span
551
+ class="method-args">(req)</span>
552
+ <span class="method-click-advice">click to toggle source</span>
553
+ </div>
554
+
555
+
556
+ <div class="method-description">
557
+
558
+
559
+
560
+
561
+
562
+ <div class="method-source-code" id="process_request-source">
563
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 47</span>
564
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">process_request</span>(<span class="ruby-identifier">req</span>)
565
+ <span class="ruby-keyword">begin</span>
566
+ <span class="ruby-identifier">emit</span>(<span class="ruby-value">:request</span>, <span class="ruby-identifier">req</span>)
567
+ <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
568
+ <span class="ruby-identifier">request_error</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">e</span>)
569
+ <span class="ruby-keyword">ensure</span>
570
+ <span class="ruby-identifier">req</span>.<span class="ruby-identifier">processed</span> = <span class="ruby-keyword">true</span>
571
+ <span class="ruby-identifier">req</span>.<span class="ruby-identifier">save</span>
572
+ <span class="ruby-keyword">end</span>
573
+ <span class="ruby-keyword">end</span></pre>
574
+ </div><!-- process_request-source -->
575
+
576
+ </div>
577
+
578
+
579
+
580
+
581
+ </div><!-- process_request-method -->
582
+
583
+
584
+ <div id="method-i-pull" class="method-detail ">
585
+
586
+ <div class="method-heading">
587
+ <span class="method-name">pull</span><span
588
+ class="method-args">()</span>
589
+ <span class="method-click-advice">click to toggle source</span>
590
+ </div>
591
+
592
+
593
+ <div class="method-description">
594
+
595
+
596
+
597
+
598
+
599
+ <div class="method-source-code" id="pull-source">
600
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 80</span>
601
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">pull</span>
602
+ <span class="ruby-ivar">@twitter</span>.<span class="ruby-identifier">pull</span>
603
+ <span class="ruby-keyword">end</span></pre>
604
+ </div><!-- pull-source -->
605
+
606
+ </div>
607
+
608
+
609
+
610
+
611
+ </div><!-- pull-method -->
612
+
613
+
614
+ <div id="method-i-push" class="method-detail ">
615
+
616
+ <div class="method-heading">
617
+ <span class="method-name">push</span><span
618
+ class="method-args">()</span>
619
+ <span class="method-click-advice">click to toggle source</span>
620
+ </div>
621
+
622
+
623
+ <div class="method-description">
624
+
625
+
626
+
627
+
628
+
629
+ <div class="method-source-code" id="push-source">
630
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 104</span>
631
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">push</span>
632
+ <span class="ruby-constant">Response</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value">:dispatched</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">false</span>).<span class="ruby-identifier">each</span>(&amp;<span class="ruby-identifier">method</span>(<span class="ruby-value">:dispatch</span>))
633
+ <span class="ruby-keyword">end</span></pre>
634
+ </div><!-- push-source -->
635
+
636
+ </div>
637
+
638
+
639
+
640
+
641
+ </div><!-- push-method -->
642
+
643
+
644
+ <div id="method-i-request_error" class="method-detail ">
645
+
646
+ <div class="method-heading">
647
+ <span class="method-name">request_error</span><span
648
+ class="method-args">(req, e)</span>
649
+ <span class="method-click-advice">click to toggle source</span>
650
+ </div>
651
+
652
+
653
+ <div class="method-description">
654
+
655
+
656
+
657
+
658
+
659
+ <div class="method-source-code" id="request_error-source">
660
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 40</span>
661
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">request_error</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">e</span>)
662
+ <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-node">&quot;Error processing #{req.source.class} '#{req.text}': #{e}\n#{e.backtrace.join(&quot;\n\t&quot;)}&quot;</span>
663
+ <span class="ruby-identifier">req</span>.<span class="ruby-identifier">errors</span>[<span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>] = <span class="ruby-identifier">e</span>
664
+ <span class="ruby-identifier">req</span>.<span class="ruby-identifier">save</span>
665
+ <span class="ruby-identifier">emit</span>(<span class="ruby-value">:request_error</span>, <span class="ruby-identifier">req</span>, <span class="ruby-identifier">e</span>)
666
+ <span class="ruby-keyword">end</span></pre>
667
+ </div><!-- request_error-source -->
668
+
669
+ </div>
670
+
671
+
672
+
673
+
674
+ </div><!-- request_error-method -->
675
+
676
+
677
+ <div id="method-i-respond" class="method-detail ">
678
+
679
+ <div class="method-heading">
680
+ <span class="method-name">respond</span><span
681
+ class="method-args">(req, text)</span>
682
+ <span class="method-click-advice">click to toggle source</span>
683
+ </div>
684
+
685
+
686
+ <div class="method-description">
687
+
688
+ <p>Adds a response to the queue. @param req <a href="Request.html">Request</a>
689
+ to respond to. @param text Contents of the response.</p>
690
+
691
+
692
+
693
+ <div class="method-source-code" id="respond-source">
694
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 93</span>
695
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">respond</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">text</span>)
696
+ <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;#{req.user.name}: #{req.text}\nsafubot: #{text}&quot;</span>)
697
+ <span class="ruby-constant">Response</span>.<span class="ruby-identifier">create</span>(<span class="ruby-value">:request</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">req</span>, <span class="ruby-value">:text</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">text</span>)
698
+ <span class="ruby-keyword">end</span></pre>
699
+ </div><!-- respond-source -->
700
+
701
+ </div>
702
+
703
+
704
+
705
+
706
+ </div><!-- respond-method -->
707
+
708
+
709
+ <div id="method-i-respond_now" class="method-detail ">
710
+
711
+ <div class="method-heading">
712
+ <span class="method-name">respond_now</span><span
713
+ class="method-args">(req, text)</span>
714
+ <span class="method-click-advice">click to toggle source</span>
715
+ </div>
716
+
717
+
718
+ <div class="method-description">
719
+
720
+ <p>Respond + push</p>
721
+
722
+
723
+
724
+ <div class="method-source-code" id="respond_now-source">
725
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 99</span>
726
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">respond_now</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">text</span>)
727
+ <span class="ruby-identifier">respond</span>(<span class="ruby-identifier">req</span>, <span class="ruby-identifier">text</span>)
728
+ <span class="ruby-identifier">push</span>
729
+ <span class="ruby-keyword">end</span></pre>
730
+ </div><!-- respond_now-source -->
731
+
732
+ </div>
733
+
734
+
735
+
736
+
737
+ </div><!-- respond_now-method -->
738
+
739
+
740
+ <div id="method-i-run" class="method-detail ">
741
+
742
+ <div class="method-heading">
743
+ <span class="method-name">run</span><span
744
+ class="method-args">()</span>
745
+ <span class="method-click-advice">click to toggle source</span>
746
+ </div>
747
+
748
+
749
+ <div class="method-description">
750
+
751
+
752
+
753
+
754
+
755
+ <div class="method-source-code" id="run-source">
756
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 127</span>
757
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">run</span>
758
+ <span class="ruby-constant">EventMachine</span><span class="ruby-operator">::</span><span class="ruby-identifier">run</span> <span class="ruby-keyword">do</span>
759
+ <span class="ruby-constant">EM</span><span class="ruby-operator">::</span><span class="ruby-identifier">error_handler</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
760
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Interrupt</span>
761
+ <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&quot;Received interrupt, shutting down.&quot;</span>)
762
+ <span class="ruby-identifier">stop</span>
763
+ <span class="ruby-keyword">else</span>
764
+ <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;Unhandled exception: #{e}\n#{e.backtrace.join(&quot;\t\n&quot;)}&quot;</span>)
765
+ <span class="ruby-keyword">end</span>
766
+ <span class="ruby-keyword">end</span>
767
+
768
+ <span class="ruby-identifier">cycle</span>
769
+ <span class="ruby-ivar">@twitter</span>.<span class="ruby-identifier">run</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@twitter</span>
770
+ <span class="ruby-ivar">@xmpp</span>.<span class="ruby-identifier">run</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@xmpp</span>
771
+ <span class="ruby-keyword">end</span>
772
+ <span class="ruby-keyword">end</span></pre>
773
+ </div><!-- run-source -->
774
+
775
+ </div>
776
+
777
+
778
+
779
+
780
+ </div><!-- run-method -->
781
+
782
+
783
+ <div id="method-i-stop" class="method-detail ">
784
+
785
+ <div class="method-heading">
786
+ <span class="method-name">stop</span><span
787
+ class="method-args">()</span>
788
+ <span class="method-click-advice">click to toggle source</span>
789
+ </div>
790
+
791
+
792
+ <div class="method-description">
793
+
794
+
795
+
796
+
797
+
798
+ <div class="method-source-code" id="stop-source">
799
+ <pre><span class="ruby-comment"># File lib/safubot/bot.rb, line 144</span>
800
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier">stop</span>
801
+ <span class="ruby-ivar">@twitter</span>.<span class="ruby-identifier">stop</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@twitter</span>
802
+ <span class="ruby-ivar">@xmpp</span>.<span class="ruby-identifier">stop</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@xmpp</span>
803
+ <span class="ruby-constant">EM</span><span class="ruby-operator">::</span><span class="ruby-identifier">stop_event_loop</span>
804
+ <span class="ruby-keyword">end</span></pre>
805
+ </div><!-- stop-source -->
806
+
807
+ </div>
808
+
809
+
810
+
811
+
812
+ </div><!-- stop-method -->
813
+
814
+
815
+ </section><!-- public-instance-method-details -->
816
+
817
+ </section><!-- 5Buntitled-5D -->
818
+
819
+ </div><!-- documentation -->
820
+
821
+
822
+ <footer id="validator-badges">
823
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
824
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
825
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
826
+ </footer>
827
+