<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
  <title>roovo blog</title>
  <subtitle>ramblings and rumblings</subtitle>
  <link href="http://roovoweb.com//" rel="self" />
  <link href="http://roovoweb.com/" />
  <updated>2010-08-16T08:09:18+01:00</updated>
  <author>
    <name>roovo</name>
    <email>roovo@roovoweb.com</email>
  </author>
  <id>http://roovoweb.com/</id>
  
      <entry>
        <title>OAuth conversion for unattended twitter bots</title>
        <link href="/posts/2010/08/15/oauth-conversion-for-unattended-twitter-bots.html" />
        <id>tag:roovoweb.com,2010-08-15:1281900210</id>
        <updated>2010-08-15T20:23:30+01:00</updated>
        <content type="html">&lt;p&gt;I have a couple of ruby scripts which scrape information off websites to post to their own twitter accounts: &lt;a href=&quot;http://twitter.com/felixstowe_port&quot;&gt;felixstowe port&lt;/a&gt; and &lt;a href=&quot;http://twitter.com/virgin_movies&quot;&gt;virgin movies&lt;/a&gt;.  These were both set up quite a while ago using Twitter4r and basic authentication and so were doomed to stop working come the end of the month if I didn&amp;#8217;t update them.&lt;/p&gt;
&lt;p&gt;As today is the start of the basic-auth turn off process I though I&amp;#8217;d better convert them over to OAth.  I already had a fair understanding of how OAth worked, but I found it pretty tricky to find the information I needed on how to get these unattended scripts set up to work using it.&lt;/p&gt;
&lt;p&gt;The first thing I did was to switch over to John Nunemaker&amp;#8217;s &lt;a href=&quot;http://twitter.rubyforge.org/&quot;&gt;Twitter gem&lt;/a&gt; as I couldn&amp;#8217;t work out if Twitter4r supported OAuth or not and Johns obviously did and has a really helpful page on how to set it up &amp;#8211; here&amp;#8217;s a copy of the snippet you need.&lt;/p&gt;
&lt;div class=&quot;CodeRay&quot;&gt;
&lt;pre&gt;oauth = &lt;span class=&quot;co&quot;&gt;Twitter&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;OAuth&lt;/span&gt;.new(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;consumer token&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;consumer secret&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)
oauth.authorize_from_access(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;access token&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;access secret&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)

client = &lt;span class=&quot;co&quot;&gt;Twitter&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;Base&lt;/span&gt;.new(oauth)
client.friends_timeline.each  { |tweet| puts tweet.inspect }
client.user_timeline.each     { |tweet| puts tweet.inspect }
client.replies.each           { |tweet| puts tweet.inspect }
client.update(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Heeeyyyyoooo from Twitter Gem!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then all you need is the consumer and access keys and secrets.&lt;/p&gt;
&lt;p&gt;To generate these you need to add an application to your twitter account (go to &lt;a href=&quot;http://dev.twitter.com/apps&quot;&gt;http://dev.twitter.com/apps&lt;/a&gt; after logging in to your account).  Fill out the info to register your application (i.e. your script).  The important items are the Application Name as this will appear as the source of the tweets on your twitter stream, and the Application Type which you need to set to Client (as you can&amp;#8217;t use callback urls in an unattended script).&lt;/p&gt;
&lt;p&gt;Once your application details have been saved you can get the details you need: the consumer key (or token) and secret are on the application details page and the access token and secret are available from the My Access Token link (oauth_token and oauth_token_secret).&lt;/p&gt;
&lt;p&gt;Fill them in the code above and you should be good to go.&lt;/p&gt;</content>
      </entry>
  
      <entry>
        <title>The End of Dependency Hell?</title>
        <link href="/posts/2009/04/20/the-end-of-dependency-hell.html" />
        <id>tag:roovoweb.com,2009-04-20:1240265569</id>
        <updated>2009-04-20T23:12:49+01:00</updated>
        <content type="html">&lt;p&gt;Saw an interesting &lt;a href=&quot;http://github.com/wycats/merb/commit/a5ee3a0d9e9e19480a32c35c4267480e816d6592&quot;&gt;commit message&lt;/a&gt; in the merb repo on github today.&lt;/p&gt;
&lt;p&gt;The part that caught my attention was:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Adds support for Merb::Config[:ignore_system_gems], which if set to true will &lt;strong&gt;not&lt;/strong&gt; fallback to system gems. This enables you to be sure your merb app has all required gems bundled, and not accidently using system gems.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;This sounds like it has the potential to keep all those nasty already loaded errors at bay.  Can&amp;#8217;t wait to see if it&amp;#8217;s true.&lt;/p&gt;</content>
      </entry>
  
      <entry>
        <title>(Not So Well) Targeted Advertising</title>
        <link href="/posts/2009/04/17/targeted-ads.html" />
        <id>tag:roovoweb.com,2009-04-17:1239953389</id>
        <updated>2009-04-17T08:29:49+01:00</updated>
        <content type="html">&lt;p&gt;Spotted on the Guardian website &amp;#8211; bodes well for the wonders of targeted advertising&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/content/targeted_advertising.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;</content>
      </entry>
  
      <entry>
        <title>DataMapper - Form Friendly Integers</title>
        <link href="/posts/2009/04/14/form-friendly-integers-for-datamapper.html" />
        <id>tag:roovoweb.com,2009-04-14:1239723450</id>
        <updated>2009-04-14T16:37:30+01:00</updated>
        <content type="html">&lt;p&gt;I like friendly things and DataMapper is one of them.  I also like friendly forms and am a bit picky about how they should behave. Here&amp;#8217;s part of a form for inputting a value into an Integer property on a DataMapper model.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/content/before_save.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Notice that some dumb-ass has entered something stupid in the text box. Now when they submit the form they end up seeing:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/content/after_save.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The error is great, but I&amp;#8217;m not big on the disappearing trick that the text has done.  Internally DataMapper is casting the input to be an Integer which results in the text vanishing never to be seen again.  If the value input was a decimal then if there were no other errors on the form it would submit OK without complaining that the number wasn&amp;#8217;t an integer and save the integer part of the number to the database &amp;#8211; WTF!&lt;/p&gt;
&lt;h4&gt;The solution&lt;/h4&gt;
&lt;p&gt;There&amp;#8217;s a very helpful &lt;a href=&quot;http://datamapper.org/doku.php?id=dm-more:dm-types&quot;&gt;docs page&lt;/a&gt; which explains how to write your own DataMapper types.  So I did and it was pretty straightforward.  The result is on my github account:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://github.com/roovo/dm-form_friendly_integer&quot;&gt;dm-form_friendly_integer&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can use this in your models and your form fields will behave a bit more sensibly (well I think so anyway).&lt;/p&gt;</content>
      </entry>
  
</feed>
