safubot 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardoc/checksums +5 -5
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/README.md +9 -9
- data/doc/Safubot/Bot.html +334 -218
- data/doc/Safubot/Evented.html +1 -1
- data/doc/Safubot/KnownUser.html +1 -1
- data/doc/Safubot/Log.html +1 -1
- data/doc/Safubot/Problem.html +130 -0
- data/doc/Safubot/Problematic.html +282 -0
- data/doc/Safubot/Query.html +50 -1
- data/doc/Safubot/Request.html +19 -2
- data/doc/Safubot/Response.html +19 -2
- data/doc/Safubot/Test.html +1 -1
- data/doc/Safubot/Twitter/Bot.html +248 -135
- data/doc/Safubot/Twitter/DirectMessage.html +22 -22
- data/doc/Safubot/Twitter/Tweet.html +40 -40
- data/doc/Safubot/Twitter.html +1 -1
- data/doc/Safubot/XMPP/Bot.html +47 -31
- data/doc/Safubot/XMPP/Message.html +1 -1
- data/doc/Safubot/XMPP.html +1 -1
- data/doc/Safubot.html +4 -4
- data/doc/_index.html +26 -4
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +11 -10
- data/doc/index.html +11 -10
- data/doc/method_list.html +103 -79
- data/doc/top-level-namespace.html +1 -1
- data/lib/safubot/bot.rb +100 -26
- data/lib/safubot/test_helper.rb +4 -0
- data/lib/safubot/twitter.rb +6 -7
- data/lib/safubot/version.rb +1 -1
- data/lib/safubot/xmpp.rb +9 -3
- data/safubot.gemspec +1 -0
- metadata +119 -113
@@ -384,8 +384,7 @@ Initializes the TweetStream client.
|
|
384
384
|
|
385
385
|
|
386
386
|
<span class="summary_desc"><div class='inline'><p>
|
387
|
-
|
388
|
-
:username is ours and important.
|
387
|
+
::Twitter, but the :username is ours and important.
|
389
388
|
</p>
|
390
389
|
</div></span>
|
391
390
|
|
@@ -586,15 +585,37 @@ Shut down the TweetStream client.
|
|
586
585
|
</p><div class="docstring">
|
587
586
|
<div class="discussion">
|
588
587
|
<p>
|
589
|
-
|
590
|
-
:username is ours and important.
|
588
|
+
::Twitter, but the :username is ours and important.
|
591
589
|
</p>
|
592
590
|
|
593
591
|
|
594
592
|
</div>
|
595
593
|
</div>
|
596
594
|
<div class="tags">
|
595
|
+
<h3>Parameters:</h3>
|
596
|
+
<ul class="param">
|
597
|
+
|
598
|
+
<li>
|
599
|
+
|
600
|
+
<span class='name'>options</span>
|
601
|
+
|
602
|
+
|
603
|
+
<span class='type'></span>
|
604
|
+
|
605
|
+
|
606
|
+
<em class="default">(defaults to: <tt>{}</tt>)</em>
|
607
|
+
|
608
|
+
|
609
|
+
—
|
610
|
+
<div class='inline'><p>
|
611
|
+
These are passed straight through to ::TweetStream and
|
612
|
+
</p>
|
613
|
+
</div>
|
614
|
+
|
615
|
+
</li>
|
597
616
|
|
617
|
+
</ul>
|
618
|
+
|
598
619
|
|
599
620
|
</div><table class="source_code">
|
600
621
|
<tr>
|
@@ -602,21 +623,21 @@ Options are passed straight through to ::TweetStream and ::Twitter, but the
|
|
602
623
|
<pre class="lines">
|
603
624
|
|
604
625
|
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
626
|
+
299
|
627
|
+
300
|
628
|
+
301
|
629
|
+
302
|
630
|
+
303
|
631
|
+
304
|
632
|
+
305
|
633
|
+
306
|
634
|
+
307
|
635
|
+
308
|
636
|
+
309
|
637
|
+
310</pre>
|
617
638
|
</td>
|
618
639
|
<td>
|
619
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
640
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 299</span>
|
620
641
|
|
621
642
|
<span class='kw'>def</span> <span class='id initialize'>initialize</span><span class='lparen'>(</span><span class='id options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
|
622
643
|
<span class='id defaults'>defaults</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='symbol'>:username</span> <span class='op'>=></span> <span class='kw'>nil</span><span class='comma'>,</span>
|
@@ -668,12 +689,12 @@ Returns the value of attribute client
|
|
668
689
|
<pre class="lines">
|
669
690
|
|
670
691
|
|
671
|
-
|
672
|
-
|
673
|
-
|
692
|
+
163
|
693
|
+
164
|
694
|
+
165</pre>
|
674
695
|
</td>
|
675
696
|
<td>
|
676
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
697
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 163</span>
|
677
698
|
|
678
699
|
<span class='kw'>def</span> <span class='id client'>client</span>
|
679
700
|
<span class='ivar'>@client</span>
|
@@ -711,12 +732,12 @@ Returns the value of attribute opts
|
|
711
732
|
<pre class="lines">
|
712
733
|
|
713
734
|
|
714
|
-
|
715
|
-
|
716
|
-
|
735
|
+
163
|
736
|
+
164
|
737
|
+
165</pre>
|
717
738
|
</td>
|
718
739
|
<td>
|
719
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
740
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 163</span>
|
720
741
|
|
721
742
|
<span class='kw'>def</span> <span class='id opts'>opts</span>
|
722
743
|
<span class='ivar'>@opts</span>
|
@@ -754,12 +775,12 @@ Returns the value of attribute pid
|
|
754
775
|
<pre class="lines">
|
755
776
|
|
756
777
|
|
757
|
-
|
758
|
-
|
759
|
-
|
778
|
+
163
|
779
|
+
164
|
780
|
+
165</pre>
|
760
781
|
</td>
|
761
782
|
<td>
|
762
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
783
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 163</span>
|
763
784
|
|
764
785
|
<span class='kw'>def</span> <span class='id pid'>pid</span>
|
765
786
|
<span class='ivar'>@pid</span>
|
@@ -797,12 +818,12 @@ Returns the value of attribute stream
|
|
797
818
|
<pre class="lines">
|
798
819
|
|
799
820
|
|
800
|
-
|
801
|
-
|
802
|
-
|
821
|
+
163
|
822
|
+
164
|
823
|
+
165</pre>
|
803
824
|
</td>
|
804
825
|
<td>
|
805
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
826
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 163</span>
|
806
827
|
|
807
828
|
<span class='kw'>def</span> <span class='id stream'>stream</span>
|
808
829
|
<span class='ivar'>@stream</span>
|
@@ -840,12 +861,12 @@ Returns the value of attribute username
|
|
840
861
|
<pre class="lines">
|
841
862
|
|
842
863
|
|
843
|
-
|
844
|
-
|
845
|
-
|
864
|
+
163
|
865
|
+
164
|
866
|
+
165</pre>
|
846
867
|
</td>
|
847
868
|
<td>
|
848
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
869
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 163</span>
|
849
870
|
|
850
871
|
<span class='kw'>def</span> <span class='id username'>username</span>
|
851
872
|
<span class='ivar'>@username</span>
|
@@ -879,7 +900,28 @@ Stores a DM and creates a matching Request as needed.
|
|
879
900
|
</div>
|
880
901
|
</div>
|
881
902
|
<div class="tags">
|
903
|
+
<h3>Parameters:</h3>
|
904
|
+
<ul class="param">
|
905
|
+
|
906
|
+
<li>
|
907
|
+
|
908
|
+
<span class='name'>message</span>
|
909
|
+
|
910
|
+
|
911
|
+
<span class='type'></span>
|
912
|
+
|
913
|
+
|
914
|
+
|
915
|
+
—
|
916
|
+
<div class='inline'><p>
|
917
|
+
A raw JSON-derived direct message.
|
918
|
+
</p>
|
919
|
+
</div>
|
920
|
+
|
921
|
+
</li>
|
882
922
|
|
923
|
+
</ul>
|
924
|
+
|
883
925
|
|
884
926
|
</div><table class="source_code">
|
885
927
|
<tr>
|
@@ -887,17 +929,17 @@ Stores a DM and creates a matching Request as needed.
|
|
887
929
|
<pre class="lines">
|
888
930
|
|
889
931
|
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
932
|
+
189
|
933
|
+
190
|
934
|
+
191
|
935
|
+
192</pre>
|
894
936
|
</td>
|
895
937
|
<td>
|
896
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
938
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 189</span>
|
897
939
|
|
898
940
|
<span class='kw'>def</span> <span class='id handle_message'>handle_message</span><span class='lparen'>(</span><span class='id message'>message</span><span class='rparen'>)</span>
|
899
941
|
<span class='kw'>return</span> <span class='kw'>if</span> <span class='id message'>message</span><span class='period'>.</span><span class='id sender'>sender</span><span class='period'>.</span><span class='id screen_name'>screen_name</span> <span class='op'>==</span> <span class='ivar'>@username</span>
|
900
|
-
<span class='const'>DirectMessage</span><span class='period'>.</span><span class='id from'>from</span><span class='lparen'>(</span><span class='id message'>message</span><span class='rparen'>)</span><span class='period'>.</span><span class='id make_request'>make_request</span>
|
942
|
+
<span class='id handle_request'>handle_request</span><span class='lparen'>(</span><span class='const'>DirectMessage</span><span class='period'>.</span><span class='id from'>from</span><span class='lparen'>(</span><span class='id message'>message</span><span class='rparen'>)</span><span class='period'>.</span><span class='id make_request'>make_request</span><span class='rparen'>)</span>
|
901
943
|
<span class='kw'>end</span></pre>
|
902
944
|
</td>
|
903
945
|
</tr>
|
@@ -921,7 +963,28 @@ Emit a request event unless the request is already processed.
|
|
921
963
|
</div>
|
922
964
|
</div>
|
923
965
|
<div class="tags">
|
966
|
+
<h3>Parameters:</h3>
|
967
|
+
<ul class="param">
|
968
|
+
|
969
|
+
<li>
|
970
|
+
|
971
|
+
<span class='name'>req</span>
|
972
|
+
|
973
|
+
|
974
|
+
<span class='type'></span>
|
975
|
+
|
976
|
+
|
977
|
+
|
978
|
+
—
|
979
|
+
<div class='inline'><p>
|
980
|
+
Request to handle.
|
981
|
+
</p>
|
982
|
+
</div>
|
983
|
+
|
984
|
+
</li>
|
924
985
|
|
986
|
+
</ul>
|
987
|
+
|
925
988
|
|
926
989
|
</div><table class="source_code">
|
927
990
|
<tr>
|
@@ -929,12 +992,12 @@ Emit a request event unless the request is already processed.
|
|
929
992
|
<pre class="lines">
|
930
993
|
|
931
994
|
|
932
|
-
|
933
|
-
|
934
|
-
|
995
|
+
182
|
996
|
+
183
|
997
|
+
184</pre>
|
935
998
|
</td>
|
936
999
|
<td>
|
937
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1000
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 182</span>
|
938
1001
|
|
939
1002
|
<span class='kw'>def</span> <span class='id handle_request'>handle_request</span><span class='lparen'>(</span><span class='id req'>req</span><span class='rparen'>)</span>
|
940
1003
|
<span class='id emit'>emit</span><span class='lparen'>(</span><span class='symbol'>:request</span><span class='comma'>,</span> <span class='id req'>req</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id req'>req</span><span class='period'>.</span><span class='id nil?'>nil?</span> <span class='op'>||</span> <span class='id req'>req</span><span class='period'>.</span><span class='id processed'>processed</span>
|
@@ -962,7 +1025,28 @@ Otherwise, emit a :timeline event.
|
|
962
1025
|
</div>
|
963
1026
|
</div>
|
964
1027
|
<div class="tags">
|
1028
|
+
<h3>Parameters:</h3>
|
1029
|
+
<ul class="param">
|
1030
|
+
|
1031
|
+
<li>
|
1032
|
+
|
1033
|
+
<span class='name'>status</span>
|
1034
|
+
|
1035
|
+
|
1036
|
+
<span class='type'></span>
|
1037
|
+
|
1038
|
+
|
1039
|
+
|
1040
|
+
—
|
1041
|
+
<div class='inline'><p>
|
1042
|
+
A raw JSON-derived tweet.
|
1043
|
+
</p>
|
1044
|
+
</div>
|
1045
|
+
|
1046
|
+
</li>
|
965
1047
|
|
1048
|
+
</ul>
|
1049
|
+
|
966
1050
|
|
967
1051
|
</div><table class="source_code">
|
968
1052
|
<tr>
|
@@ -970,22 +1054,22 @@ Otherwise, emit a :timeline event.
|
|
970
1054
|
<pre class="lines">
|
971
1055
|
|
972
1056
|
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
1057
|
+
198
|
1058
|
+
199
|
1059
|
+
200
|
1060
|
+
201
|
1061
|
+
202
|
1062
|
+
203
|
1063
|
+
204
|
1064
|
+
205</pre>
|
981
1065
|
</td>
|
982
1066
|
<td>
|
983
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1067
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 198</span>
|
984
1068
|
|
985
1069
|
<span class='kw'>def</span> <span class='id handle_tweet'>handle_tweet</span><span class='lparen'>(</span><span class='id status'>status</span><span class='rparen'>)</span>
|
986
1070
|
<span class='kw'>return</span> <span class='kw'>if</span> <span class='id status'>status</span><span class='period'>.</span><span class='id user'>user</span><span class='period'>.</span><span class='id screen_name'>screen_name</span> <span class='op'>==</span> <span class='ivar'>@username</span>
|
987
1071
|
<span class='kw'>if</span> <span class='id status'>status</span><span class='period'>.</span><span class='id text'>text</span><span class='period'>.</span><span class='id match'>match</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>@</span><span class='embexpr_beg'>#{</span><span class='ivar'>@username</span><span class='rbrace'>}</span><span class='regexp_end'>/i</span></span><span class='rparen'>)</span>
|
988
|
-
<span class='const'>Tweet</span><span class='period'>.</span><span class='id from'>from</span><span class='lparen'>(</span><span class='id status'>status</span><span class='rparen'>)</span><span class='period'>.</span><span class='id make_request'>make_request</span>
|
1072
|
+
<span class='id handle_request'>handle_request</span><span class='lparen'>(</span><span class='const'>Tweet</span><span class='period'>.</span><span class='id from'>from</span><span class='lparen'>(</span><span class='id status'>status</span><span class='rparen'>)</span><span class='period'>.</span><span class='id make_request'>make_request</span><span class='rparen'>)</span>
|
989
1073
|
<span class='kw'>else</span>
|
990
1074
|
<span class='id emit'>emit</span><span class='lparen'>(</span><span class='symbol'>:timeline</span><span class='comma'>,</span> <span class='const'>Tweet</span><span class='period'>.</span><span class='id from'>from</span><span class='lparen'>(</span><span class='id status'>status</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
991
1075
|
<span class='kw'>end</span>
|
@@ -1020,17 +1104,6 @@ Initializes the TweetStream client.
|
|
1020
1104
|
<pre class="lines">
|
1021
1105
|
|
1022
1106
|
|
1023
|
-
227
|
1024
|
-
228
|
1025
|
-
229
|
1026
|
-
230
|
1027
|
-
231
|
1028
|
-
232
|
1029
|
-
233
|
1030
|
-
234
|
1031
|
-
235
|
1032
|
-
236
|
1033
|
-
237
|
1034
1107
|
238
|
1035
1108
|
239
|
1036
1109
|
240
|
@@ -1039,17 +1112,27 @@ Initializes the TweetStream client.
|
|
1039
1112
|
243
|
1040
1113
|
244
|
1041
1114
|
245
|
1042
|
-
246
|
1115
|
+
246
|
1116
|
+
247
|
1117
|
+
248
|
1118
|
+
249
|
1119
|
+
250
|
1120
|
+
251
|
1121
|
+
252
|
1122
|
+
253
|
1123
|
+
254
|
1124
|
+
255
|
1125
|
+
256
|
1126
|
+
257</pre>
|
1043
1127
|
</td>
|
1044
1128
|
<td>
|
1045
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1129
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 238</span>
|
1046
1130
|
|
1047
1131
|
<span class='kw'>def</span> <span class='id init_stream'>init_stream</span>
|
1048
1132
|
<span class='ivar'>@stream</span> <span class='op'>=</span> <span class='const'>TweetStream</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id new'>new</span><span class='lparen'>(</span><span class='ivar'>@opts</span><span class='rparen'>)</span>
|
1049
1133
|
|
1050
1134
|
<span class='ivar'>@stream</span><span class='period'>.</span><span class='id on_direct_message'>on_direct_message</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id message'>message</span><span class='op'>|</span>
|
1051
|
-
<span class='id
|
1052
|
-
<span class='id handle_request'>handle_request</span><span class='lparen'>(</span><span class='id req'>req</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id req'>req</span><span class='period'>.</span><span class='id is_a?'>is_a?</span> <span class='const'>Request</span>
|
1135
|
+
<span class='id handle_message'>handle_message</span><span class='lparen'>(</span><span class='id message'>message</span><span class='rparen'>)</span>
|
1053
1136
|
<span class='kw'>end</span>
|
1054
1137
|
|
1055
1138
|
<span class='ivar'>@stream</span><span class='period'>.</span><span class='id on_error'>on_error</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id err'>err</span><span class='op'>|</span>
|
@@ -1062,6 +1145,7 @@ Initializes the TweetStream client.
|
|
1062
1145
|
|
1063
1146
|
<span class='ivar'>@stream</span><span class='period'>.</span><span class='id on_inited'>on_inited</span> <span class='kw'>do</span>
|
1064
1147
|
<span class='const'>Log</span><span class='period'>.</span><span class='id info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>TweetStream client is online at @</span><span class='embexpr_beg'>#{</span><span class='ivar'>@username</span><span class='rbrace'>}</span><span class='tstring_content'> :3</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1148
|
+
<span class='id emit'>emit</span><span class='lparen'>(</span><span class='symbol'>:ready</span><span class='rparen'>)</span>
|
1065
1149
|
<span class='kw'>end</span>
|
1066
1150
|
<span class='kw'>end</span></pre>
|
1067
1151
|
</td>
|
@@ -1096,24 +1180,24 @@ offline.
|
|
1096
1180
|
<pre class="lines">
|
1097
1181
|
|
1098
1182
|
|
1099
|
-
210
|
1100
|
-
211
|
1101
|
-
212
|
1102
|
-
213
|
1103
|
-
214
|
1104
|
-
215
|
1105
|
-
216
|
1106
|
-
217
|
1107
|
-
218
|
1108
|
-
219
|
1109
|
-
220
|
1110
1183
|
221
|
1111
1184
|
222
|
1112
1185
|
223
|
1113
|
-
224
|
1186
|
+
224
|
1187
|
+
225
|
1188
|
+
226
|
1189
|
+
227
|
1190
|
+
228
|
1191
|
+
229
|
1192
|
+
230
|
1193
|
+
231
|
1194
|
+
232
|
1195
|
+
233
|
1196
|
+
234
|
1197
|
+
235</pre>
|
1114
1198
|
</td>
|
1115
1199
|
<td>
|
1116
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1200
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 221</span>
|
1117
1201
|
|
1118
1202
|
<span class='kw'>def</span> <span class='id pull'>pull</span>
|
1119
1203
|
<span class='kw'>begin</span>
|
@@ -1198,12 +1282,12 @@ The response text.
|
|
1198
1282
|
<pre class="lines">
|
1199
1283
|
|
1200
1284
|
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1285
|
+
215
|
1286
|
+
216
|
1287
|
+
217</pre>
|
1204
1288
|
</td>
|
1205
1289
|
<td>
|
1206
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1290
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 215</span>
|
1207
1291
|
|
1208
1292
|
<span class='kw'>def</span> <span class='id reply'>reply</span><span class='lparen'>(</span><span class='id tweet'>tweet</span><span class='comma'>,</span> <span class='id text'>text</span><span class='rparen'>)</span>
|
1209
1293
|
<span class='ivar'>@client</span><span class='period'>.</span><span class='id update'>update</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id reply_header'>reply_header</span><span class='lparen'>(</span><span class='id tweet'>tweet</span><span class='rparen'>)</span><span class='rbrace'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id text'>text</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='symbol'>:in_reply_to_status_id</span> <span class='op'>=></span> <span class='id tweet'>tweet</span><span class='period'>.</span><span class='id raw'>raw</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>id</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
@@ -1238,12 +1322,12 @@ Constructs the appropriate series of mentions for a reply to this tweet.
|
|
1238
1322
|
<pre class="lines">
|
1239
1323
|
|
1240
1324
|
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1325
|
+
208
|
1326
|
+
209
|
1327
|
+
210</pre>
|
1244
1328
|
</td>
|
1245
1329
|
<td>
|
1246
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1330
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 208</span>
|
1247
1331
|
|
1248
1332
|
<span class='kw'>def</span> <span class='id reply_header'>reply_header</span><span class='lparen'>(</span><span class='id tweet'>tweet</span><span class='rparen'>)</span>
|
1249
1333
|
<span class='lparen'>(</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>@</span><span class='embexpr_beg'>#{</span><span class='id tweet'>tweet</span><span class='period'>.</span><span class='id username'>username</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='op'>+</span> <span class='lparen'>(</span><span class='id tweet'>tweet</span><span class='period'>.</span><span class='id header_mentions'>header_mentions</span> <span class='op'>-</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>@</span><span class='embexpr_beg'>#{</span><span class='ivar'>@username</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id join'>join</span>
|
@@ -1278,16 +1362,16 @@ Starts our TweetStream client running in a new process.
|
|
1278
1362
|
<pre class="lines">
|
1279
1363
|
|
1280
1364
|
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1365
|
+
277
|
1366
|
+
278
|
1367
|
+
279
|
1368
|
+
280
|
1369
|
+
281
|
1370
|
+
282
|
1371
|
+
283</pre>
|
1288
1372
|
</td>
|
1289
1373
|
<td>
|
1290
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1374
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 277</span>
|
1291
1375
|
|
1292
1376
|
<span class='kw'>def</span> <span class='id run'>run</span>
|
1293
1377
|
<span class='ivar'>@pid</span> <span class='op'>=</span> <span class='const'>Process</span><span class='period'>.</span><span class='id fork'>fork</span> <span class='kw'>do</span>
|
@@ -1326,40 +1410,38 @@ Runs the TweetStream client.
|
|
1326
1410
|
<pre class="lines">
|
1327
1411
|
|
1328
1412
|
|
1329
|
-
249
|
1330
|
-
250
|
1331
|
-
251
|
1332
|
-
252
|
1333
|
-
253
|
1334
|
-
254
|
1335
|
-
255
|
1336
|
-
256
|
1337
|
-
257
|
1338
|
-
258
|
1339
|
-
259
|
1340
1413
|
260
|
1341
1414
|
261
|
1342
1415
|
262
|
1343
1416
|
263
|
1344
|
-
264
|
1417
|
+
264
|
1418
|
+
265
|
1419
|
+
266
|
1420
|
+
267
|
1421
|
+
268
|
1422
|
+
269
|
1423
|
+
270
|
1424
|
+
271
|
1425
|
+
272
|
1426
|
+
273
|
1427
|
+
274</pre>
|
1345
1428
|
</td>
|
1346
1429
|
<td>
|
1347
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1430
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 260</span>
|
1348
1431
|
|
1349
1432
|
<span class='kw'>def</span> <span class='id run_stream'>run_stream</span>
|
1350
1433
|
<span class='kw'>begin</span>
|
1351
1434
|
<span class='ivar'>@stream</span><span class='period'>.</span><span class='id userstream'>userstream</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id status'>status</span><span class='op'>|</span>
|
1352
|
-
<span class='id
|
1353
|
-
<span class='id handle_request'>handle_request</span><span class='lparen'>(</span><span class='id req'>req</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id req'>req</span><span class='period'>.</span><span class='id is_a?'>is_a?</span> <span class='const'>Request</span>
|
1435
|
+
<span class='id handle_tweet'>handle_tweet</span><span class='lparen'>(</span><span class='id status'>status</span><span class='rparen'>)</span>
|
1354
1436
|
<span class='kw'>end</span>
|
1355
1437
|
<span class='kw'>rescue</span> <span class='const'>Exception</span> <span class='op'>=></span> <span class='id e'>e</span>
|
1356
|
-
<span class='kw'>
|
1438
|
+
<span class='kw'>if</span> <span class='id e'>e</span><span class='period'>.</span><span class='id is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Interrupt</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id e'>e</span><span class='period'>.</span><span class='id is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>SignalException</span><span class='rparen'>)</span>
|
1439
|
+
<span class='id stop'>stop</span>
|
1440
|
+
<span class='kw'>else</span>
|
1357
1441
|
<span class='const'>Log</span><span class='period'>.</span><span class='id error'>error</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>TweetStream client exited unexpectedly: </span><span class='embexpr_beg'>#{</span><span class='id error_report'>error_report</span><span class='lparen'>(</span><span class='id e'>e</span><span class='rparen'>)</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span>
|
1358
1442
|
<span class='const'>Log</span><span class='period'>.</span><span class='id error'>error</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Restarting TweetStream client in 5 seconds.</span><span class='tstring_end'>"</span></span>
|
1359
1443
|
<span class='id sleep'>sleep</span> <span class='int'>5</span><span class='semicolon'>;</span> <span class='id init_stream'>init_stream</span><span class='semicolon'>;</span> <span class='id run_stream'>run_stream</span>
|
1360
1444
|
<span class='kw'>end</span>
|
1361
|
-
<span class='kw'>else</span>
|
1362
|
-
<span class='const'>Log</span><span class='period'>.</span><span class='id info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>TweetStream client shutdown complete.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1363
1445
|
<span class='kw'>end</span>
|
1364
1446
|
<span class='kw'>end</span></pre>
|
1365
1447
|
</td>
|
@@ -1384,7 +1466,28 @@ Sends a Twitter-sourced Response to the appropriate target.
|
|
1384
1466
|
</div>
|
1385
1467
|
</div>
|
1386
1468
|
<div class="tags">
|
1469
|
+
<h3>Parameters:</h3>
|
1470
|
+
<ul class="param">
|
1471
|
+
|
1472
|
+
<li>
|
1473
|
+
|
1474
|
+
<span class='name'>resp</span>
|
1475
|
+
|
1476
|
+
|
1477
|
+
<span class='type'></span>
|
1478
|
+
|
1479
|
+
|
1480
|
+
|
1481
|
+
—
|
1482
|
+
<div class='inline'><p>
|
1483
|
+
Response to send.
|
1484
|
+
</p>
|
1485
|
+
</div>
|
1486
|
+
|
1487
|
+
</li>
|
1387
1488
|
|
1489
|
+
</ul>
|
1490
|
+
|
1388
1491
|
|
1389
1492
|
</div><table class="source_code">
|
1390
1493
|
<tr>
|
@@ -1392,26 +1495,26 @@ Sends a Twitter-sourced Response to the appropriate target.
|
|
1392
1495
|
<pre class="lines">
|
1393
1496
|
|
1394
1497
|
|
1395
|
-
163
|
1396
|
-
164
|
1397
|
-
165
|
1398
|
-
166
|
1399
|
-
167
|
1400
1498
|
168
|
1401
1499
|
169
|
1402
1500
|
170
|
1403
1501
|
171
|
1404
|
-
172
|
1502
|
+
172
|
1503
|
+
173
|
1504
|
+
174
|
1505
|
+
175
|
1506
|
+
176
|
1507
|
+
177</pre>
|
1405
1508
|
</td>
|
1406
1509
|
<td>
|
1407
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1510
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 168</span>
|
1408
1511
|
|
1409
1512
|
<span class='kw'>def</span> <span class='id send'>send</span><span class='lparen'>(</span><span class='id resp'>resp</span><span class='rparen'>)</span>
|
1410
1513
|
<span class='id source'>source</span> <span class='op'>=</span> <span class='id resp'>resp</span><span class='period'>.</span><span class='id request'>request</span><span class='period'>.</span><span class='id source'>source</span>
|
1411
1514
|
<span class='kw'>if</span> <span class='id source'>source</span><span class='period'>.</span><span class='id is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>DirectMessage</span><span class='rparen'>)</span>
|
1412
1515
|
<span class='ivar'>@client</span><span class='period'>.</span><span class='id direct_message_create'>direct_message_create</span><span class='lparen'>(</span><span class='id source'>source</span><span class='period'>.</span><span class='id raw'>raw</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>sender</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>screen_name</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id resp'>resp</span><span class='period'>.</span><span class='id text'>text</span><span class='rparen'>)</span>
|
1413
1516
|
<span class='kw'>elsif</span> <span class='id source'>source</span><span class='period'>.</span><span class='id is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Tweet</span><span class='rparen'>)</span>
|
1414
|
-
<span class='id reply'>reply</span
|
1517
|
+
<span class='id reply'>reply</span> <span class='id source'>source</span><span class='comma'>,</span> <span class='id resp'>resp</span><span class='period'>.</span><span class='id text'>text</span>
|
1415
1518
|
<span class='kw'>else</span>
|
1416
1519
|
<span class='id raise'>raise</span> <span class='const'>NotImplementedError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Don't know how to send response to a </span><span class='embexpr_beg'>#{</span><span class='id req'>req</span><span class='period'>.</span><span class='id source'>source</span><span class='period'>.</span><span class='id class'>class</span><span class='rbrace'>}</span><span class='tstring_content'>!</span><span class='tstring_end'>"</span></span>
|
1417
1520
|
<span class='kw'>end</span>
|
@@ -1446,17 +1549,27 @@ Shut down the TweetStream client.
|
|
1446
1549
|
<pre class="lines">
|
1447
1550
|
|
1448
1551
|
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1552
|
+
286
|
1553
|
+
287
|
1554
|
+
288
|
1555
|
+
289
|
1556
|
+
290
|
1557
|
+
291
|
1558
|
+
292
|
1559
|
+
293
|
1560
|
+
294</pre>
|
1453
1561
|
</td>
|
1454
1562
|
<td>
|
1455
|
-
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line
|
1563
|
+
<pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 286</span>
|
1456
1564
|
|
1457
1565
|
<span class='kw'>def</span> <span class='id stop'>stop</span>
|
1458
|
-
<span class='
|
1459
|
-
|
1566
|
+
<span class='kw'>if</span> <span class='ivar'>@stream</span>
|
1567
|
+
<span class='ivar'>@stream</span><span class='period'>.</span><span class='id stop'>stop</span>
|
1568
|
+
<span class='ivar'>@stream</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
1569
|
+
<span class='const'>Log</span><span class='period'>.</span><span class='id info'>info</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>TweetStream client shutdown complete.</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
1570
|
+
<span class='kw'>else</span>
|
1571
|
+
<span class='const'>Process</span><span class='period'>.</span><span class='id kill'>kill</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>TERM</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='ivar'>@pid</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@pid</span>
|
1572
|
+
<span class='kw'>end</span>
|
1460
1573
|
<span class='kw'>end</span></pre>
|
1461
1574
|
</td>
|
1462
1575
|
</tr>
|
@@ -1468,7 +1581,7 @@ Shut down the TweetStream client.
|
|
1468
1581
|
</div>
|
1469
1582
|
|
1470
1583
|
<div id="footer">
|
1471
|
-
Generated on
|
1584
|
+
Generated on Thu Dec 1 18:19:17 2011 by
|
1472
1585
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1473
1586
|
0.7.3 (ruby-1.9.2).
|
1474
1587
|
</div>
|