<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>has_many :thoughts: Capistrano Twitter task</title>
    <link>http://blog.kineticweb.com/articles/2008/02/10/capistrano-twitter-task</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Musings from a Ruby on Rails development team</description>
    <item>
      <title>Capistrano Twitter task</title>
      <description>&lt;p&gt;Justin had an idea that we should post to &lt;a href="http://www.twitter.com"&gt;Twitter&lt;/a&gt; whenever we deploy a new version of our apps to either a staging site or the production app. Turns out, this is really easy with the &lt;a href="http://twitter4r.rubyforge.org/"&gt;twitter4r gem&lt;/a&gt;. I used a twitter account that Justin created expressly for our internal notices and set its updates to be private. Then I created this task:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="ident"&gt;desc&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;posts to twitter that something was deployed&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="ident"&gt;task&lt;/span&gt; &lt;span class="symbol"&gt;:send_tweet&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;rubygems&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;gem&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;twitter4r&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;twitter&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;require&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;twitter/console&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;twitter&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Twitter&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Client&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;from_config&lt;/span&gt;&lt;span class="punct"&gt;('&lt;/span&gt;&lt;span class="string"&gt;config/twitter.yml&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt;&lt;span class="ident"&gt;rails_env&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
  &lt;span class="ident"&gt;status&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;twitter&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;status&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:post&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;deployed &lt;span class="expr"&gt;#{application}&lt;/span&gt; to &lt;span class="expr"&gt;#{rails_env}&lt;/span&gt;&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;)&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;The twitter4r library loads a simple yaml file that contains the username and password of the twitter account to use. And one line of code posts the status update with the name of the app and the environment from previously-defined variables.&lt;/p&gt;


	&lt;p&gt;That&amp;#8217;s it! The great thing about using Twitter for this, as Justin pointed out, is that each one of us developers can consume this information how we choose: IM, Growl messages with &lt;a href="http://iconfactory.com/software/twitterrific"&gt;Twitterific&lt;/a&gt;, &lt;span class="caps"&gt;SMS&lt;/span&gt;, etc. So it&amp;#8217;s really just the syndication technology that we&amp;#8217;re taking advantage of.&lt;/p&gt;


	&lt;h2&gt;Update&lt;/h2&gt;


	&lt;p&gt;Chris&amp;#8217;s comment below prompted me to come up with a &lt;a href="http://blog.kineticweb.com/articles/2008/02/16/capistrano-twitter-task-take-2"&gt;new version&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Sun, 10 Feb 2008 10:37:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:c9889033-88a8-4c6a-a2cb-23b2bf7694c5</guid>
      <author>Colin A. Bartlett</author>
      <link>http://blog.kineticweb.com/articles/2008/02/10/capistrano-twitter-task</link>
      <category>capistrano</category>
      <category>ruby</category>
      <category>twitter</category>
      <category>Rails</category>
    </item>
    <item>
      <title>"Capistrano Twitter task" by Chris Matthieu</title>
      <description>You could also post a tweet without the twitter gem as follows:

require 'open-uri'

url = URI.parse('http://twitter.com/statuses/update.xml')
req = Net::HTTP::Post.new(url.path)
req.basic_auth 'twitterid' + ":" + 'twitterpassword', ''
req.set_form_data({'status' = "deployed #{application} to #{rails_env}"})
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }

Hope this helps!
Chris Matthieu
&lt;a href="http://rubyology.com" rel="nofollow"&gt;Rubyology&lt;/a&gt;</description>
      <pubDate>Mon, 11 Feb 2008 08:40:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:1fc244d0-8b9b-4986-af58-0837f8a574a6</guid>
      <link>http://blog.kineticweb.com/articles/2008/02/10/capistrano-twitter-task#comment-213</link>
    </item>
  </channel>
</rss>
