doc/Safubot/Twitter/Bot.html in safubot-0.0.1 vs doc/Safubot/Twitter/Bot.html in safubot-0.0.2

- old
+ new

@@ -1,591 +1,1141 @@ -<!DOCTYPE html> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title> + Class: Safubot::Twitter::Bot + + &mdash; Documentation by YARD 0.7.3 + +</title> -<html> -<head> -<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> + <link rel="stylesheet" href="../../css/style.css" type="text/css" media="screen" charset="utf-8" /> -<title>Class: Safubot::Twitter::Bot</title> + <link rel="stylesheet" href="../../css/common.css" type="text/css" media="screen" charset="utf-8" /> -<link type="text/css" media="screen" href="../../rdoc.css" rel="stylesheet"> - -<script type="text/javascript"> - var rdoc_rel_prefix = "../../"; +<script type="text/javascript" charset="utf-8"> + relpath = '../..'; + if (relpath != '') relpath += '/'; </script> -<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script> -<script type="text/javascript" charset="utf-8" src="../../js/navigation.js"></script> -<script type="text/javascript" charset="utf-8" src="../../js/search_index.js"></script> -<script type="text/javascript" charset="utf-8" src="../../js/search.js"></script> -<script type="text/javascript" charset="utf-8" src="../../js/searcher.js"></script> -<script type="text/javascript" charset="utf-8" src="../../js/darkfish.js"></script> + <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script> + <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script> -<body id="top" class="class"> -<nav id="metadata"> - <nav id="home-section" class="section"> - <h3 class="section-header"> - <a href="../../index.html">Home</a> - <a href="../../table_of_contents.html#classes">Classes</a> - <a href="../../table_of_contents.html#methods">Methods</a> - </h3> -</nav> + </head> + <body> + <script type="text/javascript" charset="utf-8"> + if (window.top.frames.main) document.body.className = 'frames'; + </script> + + <div id="header"> + <div id="menu"> + + <a href="../../_index.html">Index (B)</a> &raquo; + <span class='title'><span class='object_link'><a href="../../Safubot.html" title="Safubot (module)">Safubot</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Twitter.html" title="Safubot::Twitter (module)">Twitter</a></span></span> + &raquo; + <span class="title">Bot</span> + + + <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div> +</div> - <nav id="search-section" class="section project-section" class="initially-hidden"> - <form action="#" method="get" accept-charset="utf-8"> - <h3 class="section-header"> - <input type="text" name="search" placeholder="Search" id="search-field" - title="Type to search, Up and Down to navigate, Enter to load"> - </h3> - </form> + <div id="search"> + + <a id="class_list_link" href="#">Class List</a> + + <a id="method_list_link" href="#">Method List</a> + + <a id="file_list_link" href="#">File List</a> + +</div> + <div class="clear"></div> + </div> + + <iframe id="search_frame"></iframe> + + <div id="content"><h1>Class: Safubot::Twitter::Bot + + + +</h1> - <ul id="search-results" class="initially-hidden"></ul> -</nav> +<dl class="box"> + + <dt class="r1">Inherits:</dt> + <dd class="r1"> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">Safubot::Twitter::Bot</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + + + + + + + <dt class="r2">Includes:</dt> + <dd class="r2"><span class='object_link'><a href="../Evented.html" title="Safubot::Evented (module)">Evented</a></span></dd> + + + + + + <dt class="r1 last">Defined in:</dt> + <dd class="r1 last">lib/safubot/twitter.rb</dd> + +</dl> +<div class="clear"></div> +<h2>Overview</h2><div class="docstring"> + <div class="discussion"> + <p> +A Twitter::Bot instance provides a Safubot::Bot with Twitter-specific +processing. +</p> - <div id="file-metadata"> - <nav id="file-list-section" class="section"> - <h3 class="section-header">Defined In</h3> - <ul> - <li>lib/safubot/twitter.rb - </ul> -</nav> - </div> +</div> +<div class="tags"> + - <div id="class-metadata"> - - <nav id="parent-class-section" class="section"> - <h3 class="section-header">Parent</h3> +</div> + - <p class="link"><a href="../../Object.html">Object</a> -</nav> + + + <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2> + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#client-instance_method" title="#client (instance method)">- (Object) <strong>client</strong> </a> + - <!-- Included Modules --> -<nav id="includes-section" class="section"> - <h3 class="section-header">Included Modules</h3> - - <ul class="link-list"> + + </span> - <li><a class="include" href="../Evented.html">Safubot::Evented</a> + <span class="note title readonly">readonly</span> + - </ul> -</nav> + + + - <!-- Method Quickref --> -<nav id="method-list-section" class="section"> - <h3 class="section-header">Methods</h3> + + <span class="summary_desc"><div class='inline'><p> +Returns the value of attribute client. +</p> +</div></span> + +</li> - <ul class="link-list"> - <li><a href="#method-c-new">::new</a> + <li class="public "> + <span class="summary_signature"> - <li><a href="#method-i-handle_message">#handle_message</a> + <a href="#opts-instance_method" title="#opts (instance method)">- (Object) <strong>opts</strong> </a> - <li><a href="#method-i-handle_request">#handle_request</a> + - <li><a href="#method-i-handle_tweet">#handle_tweet</a> + </span> + + + <span class="note title readonly">readonly</span> - <li><a href="#method-i-pull">#pull</a> + + + + + + + + <span class="summary_desc"><div class='inline'><p> +Returns the value of attribute opts. +</p> +</div></span> + +</li> + - <li><a href="#method-i-reply">#reply</a> + <li class="public "> + <span class="summary_signature"> - <li><a href="#method-i-reply_header">#reply_header</a> + <a href="#username-instance_method" title="#username (instance method)">- (Object) <strong>username</strong> </a> - <li><a href="#method-i-run">#run</a> + - <li><a href="#method-i-send">#send</a> + </span> + + + <span class="note title readonly">readonly</span> + + + + + + + + <span class="summary_desc"><div class='inline'><p> +Returns the value of attribute username. +</p> +</div></span> + +</li> + + </ul> -</nav> - </div> - <div id="project-metadata"> - <nav id="fileindex-section" class="section project-section"> - <h3 class="section-header">Pages</h3> - <ul> - <li class="file"><a href="../../Gemfile.html">Gemfile</a> - <li class="file"><a href="../../Rakefile.html">Rakefile</a> - </ul> -</nav> - <nav id="classindex-section" class="section project-section"> - <h3 class="section-header">Class and Module Index</h3> + + <h2> + Instance Method Summary + <small>(<a href="#" class="summary_toggle">collapse</a>)</small> + </h2> - <ul class="link-list"> + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#handle_message-instance_method" title="#handle_message (instance method)">- (Object) <strong>handle_message</strong>(message) </a> + + + + </span> - <li><a href="../../Safubot.html">Safubot</a> - <li><a href="../../Safubot/Bot.html">Safubot::Bot</a> - <li><a href="../../Safubot/Evented.html">Safubot::Evented</a> - <li><a href="../../Safubot/KnownUser.html">Safubot::KnownUser</a> - <li><a href="../../Safubot/Log.html">Safubot::Log</a> - <li><a href="../../Safubot/Query.html">Safubot::Query</a> + - <li><a href="../../Safubot/Request.html">Safubot::Request</a> + <span class="summary_desc"><div class='inline'><p> +Stores a DM and creates a matching Request as needed. +</p> +</div></span> - <li><a href="../../Safubot/Response.html">Safubot::Response</a> +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#handle_request-instance_method" title="#handle_request (instance method)">- (Object) <strong>handle_request</strong>(req) </a> + + + + </span> - <li><a href="../../Safubot/Test.html">Safubot::Test</a> - <li><a href="../../Safubot/Twitter.html">Safubot::Twitter</a> - <li><a href="../../Safubot/Twitter/Bot.html">Safubot::Twitter::Bot</a> - <li><a href="../../Safubot/Twitter/DirectMessage.html">Safubot::Twitter::DirectMessage</a> - <li><a href="../../Safubot/Twitter/Tweet.html">Safubot::Twitter::Tweet</a> - <li><a href="../../Safubot/XMPP.html">Safubot::XMPP</a> + - <li><a href="../../Safubot/XMPP/Bot.html">Safubot::XMPP::Bot</a> + <span class="summary_desc"><div class='inline'><p> +Emit a request event unless the request is already processed. +</p> +</div></span> - <li><a href="../../Safubot/XMPP/Message.html">Safubot::XMPP::Message</a> +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#handle_tweet-instance_method" title="#handle_tweet (instance method)">- (Object) <strong>handle_tweet</strong>(status) </a> + + + + </span> - <li><a href="../../Object.html">Object</a> - </ul> -</nav> + + + + - </div> -</nav> + + <span class="summary_desc"><div class='inline'><p> +Stores a tweet. +</p> +</div></span> + +</li> -<div id="documentation"> - <h1 class="class">class Safubot::Twitter::Bot</h1> + + <li class="public "> + <span class="summary_signature"> + + <a href="#initialize-instance_method" title="#initialize (instance method)">- (Bot) <strong>initialize</strong>(options = {}) </a> + - <div id="description" class="description"> -<p>A <a href="Bot.html">Twitter::Bot</a> instance provides a <a -href="../Bot.html">Safubot::Bot</a> with Twitter-specific processing.</p> + </span> + + <span class="note title constructor">constructor</span> + + + + + + - </div><!-- description --> + + <span class="summary_desc"><div class='inline'><p> +Options are passed straight through to ::TweetStream and ::Twitter, but the +:username is ours and important. +</p> +</div></span> + +</li> + + <li class="public "> + <span class="summary_signature"> + + <a href="#pull-instance_method" title="#pull (instance method)">- (Object) <strong>pull</strong> </a> + + + + </span> - <section id="5Buntitled-5D" class="documentation-section"> + + + + + + <span class="summary_desc"><div class='inline'><p> +Pulls DMs and mentions using the AJAX API. +</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + <a href="#reply-instance_method" title="#reply (instance method)">- (Object) <strong>reply</strong>(tweet, text) </a> + + </span> + + + + + + + + <span class="summary_desc"><div class='inline'><p> +Replies to a tweet using the appropriate mentions. +</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + <a href="#reply_header-instance_method" title="#reply_header (instance method)">- (Object) <strong>reply_header</strong>(tweet) </a> + - <!-- Attributes --> - <section id="attribute-method-details" class="method-section section"> - <h3 class="section-header">Attributes</h3> + </span> + + + + + + - - <div id="attribute-i-client" class="method-detail"> - <div class="method-heading attribute-method-heading"> - <span class="method-name">client</span><span - class="attribute-access-type">[R]</span> - </div> + + <span class="summary_desc"><div class='inline'><p> +Constructs the appropriate series of mentions for a reply to this tweet. +</p> +</div></span> + +</li> - <div class="method-description"> - - - - </div> - </div> - <div id="attribute-i-opts" class="method-detail"> - <div class="method-heading attribute-method-heading"> - <span class="method-name">opts</span><span - class="attribute-access-type">[R]</span> - </div> + <li class="public "> + <span class="summary_signature"> + + <a href="#run-instance_method" title="#run (instance method)">- (Object) <strong>run</strong> </a> + - <div class="method-description"> - - - - </div> - </div> - - <div id="attribute-i-username" class="method-detail"> - <div class="method-heading attribute-method-heading"> - <span class="method-name">username</span><span - class="attribute-access-type">[R]</span> - </div> + + </span> + + + + + + - <div class="method-description"> - - - - </div> - </div> + + <span class="summary_desc"><div class='inline'><p> +Starts our TweetStream client running. +</p> +</div></span> + +</li> + - </section><!-- attribute-method-details --> + <li class="public "> + <span class="summary_signature"> - - <!-- Methods --> + <a href="#send-instance_method" title="#send (instance method)">- (Object) <strong>send</strong>(resp) </a> - <section id="public-class-5Buntitled-5D-method-details" class="method-section section"> - <h3 class="section-header">Public Class Methods</h3> - <div id="method-c-new" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">new</span><span - class="method-args">(options={})</span> - <span class="method-click-advice">click to toggle source</span> - </div> - + </span> + + + + + + - <div class="method-description"> - - <p>Options are passed straight through to ::TweetStream and ::Twitter, but the -:username is ours and important.</p> - + + <span class="summary_desc"><div class='inline'><p> +Sends a Twitter-sourced Response to the appropriate target. +</p> +</div></span> + +</li> - - <div class="method-source-code" id="new-source"> - <pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 249</span> -<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">options</span>={}) - <span class="ruby-identifier">defaults</span> = { <span class="ruby-value">:username</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">nil</span>, - <span class="ruby-value">:consumer_key</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">:consumer_secret</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">nil</span>, - <span class="ruby-value">:oauth_token</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">nil</span>, <span class="ruby-value">:oauth_token_secret</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">nil</span>, - <span class="ruby-value">:auth_method</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">:oauth</span> } + + </ul> + - <span class="ruby-ivar">@opts</span> = <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>) - <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">&gt;</span> <span class="ruby-keyword">true</span>) - <span class="ruby-ivar">@username</span> = <span class="ruby-ivar">@opts</span>[<span class="ruby-value">:username</span>] - <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>) -<span class="ruby-keyword">end</span></pre> - </div><!-- new-source --> - - </div> + + + + + + + + <h3 class="inherited">Methods included from <span class='object_link'><a href="../Evented.html" title="Safubot::Evented (module)">Evented</a></span></h3> + <p class="inherited"><span class='object_link'><a href="../Evented.html#bind-instance_method" title="Safubot::Evented#bind (method)">#bind</a></span>, <span class='object_link'><a href="../Evented.html#emit-instance_method" title="Safubot::Evented#emit (method)">#emit</a></span>, <span class='object_link'><a href="../Evented.html#on-instance_method" title="Safubot::Evented#on (method)">#on</a></span>, <span class='object_link'><a href="../Evented.html#once-instance_method" title="Safubot::Evented#once (method)">#once</a></span>, <span class='object_link'><a href="../Evented.html#unbind-instance_method" title="Safubot::Evented#unbind (method)">#unbind</a></span></p> +<div id="constructor_details" class="method_details_list"> + <h2>Constructor Details</h2> + + <div class="method_details first"> + <p class="signature first" id="initialize-instance_method"> + + - (<tt><span class='object_link'><a href="" title="Safubot::Twitter::Bot (class)">Bot</a></span></tt>) <strong>initialize</strong>(options = {}) + - + +</p><div class="docstring"> + <div class="discussion"> + <p> +Options are passed straight through to ::TweetStream and ::Twitter, but the +:username is ours and important. +</p> - - </div><!-- new-method --> + </div> +</div> +<div class="tags"> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 265</span> + +<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> + <span class='id defaults'>defaults</span> <span class='op'>=</span> <span class='lbrace'>{</span> <span class='symbol'>:username</span> <span class='op'>=&gt;</span> <span class='kw'>nil</span><span class='comma'>,</span> + <span class='symbol'>:consumer_key</span> <span class='op'>=&gt;</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='symbol'>:consumer_secret</span> <span class='op'>=&gt;</span> <span class='kw'>nil</span><span class='comma'>,</span> + <span class='symbol'>:oauth_token</span> <span class='op'>=&gt;</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='symbol'>:oauth_token_secret</span> <span class='op'>=&gt;</span> <span class='kw'>nil</span><span class='comma'>,</span> + <span class='symbol'>:auth_method</span> <span class='op'>=&gt;</span> <span class='symbol'>:oauth</span> <span class='rbrace'>}</span> + + <span class='ivar'>@opts</span> <span class='op'>=</span> <span class='id defaults'>defaults</span><span class='period'>.</span><span class='id merge'>merge</span><span class='lparen'>(</span><span class='id options'>options</span><span class='rparen'>)</span> + + <span class='const'>DirectMessage</span><span class='period'>.</span><span class='id ensure_index'>ensure_index</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>raw.id</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='symbol'>:unique</span> <span class='op'>=&gt;</span> <span class='kw'>true</span><span class='rparen'>)</span> + <span class='ivar'>@username</span> <span class='op'>=</span> <span class='ivar'>@opts</span><span class='lbracket'>[</span><span class='symbol'>:username</span><span class='rbracket'>]</span> + <span class='ivar'>@client</span> <span class='op'>=</span> <span class='const'>Object</span><span class='op'>::</span><span class='const'>Twitter</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> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + +</div> + + <div id="instance_attr_details" class="attr_details"> + <h2>Instance Attribute Details</h2> - </section><!-- public-class-method-details --> + + <span id=""></span> + <span id="client-instance_method"></span> + <div class="method_details first"> + <p class="signature first" id="client-instance_method"> - <section id="public-instance-5Buntitled-5D-method-details" class="method-section section"> - <h3 class="section-header">Public Instance Methods</h3> + - (<tt>Object</tt>) <strong>client</strong> <span class="extras">(readonly)</span> + + +</p><div class="docstring"> + <div class="discussion"> + <p> +Returns the value of attribute client +</p> + + + </div> +</div> +<div class="tags"> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +159 +160 +161</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 159</span> + +<span class='kw'>def</span> <span class='id client'>client</span> + <span class='ivar'>@client</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> - <div id="method-i-handle_message" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">handle_message</span><span - class="method-args">(message)</span> - <span class="method-click-advice">click to toggle source</span> - </div> - + + <span id=""></span> + <span id="opts-instance_method"></span> + <div class="method_details "> + <p class="signature " id="opts-instance_method"> + + - (<tt>Object</tt>) <strong>opts</strong> <span class="extras">(readonly)</span> + - <div class="method-description"> - - <p>Stores a DM and creates a matching <a href="../Request.html">Request</a> as -needed.</p> - + +</p><div class="docstring"> + <div class="discussion"> + <p> +Returns the value of attribute opts +</p> - - <div class="method-source-code" id="handle_message-source"> - <pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 174</span> -<span class="ruby-keyword">def</span> <span class="ruby-identifier">handle_message</span>(<span class="ruby-identifier">message</span>) - <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> - <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>) -<span class="ruby-keyword">end</span></pre> - </div><!-- handle_message-source --> - - </div> - + </div> +</div> +<div class="tags"> + - - </div><!-- handle_message-method --> +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + +159 +160 +161</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 159</span> + +<span class='kw'>def</span> <span class='id opts'>opts</span> + <span class='ivar'>@opts</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> - <div id="method-i-handle_request" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">handle_request</span><span - class="method-args">(req)</span> - <span class="method-click-advice">click to toggle source</span> - </div> - + + <span id=""></span> + <span id="username-instance_method"></span> + <div class="method_details "> + <p class="signature " id="username-instance_method"> + + - (<tt>Object</tt>) <strong>username</strong> <span class="extras">(readonly)</span> + - <div class="method-description"> - - <p>Emit a request event unless the request is already processed.</p> - + +</p><div class="docstring"> + <div class="discussion"> + <p> +Returns the value of attribute username +</p> - - <div class="method-source-code" id="handle_request-source"> - <pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 169</span> -<span class="ruby-keyword">def</span> <span class="ruby-identifier">handle_request</span>(<span class="ruby-identifier">req</span>) - <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> -<span class="ruby-keyword">end</span></pre> - </div><!-- handle_request-source --> - - </div> - + </div> +</div> +<div class="tags"> + - - </div><!-- handle_request-method --> +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + +159 +160 +161</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 159</span> + +<span class='kw'>def</span> <span class='id username'>username</span> + <span class='ivar'>@username</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> - <div id="method-i-handle_tweet" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">handle_tweet</span><span - class="method-args">(status)</span> - <span class="method-click-advice">click to toggle source</span> - </div> - + </div> - <div class="method-description"> - - <p>Stores a tweet. If this tweet is directed at us, create a matching <a -href="../Request.html">Request</a>. Otherwise, emit a :timeline event.</p> - - - <div class="method-source-code" id="handle_tweet-source"> - <pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 181</span> -<span class="ruby-keyword">def</span> <span class="ruby-identifier">handle_tweet</span>(<span class="ruby-identifier">status</span>) - <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> - <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>) - <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>) - <span class="ruby-keyword">else</span> - <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>)) - <span class="ruby-keyword">end</span> -<span class="ruby-keyword">end</span></pre> - </div><!-- handle_tweet-source --> - - </div> + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <p class="signature first" id="handle_message-instance_method"> + + - (<tt>Object</tt>) <strong>handle_message</strong>(message) + - + +</p><div class="docstring"> + <div class="discussion"> + <p> +Stores a DM and creates a matching Request as needed. +</p> - - </div><!-- handle_tweet-method --> + </div> +</div> +<div class="tags"> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +179 +180 +181 +182</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 179</span> + +<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> + <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> + <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='kw'>end</span></pre> + </td> + </tr> +</table> +</div> - <div id="method-i-pull" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">pull</span><span - class="method-args">()</span> - <span class="method-click-advice">click to toggle source</span> - </div> - + <div class="method_details "> + <p class="signature " id="handle_request-instance_method"> + + - (<tt>Object</tt>) <strong>handle_request</strong>(req) + - <div class="method-description"> - - <p>Pulls DMs and mentions using the AJAX API. Used in tandem with the -streaming API to ensure we don’t miss too much while we’re offline.</p> - + +</p><div class="docstring"> + <div class="discussion"> + <p> +Emit a request event unless the request is already processed. +</p> - - <div class="method-source-code" id="pull-source"> - <pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 204</span> -<span class="ruby-keyword">def</span> <span class="ruby-identifier">pull</span> - <span class="ruby-keyword">begin</span> - <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> - <span class="ruby-identifier">handle_message</span>(<span class="ruby-identifier">message</span>) - <span class="ruby-keyword">end</span> - <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> - <span class="ruby-identifier">handle_tweet</span>(<span class="ruby-identifier">mention</span>) - <span class="ruby-keyword">end</span> - <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> - <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-string">&quot;Twitter: Couldn't pull tweets due to temporary service unavailability.&quot;</span> - <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span> - <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-node">&quot;Twitter: Unhandled error: #{e}\n#{e.backtrace.join(&quot;\n\t&quot;)}&quot;</span> - <span class="ruby-keyword">end</span> -<span class="ruby-keyword">end</span></pre> - </div><!-- pull-source --> - - </div> + </div> +</div> +<div class="tags"> + - +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> - - </div><!-- pull-method --> +174 +175 +176</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 174</span> + +<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> + <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> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> - <div id="method-i-reply" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">reply</span><span - class="method-args">(tweet, text)</span> - <span class="method-click-advice">click to toggle source</span> - </div> - + <div class="method_details "> + <p class="signature " id="handle_tweet-instance_method"> + + - (<tt>Object</tt>) <strong>handle_tweet</strong>(status) + - <div class="method-description"> - - <p>Replies to a tweet using the appropriate mentions. @param tweet A <a -href="Tweet.html">Tweet</a> object to respond to. @param text The response -text.</p> - + +</p><div class="docstring"> + <div class="discussion"> + <p> +Stores a tweet. If this tweet is directed at us, create a matching Request. +Otherwise, emit a :timeline event. +</p> - - <div class="method-source-code" id="reply-source"> - <pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 198</span> -<span class="ruby-keyword">def</span> <span class="ruby-identifier">reply</span>(<span class="ruby-identifier">tweet</span>, <span class="ruby-identifier">text</span>) - <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">update</span>(<span class="ruby-node">&quot;#{reply_header(tweet)} #{text}&quot;</span>, <span class="ruby-value">:in_reply_to_status_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">tweet</span>.<span class="ruby-identifier">raw</span>[<span class="ruby-string">'id'</span>]) -<span class="ruby-keyword">end</span></pre> - </div><!-- reply-source --> - - </div> - + </div> +</div> +<div class="tags"> + - - </div><!-- reply-method --> +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + +186 +187 +188 +189 +190 +191 +192 +193</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 186</span> + +<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> + <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> + <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> + <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='kw'>else</span> + <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> + <span class='kw'>end</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> - <div id="method-i-reply_header" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">reply_header</span><span - class="method-args">(tweet)</span> - <span class="method-click-advice">click to toggle source</span> - </div> - + <div class="method_details "> + <p class="signature " id="pull-instance_method"> + + - (<tt>Object</tt>) <strong>pull</strong> + - <div class="method-description"> - - <p>Constructs the appropriate series of mentions for a reply to this tweet.</p> - + +</p><div class="docstring"> + <div class="discussion"> + <p> +Pulls DMs and mentions using the AJAX API. Used in tandem with the +streaming API to ensure we don&#8217;t miss too much while we&#8217;re +offline. +</p> - - <div class="method-source-code" id="reply_header-source"> - <pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 191</span> -<span class="ruby-keyword">def</span> <span class="ruby-identifier">reply_header</span>(<span class="ruby-identifier">tweet</span>) - ([<span class="ruby-node">&quot;@#{tweet.username}&quot;</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">&quot;@#{@username}&quot;</span>])).<span class="ruby-identifier">join</span> -<span class="ruby-keyword">end</span></pre> - </div><!-- reply_header-source --> - - </div> - + </div> +</div> +<div class="tags"> + - - </div><!-- reply_header-method --> +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 209</span> + +<span class='kw'>def</span> <span class='id pull'>pull</span> + <span class='kw'>begin</span> + <span class='ivar'>@client</span><span class='period'>.</span><span class='id direct_messages'>direct_messages</span><span class='period'>.</span><span class='id each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id message'>message</span><span class='op'>|</span> +<span class='id handle_message'>handle_message</span><span class='lparen'>(</span><span class='id message'>message</span><span class='rparen'>)</span> + <span class='kw'>end</span> + + <span class='ivar'>@client</span><span class='period'>.</span><span class='id mentions'>mentions</span><span class='period'>.</span><span class='id each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id mention'>mention</span><span class='op'>|</span> +<span class='id handle_tweet'>handle_tweet</span><span class='lparen'>(</span><span class='id mention'>mention</span><span class='rparen'>)</span> + <span class='kw'>end</span> + <span class='kw'>rescue</span> <span class='op'>::</span><span class='const'>Twitter</span><span class='op'>::</span><span class='const'>Error</span><span class='op'>::</span><span class='const'>ServiceUnavailable</span> + <span class='const'>Log</span><span class='period'>.</span><span class='id error'>error</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Twitter: Couldn't pull tweets due to temporary service unavailability.</span><span class='tstring_end'>&quot;</span></span> + <span class='kw'>rescue</span> <span class='const'>Exception</span> <span class='op'>=&gt;</span> <span class='id e'>e</span> + <span class='const'>Log</span><span class='period'>.</span><span class='id error'>error</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Twitter: Unhandled error: </span><span class='embexpr_beg'>#{</span><span class='id e'>e</span><span class='rbrace'>}</span><span class='tstring_content'>\n</span><span class='embexpr_beg'>#{</span><span class='id e'>e</span><span class='period'>.</span><span class='id backtrace'>backtrace</span><span class='period'>.</span><span class='id join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\n\t</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span> + <span class='kw'>end</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> - <div id="method-i-run" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">run</span><span - class="method-args">()</span> - <span class="method-click-advice">click to toggle source</span> - </div> - + <div class="method_details "> + <p class="signature " id="reply-instance_method"> + + - (<tt>Object</tt>) <strong>reply</strong>(tweet, text) + - <div class="method-description"> - - <p>Starts our TweetStream client running.</p> - + +</p><div class="docstring"> + <div class="discussion"> + <p> +Replies to a tweet using the appropriate mentions. +</p> - - <div class="method-source-code" id="run-source"> - <pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 221</span> -<span class="ruby-keyword">def</span> <span class="ruby-identifier">run</span> - <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>) - <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> - <span class="ruby-identifier">handle_message</span>(<span class="ruby-identifier">message</span>) - <span class="ruby-keyword">end</span> + </div> +</div> +<div class="tags"> + <h3>Parameters:</h3> +<ul class="param"> + + <li> + + <span class='name'>tweet</span> + + + <span class='type'></span> + + + + &mdash; + <div class='inline'><p> +A Tweet object to respond to. +</p> +</div> + + </li> + + <li> + + <span class='name'>text</span> + + + <span class='type'></span> + + + + &mdash; + <div class='inline'><p> +The response text. +</p> +</div> + + </li> + +</ul> - <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> - <span class="ruby-comment"># HACK (Mispy): For some reason this is a String instead of an Exception.</span> - <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>) - <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&quot;TweetStream authentication failure!&quot;</span>) - <span class="ruby-keyword">else</span> - <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-node">&quot;Unhandled TweetStream error: #{err}&quot;</span> - <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span> <span class="ruby-string">&quot;Reinitialising TweetStream in 5 seconds.&quot;</span> - <span class="ruby-identifier">sleep</span> <span class="ruby-value">5</span> - <span class="ruby-identifier">run</span> - <span class="ruby-keyword">end</span> - <span class="ruby-keyword">end</span> - <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> - <span class="ruby-identifier">handle_tweet</span>(<span class="ruby-identifier">status</span>) - <span class="ruby-keyword">end</span> +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> - <span class="ruby-constant">Log</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;Twitter client is online at @#{@username} :3&quot;</span>) -<span class="ruby-keyword">end</span></pre> - </div><!-- run-source --> - - </div> - +203 +204 +205</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 203</span> - - </div><!-- run-method --> +<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> + <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'>&quot;</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'>&quot;</span></span><span class='comma'>,</span> <span class='symbol'>:in_reply_to_status_id</span> <span class='op'>=&gt;</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> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <p class="signature " id="reply_header-instance_method"> + + - (<tt>Object</tt>) <strong>reply_header</strong>(tweet) + + +</p><div class="docstring"> + <div class="discussion"> + <p> +Constructs the appropriate series of mentions for a reply to this tweet. +</p> + + + </div> +</div> +<div class="tags"> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +196 +197 +198</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 196</span> + +<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> + <span class='lparen'>(</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</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'>&quot;</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'>&quot;</span><span class='tstring_content'>@</span><span class='embexpr_beg'>#{</span><span class='ivar'>@username</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id join'>join</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> - <div id="method-i-send" class="method-detail "> - - <div class="method-heading"> - <span class="method-name">send</span><span - class="method-args">(resp)</span> - <span class="method-click-advice">click to toggle source</span> - </div> - + <div class="method_details "> + <p class="signature " id="run-instance_method"> + + - (<tt>Object</tt>) <strong>run</strong> + - <div class="method-description"> - - <p>Sends a Twitter-sourced <a href="../Response.html">Response</a> to the -appropriate target.</p> - + +</p><div class="docstring"> + <div class="discussion"> + <p> +Starts our TweetStream client running. +</p> - - <div class="method-source-code" id="send-source"> - <pre><span class="ruby-comment"># File lib/safubot/twitter.rb, line 157</span> -<span class="ruby-keyword">def</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">resp</span>) - <span class="ruby-identifier">source</span> = <span class="ruby-identifier">resp</span>.<span class="ruby-identifier">request</span>.<span class="ruby-identifier">source</span> - <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>) - <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>) - <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>) - <span class="ruby-identifier">reply</span>(<span class="ruby-node">&quot;#{source.header_mentions.join(' ')} #{resp.text}&quot;</span>) - <span class="ruby-keyword">else</span> - <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 #{req.source.class}!&quot;</span> - <span class="ruby-keyword">end</span> -<span class="ruby-keyword">end</span></pre> - </div><!-- send-source --> - - </div> - + </div> +</div> +<div class="tags"> + - - </div><!-- send-method --> +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 226</span> + +<span class='kw'>def</span> <span class='id run'>run</span> + <span class='const'>Fiber</span><span class='period'>.</span><span class='id new'>new</span> <span class='kw'>do</span> + <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> + + <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> +<span class='id dm'>dm</span> <span class='op'>=</span> <span class='id handle_message'>handle_message</span><span class='lparen'>(</span><span class='id message'>message</span><span class='rparen'>)</span> +<span class='id handle_request'>handle_request</span><span class='lparen'>(</span><span class='id dm'>dm</span><span class='period'>.</span><span class='id request'>request</span><span class='rparen'>)</span> + <span class='kw'>end</span> + + <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> +<span class='comment'># HACK (Mispy): For some reason this is a String instead of an Exception. +</span><span class='kw'>if</span> <span class='id err'>err</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'>invalid status code: 401</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span> + <span class='const'>Log</span><span class='period'>.</span><span class='id error'>error</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>TweetStream authentication failure!</span><span class='tstring_end'>&quot;</span></span> +<span class='kw'>else</span> + <span class='const'>Log</span><span class='period'>.</span><span class='id error'>error</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Unhandled TweetStream error: </span><span class='embexpr_beg'>#{</span><span class='gvar'>$!</span><span class='rbrace'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='gvar'>$@</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span> +<span class='kw'>end</span> + <span class='kw'>end</span> + + <span class='kw'>begin</span> +<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> + <span class='id tweet'>tweet</span> <span class='op'>=</span> <span class='id handle_tweet'>handle_tweet</span><span class='lparen'>(</span><span class='id status'>status</span><span class='rparen'>)</span> + <span class='id handle_request'>handle_request</span><span class='lparen'>(</span><span class='id tweet'>tweet</span><span class='period'>.</span><span class='id request'>request</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id tweet'>tweet</span><span class='period'>.</span><span class='id is_a?'>is_a?</span> <span class='const'>Tweet</span> +<span class='kw'>end</span> + <span class='kw'>rescue</span> <span class='const'>Exception</span> <span class='op'>=&gt;</span> <span class='id e'>e</span> +<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='const'>Interrupt</span> + <span class='id exit'>exit</span> +<span class='kw'>else</span> + <span class='const'>Log</span><span class='period'>.</span><span class='id error'>error</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>TweetStream event loop exited: </span><span class='embexpr_beg'>#{</span><span class='gvar'>$!</span><span class='rbrace'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='gvar'>$@</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span> + <span class='const'>Log</span><span class='period'>.</span><span class='id error'>error</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Reinitialising TweetStream in 5 seconds.</span><span class='tstring_end'>&quot;</span></span> + <span class='const'>EM</span><span class='op'>::</span><span class='const'>Timer</span><span class='period'>.</span><span class='id new'>new</span><span class='lparen'>(</span><span class='int'>5</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='id run'>run</span> <span class='rbrace'>}</span> +<span class='kw'>end</span> + <span class='kw'>end</span> + + <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'>&quot;</span><span class='tstring_content'>Twitter 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'>&quot;</span></span><span class='rparen'>)</span> + <span class='kw'>end</span><span class='period'>.</span><span class='id resume'>resume</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> - </section><!-- public-instance-method-details --> + <div class="method_details "> + <p class="signature " id="send-instance_method"> - </section><!-- 5Buntitled-5D --> + - (<tt>Object</tt>) <strong>send</strong>(resp) + -</div><!-- documentation --> + +</p><div class="docstring"> + <div class="discussion"> + <p> +Sends a Twitter-sourced Response to the appropriate target. +</p> -<footer id="validator-badges"> - <p><a href="http://validator.w3.org/check/referer">[Validate]</a> - <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11. - <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3. -</footer> + </div> +</div> +<div class="tags"> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +162 +163 +164 +165 +166 +167 +168 +169 +170 +171</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'lib/safubot/twitter.rb', line 162</span> + +<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> + <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> + <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> + <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> + <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> + <span class='id reply'>reply</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id source'>source</span><span class='period'>.</span><span class='id header_mentions'>header_mentions</span><span class='period'>.</span><span class='id join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'> </span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rbrace'>}</span><span class='tstring_content'> </span><span class='embexpr_beg'>#{</span><span class='id resp'>resp</span><span class='period'>.</span><span class='id text'>text</span><span class='rbrace'>}</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> + <span class='kw'>else</span> + <span class='id raise'>raise</span> <span class='const'>NotImplementedError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</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'>&quot;</span></span> + <span class='kw'>end</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Mon Nov 28 20:20:04 2011 by + <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.7.3 (ruby-1.9.2). +</div> + + </body> +</html> \ No newline at end of file