safubot 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE.md +19 -0
- data/README.md +43 -0
- data/Rakefile +1 -0
- data/doc/Gemfile.html +119 -0
- data/doc/Object.html +171 -0
- data/doc/Rakefile.html +117 -0
- data/doc/Safubot.html +173 -0
- data/doc/Safubot/Bot.html +827 -0
- data/doc/Safubot/Evented.html +346 -0
- data/doc/Safubot/KnownUser.html +344 -0
- data/doc/Safubot/Log.html +254 -0
- data/doc/Safubot/Query.html +217 -0
- data/doc/Safubot/Request.html +201 -0
- data/doc/Safubot/Response.html +174 -0
- data/doc/Safubot/Test.html +244 -0
- data/doc/Safubot/Twitter.html +153 -0
- data/doc/Safubot/Twitter/Bot.html +591 -0
- data/doc/Safubot/Twitter/DirectMessage.html +327 -0
- data/doc/Safubot/Twitter/Tweet.html +522 -0
- data/doc/Safubot/XMPP.html +153 -0
- data/doc/Safubot/XMPP/Bot.html +403 -0
- data/doc/Safubot/XMPP/Message.html +298 -0
- data/doc/created.rid +14 -0
- data/doc/foo_rb.html +115 -0
- data/doc/images/add.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +112 -0
- data/doc/js/darkfish.js +153 -0
- data/doc/js/jquery.js +18 -0
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/lib/safubot/bot_rb.html +115 -0
- data/doc/lib/safubot/evented_rb.html +115 -0
- data/doc/lib/safubot/known_user_rb.html +115 -0
- data/doc/lib/safubot/log_rb.html +115 -0
- data/doc/lib/safubot/safubot_rb.html +115 -0
- data/doc/lib/safubot/spec/bot_spec_rb.html +115 -0
- data/doc/lib/safubot/spec/twitter_spec_rb.html +137 -0
- data/doc/lib/safubot/test_helper_rb.html +115 -0
- data/doc/lib/safubot/twitter_rb.html +115 -0
- data/doc/lib/safubot/version_rb.html +115 -0
- data/doc/lib/safubot/xmpp_rb.html +115 -0
- data/doc/lib/safubot_rb.html +115 -0
- data/doc/rdoc.css +543 -0
- data/doc/table_of_contents.html +224 -0
- data/lib/safubot.rb +20 -0
- data/lib/safubot/bot.rb +177 -0
- data/lib/safubot/evented.rb +52 -0
- data/lib/safubot/known_user.rb +27 -0
- data/lib/safubot/log.rb +21 -0
- data/lib/safubot/test_helper.rb +62 -0
- data/lib/safubot/twitter.rb +279 -0
- data/lib/safubot/version.rb +3 -0
- data/lib/safubot/xmpp.rb +144 -0
- data/safubot.gemspec +32 -0
- data/spec/fixtures/twitter/direct_message +1 -0
- data/spec/fixtures/twitter/tweet +1 -0
- data/spec/fixtures/xmpp/message +3 -0
- data/spec/helper.rb +12 -0
- data/spec/safubot/bot_spec.rb +41 -0
- data/spec/safubot/evented_spec.rb +45 -0
- data/spec/safubot/known_user_spec.rb +22 -0
- data/spec/safubot/twitter_spec.rb +60 -0
- data/spec/safubot/xmpp_spec.rb +35 -0
- metadata +260 -0
@@ -0,0 +1,153 @@
|
|
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::Twitter</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/twitter.rb
|
51
|
+
</ul>
|
52
|
+
</nav>
|
53
|
+
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div id="class-metadata">
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<div id="project-metadata">
|
65
|
+
<nav id="fileindex-section" class="section project-section">
|
66
|
+
<h3 class="section-header">Pages</h3>
|
67
|
+
|
68
|
+
<ul>
|
69
|
+
|
70
|
+
<li class="file"><a href="../Gemfile.html">Gemfile</a>
|
71
|
+
|
72
|
+
<li class="file"><a href="../Rakefile.html">Rakefile</a>
|
73
|
+
|
74
|
+
</ul>
|
75
|
+
</nav>
|
76
|
+
|
77
|
+
<nav id="classindex-section" class="section project-section">
|
78
|
+
<h3 class="section-header">Class and Module Index</h3>
|
79
|
+
|
80
|
+
<ul class="link-list">
|
81
|
+
|
82
|
+
<li><a href="../Safubot.html">Safubot</a>
|
83
|
+
|
84
|
+
<li><a href="../Safubot/Bot.html">Safubot::Bot</a>
|
85
|
+
|
86
|
+
<li><a href="../Safubot/Evented.html">Safubot::Evented</a>
|
87
|
+
|
88
|
+
<li><a href="../Safubot/KnownUser.html">Safubot::KnownUser</a>
|
89
|
+
|
90
|
+
<li><a href="../Safubot/Log.html">Safubot::Log</a>
|
91
|
+
|
92
|
+
<li><a href="../Safubot/Query.html">Safubot::Query</a>
|
93
|
+
|
94
|
+
<li><a href="../Safubot/Request.html">Safubot::Request</a>
|
95
|
+
|
96
|
+
<li><a href="../Safubot/Response.html">Safubot::Response</a>
|
97
|
+
|
98
|
+
<li><a href="../Safubot/Test.html">Safubot::Test</a>
|
99
|
+
|
100
|
+
<li><a href="../Safubot/Twitter.html">Safubot::Twitter</a>
|
101
|
+
|
102
|
+
<li><a href="../Safubot/Twitter/Bot.html">Safubot::Twitter::Bot</a>
|
103
|
+
|
104
|
+
<li><a href="../Safubot/Twitter/DirectMessage.html">Safubot::Twitter::DirectMessage</a>
|
105
|
+
|
106
|
+
<li><a href="../Safubot/Twitter/Tweet.html">Safubot::Twitter::Tweet</a>
|
107
|
+
|
108
|
+
<li><a href="../Safubot/XMPP.html">Safubot::XMPP</a>
|
109
|
+
|
110
|
+
<li><a href="../Safubot/XMPP/Bot.html">Safubot::XMPP::Bot</a>
|
111
|
+
|
112
|
+
<li><a href="../Safubot/XMPP/Message.html">Safubot::XMPP::Message</a>
|
113
|
+
|
114
|
+
<li><a href="../Object.html">Object</a>
|
115
|
+
|
116
|
+
</ul>
|
117
|
+
</nav>
|
118
|
+
|
119
|
+
</div>
|
120
|
+
</nav>
|
121
|
+
|
122
|
+
<div id="documentation">
|
123
|
+
<h1 class="module">module Safubot::Twitter</h1>
|
124
|
+
|
125
|
+
<div id="description" class="description">
|
126
|
+
|
127
|
+
</div><!-- description -->
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
<!-- Methods -->
|
142
|
+
|
143
|
+
</section><!-- 5Buntitled-5D -->
|
144
|
+
|
145
|
+
</div><!-- documentation -->
|
146
|
+
|
147
|
+
|
148
|
+
<footer id="validator-badges">
|
149
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
150
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
|
151
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
152
|
+
</footer>
|
153
|
+
|
@@ -0,0 +1,591 @@
|
|
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::Twitter::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/twitter.rb
|
51
|
+
</ul>
|
52
|
+
</nav>
|
53
|
+
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div id="class-metadata">
|
58
|
+
|
59
|
+
<nav id="parent-class-section" class="section">
|
60
|
+
<h3 class="section-header">Parent</h3>
|
61
|
+
|
62
|
+
<p class="link"><a href="../../Object.html">Object</a>
|
63
|
+
|
64
|
+
</nav>
|
65
|
+
|
66
|
+
<!-- Included Modules -->
|
67
|
+
<nav id="includes-section" class="section">
|
68
|
+
<h3 class="section-header">Included Modules</h3>
|
69
|
+
|
70
|
+
<ul class="link-list">
|
71
|
+
|
72
|
+
|
73
|
+
<li><a class="include" href="../Evented.html">Safubot::Evented</a>
|
74
|
+
|
75
|
+
|
76
|
+
</ul>
|
77
|
+
</nav>
|
78
|
+
|
79
|
+
<!-- Method Quickref -->
|
80
|
+
<nav id="method-list-section" class="section">
|
81
|
+
<h3 class="section-header">Methods</h3>
|
82
|
+
|
83
|
+
<ul class="link-list">
|
84
|
+
|
85
|
+
<li><a href="#method-c-new">::new</a>
|
86
|
+
|
87
|
+
<li><a href="#method-i-handle_message">#handle_message</a>
|
88
|
+
|
89
|
+
<li><a href="#method-i-handle_request">#handle_request</a>
|
90
|
+
|
91
|
+
<li><a href="#method-i-handle_tweet">#handle_tweet</a>
|
92
|
+
|
93
|
+
<li><a href="#method-i-pull">#pull</a>
|
94
|
+
|
95
|
+
<li><a href="#method-i-reply">#reply</a>
|
96
|
+
|
97
|
+
<li><a href="#method-i-reply_header">#reply_header</a>
|
98
|
+
|
99
|
+
<li><a href="#method-i-run">#run</a>
|
100
|
+
|
101
|
+
<li><a href="#method-i-send">#send</a>
|
102
|
+
|
103
|
+
</ul>
|
104
|
+
</nav>
|
105
|
+
|
106
|
+
</div>
|
107
|
+
|
108
|
+
<div id="project-metadata">
|
109
|
+
<nav id="fileindex-section" class="section project-section">
|
110
|
+
<h3 class="section-header">Pages</h3>
|
111
|
+
|
112
|
+
<ul>
|
113
|
+
|
114
|
+
<li class="file"><a href="../../Gemfile.html">Gemfile</a>
|
115
|
+
|
116
|
+
<li class="file"><a href="../../Rakefile.html">Rakefile</a>
|
117
|
+
|
118
|
+
</ul>
|
119
|
+
</nav>
|
120
|
+
|
121
|
+
<nav id="classindex-section" class="section project-section">
|
122
|
+
<h3 class="section-header">Class and Module Index</h3>
|
123
|
+
|
124
|
+
<ul class="link-list">
|
125
|
+
|
126
|
+
<li><a href="../../Safubot.html">Safubot</a>
|
127
|
+
|
128
|
+
<li><a href="../../Safubot/Bot.html">Safubot::Bot</a>
|
129
|
+
|
130
|
+
<li><a href="../../Safubot/Evented.html">Safubot::Evented</a>
|
131
|
+
|
132
|
+
<li><a href="../../Safubot/KnownUser.html">Safubot::KnownUser</a>
|
133
|
+
|
134
|
+
<li><a href="../../Safubot/Log.html">Safubot::Log</a>
|
135
|
+
|
136
|
+
<li><a href="../../Safubot/Query.html">Safubot::Query</a>
|
137
|
+
|
138
|
+
<li><a href="../../Safubot/Request.html">Safubot::Request</a>
|
139
|
+
|
140
|
+
<li><a href="../../Safubot/Response.html">Safubot::Response</a>
|
141
|
+
|
142
|
+
<li><a href="../../Safubot/Test.html">Safubot::Test</a>
|
143
|
+
|
144
|
+
<li><a href="../../Safubot/Twitter.html">Safubot::Twitter</a>
|
145
|
+
|
146
|
+
<li><a href="../../Safubot/Twitter/Bot.html">Safubot::Twitter::Bot</a>
|
147
|
+
|
148
|
+
<li><a href="../../Safubot/Twitter/DirectMessage.html">Safubot::Twitter::DirectMessage</a>
|
149
|
+
|
150
|
+
<li><a href="../../Safubot/Twitter/Tweet.html">Safubot::Twitter::Tweet</a>
|
151
|
+
|
152
|
+
<li><a href="../../Safubot/XMPP.html">Safubot::XMPP</a>
|
153
|
+
|
154
|
+
<li><a href="../../Safubot/XMPP/Bot.html">Safubot::XMPP::Bot</a>
|
155
|
+
|
156
|
+
<li><a href="../../Safubot/XMPP/Message.html">Safubot::XMPP::Message</a>
|
157
|
+
|
158
|
+
<li><a href="../../Object.html">Object</a>
|
159
|
+
|
160
|
+
</ul>
|
161
|
+
</nav>
|
162
|
+
|
163
|
+
</div>
|
164
|
+
</nav>
|
165
|
+
|
166
|
+
<div id="documentation">
|
167
|
+
<h1 class="class">class Safubot::Twitter::Bot</h1>
|
168
|
+
|
169
|
+
<div id="description" class="description">
|
170
|
+
|
171
|
+
<p>A <a href="Bot.html">Twitter::Bot</a> instance provides a <a
|
172
|
+
href="../Bot.html">Safubot::Bot</a> with Twitter-specific processing.</p>
|
173
|
+
|
174
|
+
</div><!-- description -->
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
<!-- Attributes -->
|
188
|
+
<section id="attribute-method-details" class="method-section section">
|
189
|
+
<h3 class="section-header">Attributes</h3>
|
190
|
+
|
191
|
+
|
192
|
+
<div id="attribute-i-client" class="method-detail">
|
193
|
+
<div class="method-heading attribute-method-heading">
|
194
|
+
<span class="method-name">client</span><span
|
195
|
+
class="attribute-access-type">[R]</span>
|
196
|
+
</div>
|
197
|
+
|
198
|
+
<div class="method-description">
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
</div>
|
203
|
+
</div>
|
204
|
+
|
205
|
+
<div id="attribute-i-opts" class="method-detail">
|
206
|
+
<div class="method-heading attribute-method-heading">
|
207
|
+
<span class="method-name">opts</span><span
|
208
|
+
class="attribute-access-type">[R]</span>
|
209
|
+
</div>
|
210
|
+
|
211
|
+
<div class="method-description">
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
</div>
|
216
|
+
</div>
|
217
|
+
|
218
|
+
<div id="attribute-i-username" class="method-detail">
|
219
|
+
<div class="method-heading attribute-method-heading">
|
220
|
+
<span class="method-name">username</span><span
|
221
|
+
class="attribute-access-type">[R]</span>
|
222
|
+
</div>
|
223
|
+
|
224
|
+
<div class="method-description">
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
</div>
|
229
|
+
</div>
|
230
|
+
|
231
|
+
</section><!-- attribute-method-details -->
|
232
|
+
|
233
|
+
|
234
|
+
<!-- Methods -->
|
235
|
+
|
236
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section section">
|
237
|
+
<h3 class="section-header">Public Class Methods</h3>
|
238
|
+
|
239
|
+
|
240
|
+
<div id="method-c-new" class="method-detail ">
|
241
|
+
|
242
|
+
<div class="method-heading">
|
243
|
+
<span class="method-name">new</span><span
|
244
|
+
class="method-args">(options={})</span>
|
245
|
+
<span class="method-click-advice">click to toggle source</span>
|
246
|
+
</div>
|
247
|
+
|
248
|
+
|
249
|
+
<div class="method-description">
|
250
|
+
|
251
|
+
<p>Options are passed straight through to ::TweetStream and ::Twitter, but the
|
252
|
+
:username is ours and important.</p>
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
<div class="method-source-code" id="new-source">
|
257
|
+
<pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 249</span>
|
258
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={})
|
259
|
+
<span class="ruby-identifier">defaults</span> = { <span class="ruby-value">:username</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>,
|
260
|
+
<span class="ruby-value">:consumer_key</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">:consumer_secret</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>,
|
261
|
+
<span class="ruby-value">:oauth_token</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">:oauth_token_secret</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">nil</span>,
|
262
|
+
<span class="ruby-value">:auth_method</span> =<span class="ruby-operator">></span> <span class="ruby-value">:oauth</span> }
|
263
|
+
|
264
|
+
<span class="ruby-ivar">@opts</span> = <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
|
265
|
+
|
266
|
+
<span class="ruby-constant">DirectMessage</span>.<span class="ruby-identifier">ensure_index</span>(<span class="ruby-string">'raw.id'</span>, <span class="ruby-value">:unique</span> =<span class="ruby-operator">></span> <span class="ruby-keyword">true</span>)
|
267
|
+
<span class="ruby-ivar">@username</span> = <span class="ruby-ivar">@opts</span>[<span class="ruby-value">:username</span>]
|
268
|
+
<span class="ruby-ivar">@client</span> = <span class="ruby-constant">Object</span><span class="ruby-operator">::</span><span class="ruby-constant">Twitter</span><span class="ruby-operator">::</span><span class="ruby-constant">Client</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@opts</span>)
|
269
|
+
<span class="ruby-keyword">end</span></pre>
|
270
|
+
</div><!-- new-source -->
|
271
|
+
|
272
|
+
</div>
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
</div><!-- new-method -->
|
278
|
+
|
279
|
+
|
280
|
+
</section><!-- public-class-method-details -->
|
281
|
+
|
282
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
|
283
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
284
|
+
|
285
|
+
|
286
|
+
<div id="method-i-handle_message" class="method-detail ">
|
287
|
+
|
288
|
+
<div class="method-heading">
|
289
|
+
<span class="method-name">handle_message</span><span
|
290
|
+
class="method-args">(message)</span>
|
291
|
+
<span class="method-click-advice">click to toggle source</span>
|
292
|
+
</div>
|
293
|
+
|
294
|
+
|
295
|
+
<div class="method-description">
|
296
|
+
|
297
|
+
<p>Stores a DM and creates a matching <a href="../Request.html">Request</a> as
|
298
|
+
needed.</p>
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
<div class="method-source-code" id="handle_message-source">
|
303
|
+
<pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 174</span>
|
304
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">handle_message</span>(<span class="ruby-identifier">message</span>)
|
305
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">message</span>.<span class="ruby-identifier">sender</span>.<span class="ruby-identifier">screen_name</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@username</span>
|
306
|
+
<span class="ruby-identifier">handle_request</span>(<span class="ruby-constant">DirectMessage</span>.<span class="ruby-identifier">from</span>(<span class="ruby-identifier">message</span>).<span class="ruby-identifier">make_request</span>)
|
307
|
+
<span class="ruby-keyword">end</span></pre>
|
308
|
+
</div><!-- handle_message-source -->
|
309
|
+
|
310
|
+
</div>
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
</div><!-- handle_message-method -->
|
316
|
+
|
317
|
+
|
318
|
+
<div id="method-i-handle_request" class="method-detail ">
|
319
|
+
|
320
|
+
<div class="method-heading">
|
321
|
+
<span class="method-name">handle_request</span><span
|
322
|
+
class="method-args">(req)</span>
|
323
|
+
<span class="method-click-advice">click to toggle source</span>
|
324
|
+
</div>
|
325
|
+
|
326
|
+
|
327
|
+
<div class="method-description">
|
328
|
+
|
329
|
+
<p>Emit a request event unless the request is already processed.</p>
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
<div class="method-source-code" id="handle_request-source">
|
334
|
+
<pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 169</span>
|
335
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">handle_request</span>(<span class="ruby-identifier">req</span>)
|
336
|
+
<span class="ruby-identifier">emit</span>(<span class="ruby-value">:request</span>, <span class="ruby-identifier">req</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">req</span>.<span class="ruby-identifier">processed</span>
|
337
|
+
<span class="ruby-keyword">end</span></pre>
|
338
|
+
</div><!-- handle_request-source -->
|
339
|
+
|
340
|
+
</div>
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
</div><!-- handle_request-method -->
|
346
|
+
|
347
|
+
|
348
|
+
<div id="method-i-handle_tweet" class="method-detail ">
|
349
|
+
|
350
|
+
<div class="method-heading">
|
351
|
+
<span class="method-name">handle_tweet</span><span
|
352
|
+
class="method-args">(status)</span>
|
353
|
+
<span class="method-click-advice">click to toggle source</span>
|
354
|
+
</div>
|
355
|
+
|
356
|
+
|
357
|
+
<div class="method-description">
|
358
|
+
|
359
|
+
<p>Stores a tweet. If this tweet is directed at us, create a matching <a
|
360
|
+
href="../Request.html">Request</a>. Otherwise, emit a :timeline event.</p>
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
<div class="method-source-code" id="handle_tweet-source">
|
365
|
+
<pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 181</span>
|
366
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">handle_tweet</span>(<span class="ruby-identifier">status</span>)
|
367
|
+
<span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">user</span>.<span class="ruby-identifier">screen_name</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@username</span>
|
368
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">status</span>.<span class="ruby-identifier">text</span>.<span class="ruby-identifier">match</span>(<span class="ruby-node">/@#{@username}/</span>)
|
369
|
+
<span class="ruby-identifier">handle_request</span>(<span class="ruby-constant">Tweet</span>.<span class="ruby-identifier">from</span>(<span class="ruby-identifier">status</span>).<span class="ruby-identifier">make_request</span>)
|
370
|
+
<span class="ruby-keyword">else</span>
|
371
|
+
<span class="ruby-identifier">emit</span>(<span class="ruby-value">:timeline</span>, <span class="ruby-constant">Tweet</span>.<span class="ruby-identifier">from</span>(<span class="ruby-identifier">status</span>))
|
372
|
+
<span class="ruby-keyword">end</span>
|
373
|
+
<span class="ruby-keyword">end</span></pre>
|
374
|
+
</div><!-- handle_tweet-source -->
|
375
|
+
|
376
|
+
</div>
|
377
|
+
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
</div><!-- handle_tweet-method -->
|
382
|
+
|
383
|
+
|
384
|
+
<div id="method-i-pull" class="method-detail ">
|
385
|
+
|
386
|
+
<div class="method-heading">
|
387
|
+
<span class="method-name">pull</span><span
|
388
|
+
class="method-args">()</span>
|
389
|
+
<span class="method-click-advice">click to toggle source</span>
|
390
|
+
</div>
|
391
|
+
|
392
|
+
|
393
|
+
<div class="method-description">
|
394
|
+
|
395
|
+
<p>Pulls DMs and mentions using the AJAX API. Used in tandem with the
|
396
|
+
streaming API to ensure we don’t miss too much while we’re offline.</p>
|
397
|
+
|
398
|
+
|
399
|
+
|
400
|
+
<div class="method-source-code" id="pull-source">
|
401
|
+
<pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 204</span>
|
402
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">pull</span>
|
403
|
+
<span class="ruby-keyword">begin</span>
|
404
|
+
<span class="ruby-ivar">@client</span>.<span class="ruby-identifier">direct_messages</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">message</span><span class="ruby-operator">|</span>
|
405
|
+
<span class="ruby-identifier">handle_message</span>(<span class="ruby-identifier">message</span>)
|
406
|
+
<span class="ruby-keyword">end</span>
|
407
|
+
|
408
|
+
<span class="ruby-ivar">@client</span>.<span class="ruby-identifier">mentions</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">mention</span><span class="ruby-operator">|</span>
|
409
|
+
<span class="ruby-identifier">handle_tweet</span>(<span class="ruby-identifier">mention</span>)
|
410
|
+
<span class="ruby-keyword">end</span>
|
411
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-operator">::</span><span class="ruby-constant">Twitter</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span><span class="ruby-operator">::</span><span class="ruby-constant">ServiceUnavailable</span>
|
412
|
+
<span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-string">"Twitter: Couldn't pull tweets due to temporary service unavailability."</span>
|
413
|
+
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
414
|
+
<span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-node">"Twitter: Unhandled error: #{e}\n#{e.backtrace.join("\n\t")}"</span>
|
415
|
+
<span class="ruby-keyword">end</span>
|
416
|
+
<span class="ruby-keyword">end</span></pre>
|
417
|
+
</div><!-- pull-source -->
|
418
|
+
|
419
|
+
</div>
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
|
424
|
+
</div><!-- pull-method -->
|
425
|
+
|
426
|
+
|
427
|
+
<div id="method-i-reply" class="method-detail ">
|
428
|
+
|
429
|
+
<div class="method-heading">
|
430
|
+
<span class="method-name">reply</span><span
|
431
|
+
class="method-args">(tweet, text)</span>
|
432
|
+
<span class="method-click-advice">click to toggle source</span>
|
433
|
+
</div>
|
434
|
+
|
435
|
+
|
436
|
+
<div class="method-description">
|
437
|
+
|
438
|
+
<p>Replies to a tweet using the appropriate mentions. @param tweet A <a
|
439
|
+
href="Tweet.html">Tweet</a> object to respond to. @param text The response
|
440
|
+
text.</p>
|
441
|
+
|
442
|
+
|
443
|
+
|
444
|
+
<div class="method-source-code" id="reply-source">
|
445
|
+
<pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 198</span>
|
446
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">reply</span>(<span class="ruby-identifier">tweet</span>, <span class="ruby-identifier">text</span>)
|
447
|
+
<span class="ruby-ivar">@client</span>.<span class="ruby-identifier">update</span>(<span class="ruby-node">"#{reply_header(tweet)} #{text}"</span>, <span class="ruby-value">:in_reply_to_status_id</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">tweet</span>.<span class="ruby-identifier">raw</span>[<span class="ruby-string">'id'</span>])
|
448
|
+
<span class="ruby-keyword">end</span></pre>
|
449
|
+
</div><!-- reply-source -->
|
450
|
+
|
451
|
+
</div>
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
|
456
|
+
</div><!-- reply-method -->
|
457
|
+
|
458
|
+
|
459
|
+
<div id="method-i-reply_header" class="method-detail ">
|
460
|
+
|
461
|
+
<div class="method-heading">
|
462
|
+
<span class="method-name">reply_header</span><span
|
463
|
+
class="method-args">(tweet)</span>
|
464
|
+
<span class="method-click-advice">click to toggle source</span>
|
465
|
+
</div>
|
466
|
+
|
467
|
+
|
468
|
+
<div class="method-description">
|
469
|
+
|
470
|
+
<p>Constructs the appropriate series of mentions for a reply to this tweet.</p>
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
<div class="method-source-code" id="reply_header-source">
|
475
|
+
<pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 191</span>
|
476
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">reply_header</span>(<span class="ruby-identifier">tweet</span>)
|
477
|
+
([<span class="ruby-node">"@#{tweet.username}"</span>] <span class="ruby-operator">+</span> (<span class="ruby-identifier">tweet</span>.<span class="ruby-identifier">header_mentions</span> <span class="ruby-operator">-</span> [<span class="ruby-node">"@#{@username}"</span>])).<span class="ruby-identifier">join</span>
|
478
|
+
<span class="ruby-keyword">end</span></pre>
|
479
|
+
</div><!-- reply_header-source -->
|
480
|
+
|
481
|
+
</div>
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
|
486
|
+
</div><!-- reply_header-method -->
|
487
|
+
|
488
|
+
|
489
|
+
<div id="method-i-run" class="method-detail ">
|
490
|
+
|
491
|
+
<div class="method-heading">
|
492
|
+
<span class="method-name">run</span><span
|
493
|
+
class="method-args">()</span>
|
494
|
+
<span class="method-click-advice">click to toggle source</span>
|
495
|
+
</div>
|
496
|
+
|
497
|
+
|
498
|
+
<div class="method-description">
|
499
|
+
|
500
|
+
<p>Starts our TweetStream client running.</p>
|
501
|
+
|
502
|
+
|
503
|
+
|
504
|
+
<div class="method-source-code" id="run-source">
|
505
|
+
<pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 221</span>
|
506
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">run</span>
|
507
|
+
<span class="ruby-ivar">@stream</span> = <span class="ruby-constant">TweetStream</span><span class="ruby-operator">::</span><span class="ruby-constant">Client</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@opts</span>)
|
508
|
+
|
509
|
+
<span class="ruby-ivar">@stream</span>.<span class="ruby-identifier">on_direct_message</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">message</span><span class="ruby-operator">|</span>
|
510
|
+
<span class="ruby-identifier">handle_message</span>(<span class="ruby-identifier">message</span>)
|
511
|
+
<span class="ruby-keyword">end</span>
|
512
|
+
|
513
|
+
<span class="ruby-ivar">@stream</span>.<span class="ruby-identifier">on_error</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">err</span><span class="ruby-operator">|</span>
|
514
|
+
<span class="ruby-comment"># HACK (Mispy): For some reason this is a String instead of an Exception.</span>
|
515
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">err</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">/invalid status code: 401/</span>)
|
516
|
+
<span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">"TweetStream authentication failure!"</span>)
|
517
|
+
<span class="ruby-keyword">else</span>
|
518
|
+
<span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-node">"Unhandled TweetStream error: #{err}"</span>
|
519
|
+
<span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-string">"Reinitialising TweetStream in 5 seconds."</span>
|
520
|
+
<span class="ruby-identifier">sleep</span> <span class="ruby-value">5</span>
|
521
|
+
<span class="ruby-identifier">run</span>
|
522
|
+
<span class="ruby-keyword">end</span>
|
523
|
+
<span class="ruby-keyword">end</span>
|
524
|
+
|
525
|
+
<span class="ruby-ivar">@stream</span>.<span class="ruby-identifier">userstream</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">status</span><span class="ruby-operator">|</span>
|
526
|
+
<span class="ruby-identifier">handle_tweet</span>(<span class="ruby-identifier">status</span>)
|
527
|
+
<span class="ruby-keyword">end</span>
|
528
|
+
|
529
|
+
<span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">"Twitter client is online at @#{@username} :3"</span>)
|
530
|
+
<span class="ruby-keyword">end</span></pre>
|
531
|
+
</div><!-- run-source -->
|
532
|
+
|
533
|
+
</div>
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
|
538
|
+
</div><!-- run-method -->
|
539
|
+
|
540
|
+
|
541
|
+
<div id="method-i-send" class="method-detail ">
|
542
|
+
|
543
|
+
<div class="method-heading">
|
544
|
+
<span class="method-name">send</span><span
|
545
|
+
class="method-args">(resp)</span>
|
546
|
+
<span class="method-click-advice">click to toggle source</span>
|
547
|
+
</div>
|
548
|
+
|
549
|
+
|
550
|
+
<div class="method-description">
|
551
|
+
|
552
|
+
<p>Sends a Twitter-sourced <a href="../Response.html">Response</a> to the
|
553
|
+
appropriate target.</p>
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
<div class="method-source-code" id="send-source">
|
558
|
+
<pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 157</span>
|
559
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">resp</span>)
|
560
|
+
<span class="ruby-identifier">source</span> = <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">source</span>
|
561
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">DirectMessage</span>)
|
562
|
+
<span class="ruby-ivar">@client</span>.<span class="ruby-identifier">direct_message_create</span>(<span class="ruby-identifier">source</span>.<span class="ruby-identifier">raw</span>[<span class="ruby-string">'sender'</span>][<span class="ruby-string">'screen_name'</span>], <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">text</span>)
|
563
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Tweet</span>)
|
564
|
+
<span class="ruby-identifier">reply</span>(<span class="ruby-node">"#{source.header_mentions.join(' ')} #{resp.text}"</span>)
|
565
|
+
<span class="ruby-keyword">else</span>
|
566
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>, <span class="ruby-node">"Don't know how to send response to a #{req.source.class}!"</span>
|
567
|
+
<span class="ruby-keyword">end</span>
|
568
|
+
<span class="ruby-keyword">end</span></pre>
|
569
|
+
</div><!-- send-source -->
|
570
|
+
|
571
|
+
</div>
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
|
576
|
+
</div><!-- send-method -->
|
577
|
+
|
578
|
+
|
579
|
+
</section><!-- public-instance-method-details -->
|
580
|
+
|
581
|
+
</section><!-- 5Buntitled-5D -->
|
582
|
+
|
583
|
+
</div><!-- documentation -->
|
584
|
+
|
585
|
+
|
586
|
+
<footer id="validator-badges">
|
587
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
588
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
|
589
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
590
|
+
</footer>
|
591
|
+
|