<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Squash &#187; Ruby</title>
	<atom:link href="http://balpreetpankaj.com/blog/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://balpreetpankaj.com/blog</link>
	<description>Just another weblog</description>
	<lastBuildDate>Sun, 16 Oct 2011 23:32:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Facebooker: Creating an Iframe Application (Incorrect Signature)</title>
		<link>http://balpreetpankaj.com/blog/2009/07/24/facebooker-creating-an-iframe-application-incorrect-signature/</link>
		<comments>http://balpreetpankaj.com/blog/2009/07/24/facebooker-creating-an-iframe-application-incorrect-signature/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 09:05:06 +0000</pubDate>
		<dc:creator>balpreetspankaj</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Facebooker]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://balpreetpankaj.com/blog/?p=56</guid>
		<description><![CDATA[I started developing a Facebook app for one of my existing websites.  Since, I already had a working website and I prefer normal html and js over fbml and JS over FBML and FBJS, I decided to take the IFrame route. While working with my app, I ran into this bizarre problem where clicking on [...]]]></description>
			<content:encoded><![CDATA[<p>I started developing a Facebook app for one of my existing websites.  Since, I already had a working website and I prefer normal html and js over fbml and JS over FBML and FBJS, I decided to take the IFrame route. While working with my app, I ran into this bizarre problem where clicking on any link after loading the facebook app, gave me an invalid Signature exception. After digging my way through the Facebooker (Rails plugin for Facebook app dev) code, I find that the expected signature is nil inside the "verify_signature function". Turns out you need to append all your links in a Facebook iframe app with the fb_sig params. So, I created a function in Application.rb and set it as a before_filter</p>
<pre class="ruby">before_filter <span style="color:#ff3333; font-weight:bold;">:set_facebook_params</span>
ensure_application_is_installed_by_facebook_user
&nbsp;
protected
<span style="color:#9966CC; font-weight:bold;">def</span> set_facebook_params
<span style="color:#0066ff; font-weight:bold;">@fb_params</span> = params.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |collection, pair|
collection<span style="color:#006600; font-weight:bold;">&#91;</span>pair.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#93;</span> = pair.<span style="color:#9900CC;">second</span> <span style="color:#9966CC; font-weight:bold;">if</span> pair.<span style="color:#9900CC;">first</span> =~ /^fb_sig/
collection
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre>
<p>The above code will extract out all the fb_sig params from the url and store it in @fb_params. Now add this hash to every url that you create inside you Iframe. This was the fix that I came in the middle of the might, and I am sure this may not be the best fix. But this works. Let me know if there is another workaround.</p>
]]></content:encoded>
			<wfw:commentRss>http://balpreetpankaj.com/blog/2009/07/24/facebooker-creating-an-iframe-application-incorrect-signature/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>action_mailer_tls and Ruby 1.8.7</title>
		<link>http://balpreetpankaj.com/blog/2009/01/21/action_mailer_tls-and-ruby-187/</link>
		<comments>http://balpreetpankaj.com/blog/2009/01/21/action_mailer_tls-and-ruby-187/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 19:13:22 +0000</pubDate>
		<dc:creator>balpreetspankaj</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[action_mailer_tls]]></category>
		<category><![CDATA[check_auth_args]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[ruby 1.8.7]]></category>

		<guid isPermaLink="false">http://balpreetpankaj.com/blog/?p=34</guid>
		<description><![CDATA[If you are using action_mailer_tls rails pluin and you shifted to Ruby 1.8.7, your app might break. I recently ran into this problem, coz my host providers shifted to Ruby 1.8.7 and I started getting errors when I was trying to send emails. The problem is because the check_auth_args function has changed in Ruby 1.8.7. [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using action_mailer_tls rails pluin and you shifted to Ruby 1.8.7, your app might break. I recently ran into this problem, coz my host providers shifted to Ruby 1.8.7 and I started getting errors when I was trying to send emails. The problem is because the check_auth_args function has changed in Ruby 1.8.7. Now it requires only 2 args as opposed to 3. The action_mailer_tls plugin uses this function but uses three arguments. So, to get back running again, make the following changes:</p>
<p>1).  Go to your action_mailer_tls plugin installation<br />
2). Inside the do_start function, replace the call to "check_auth_args" with the following snippet:</p>
<pre class="ruby">&nbsp;
no_args = method<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:check_auth_args</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">arity</span>
<span style="color:#9966CC; font-weight:bold;">if</span> no_args == <span style="color:#006666;">2</span>
  check_auth_args user, secret <span style="color:#9966CC; font-weight:bold;">if</span> user <span style="color:#9966CC; font-weight:bold;">or</span> secret
<span style="color:#9966CC; font-weight:bold;">else</span>
  check_auth_args user, secret, authtype <span style="color:#9966CC; font-weight:bold;">if</span> user <span style="color:#9966CC; font-weight:bold;">or</span> secret
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://balpreetpankaj.com/blog/2009/01/21/action_mailer_tls-and-ruby-187/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ruby 1.8.7 String#chars compatibility problem with rails</title>
		<link>http://balpreetpankaj.com/blog/2008/12/31/ruby-187-stringchars-compatibility-problem-with-rails/</link>
		<comments>http://balpreetpankaj.com/blog/2008/12/31/ruby-187-stringchars-compatibility-problem-with-rails/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 16:45:57 +0000</pubDate>
		<dc:creator>balpreetspankaj</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ActiveSupport]]></category>

		<guid isPermaLink="false">http://balpreetpankaj.com/blog/?p=28</guid>
		<description><![CDATA[Recently, I started getting weird "LoadError" with my Rails app on Dreamhost. I had an "Article" model which contained many "Photo" models.  When the "Article" controller tried to refer to the photos in its object, I got the following error:
LoadError: Expected {full server path}/photo.rb to define Photo. 
I had a photo.rb file which had [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I started getting weird "LoadError" with my Rails app on Dreamhost. I had an "Article" model which contained many "Photo" models.  When the "Article" controller tried to refer to the photos in its object, I got the following error:<br />
<code>LoadError: Expected {full server path}/photo.rb to define Photo. </code></p>
<p>I had a photo.rb file which had class Photo defined. I was using attachment_fu plugin to implement photos. After some head scratching, I found that the error was in photo.rb file. Hence photo.rb was not loading correctly, and therefore a load error.</p>
<p>The actual error happened coz the Dreamhost guys had updated Ruby to 1.8.7 which has some incompatibility with Rails 2.0.2 that I was using. When I tried to create a Photo object on the command line, I got this error:<br />
<code>NoMethodError: undefined method '[]' for #&lt;Enumerable:enumerator&gt;&lt;/code&gt;</p>
<p>Ruby 1.8.7 has String#chars. This returns an Enumerator object but Rails 2.0.2 expects an ActiveSupport::MultiBye::Chars object.</p>
<p>We can avoid this conflict, by putting the following code in the config/initializers/ directory.</p>
<pre class="ruby"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#996600;">'1.9'</span>.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:force_encoding</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#CC0066; font-weight:bold;">String</span>.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#9966CC; font-weight:bold;">begin</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    remove_method <span style="color:#ff3333; font-weight:bold;">:chars</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">NameError</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color:#008000; font-style:italic;"># OK</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#9966CC; font-weight:bold;">end</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li></ol></pre>
]]></content:encoded>
			<wfw:commentRss>http://balpreetpankaj.com/blog/2008/12/31/ruby-187-stringchars-compatibility-problem-with-rails/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Insert comments in an erb file</title>
		<link>http://balpreetpankaj.com/blog/2008/12/31/insert-comments-in-an-erb-file/</link>
		<comments>http://balpreetpankaj.com/blog/2008/12/31/insert-comments-in-an-erb-file/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 16:19:06 +0000</pubDate>
		<dc:creator>balpreetspankaj</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Comments]]></category>
		<category><![CDATA[Erb]]></category>

		<guid isPermaLink="false">http://balpreetpankaj.com/blog/?p=23</guid>
		<description><![CDATA[How does one insert comments in an erb file. The normal http tag to insert comments do not work well when there are embedded ruby statements in the html.
&#60;!-- &#60;b&#62;Hello&#60;/b&#62;&#60;%= @article.author %&#62; --&#62;
The above statement will not stop the evaluation of article.author. Instead, @article.author will still be evaluated and placed as a comment in the [...]]]></description>
			<content:encoded><![CDATA[<p>How does one insert comments in an erb file. The normal http tag to insert comments do not work well when there are embedded ruby statements in the html.</p>
<p><code>&lt;!-- &lt;b&gt;Hello&lt;/b&gt;&lt;%= @article.author %&gt; --&gt;</code></p>
<p>The above statement will not stop the evaluation of article.author. Instead, @article.author will still be evaluated and placed as a comment in the generated html file. Say the author was Balpreet, then we have a html comment:</p>
<p>&lt;!-- &lt;b&gt;Hello&lt;/b&gt;Balpreet --&gt;</p>
<p>So, what if we want to just comment stuff out, so that the embedded ruby statements are not evaluated at all. There are basically two ways that I think we can achieve this:</p>
<p>1. Insert block level comments using embedded ruby.<br />
<code>&lt;%<br />
=begin %&gt;<br />
&lt;b&gt;Hello&lt;/b&gt;&lt;%= @article.author %&gt;&lt;%<br />
=end %&gt;</code></p>
<p>2. Insert conditional<br />
<code>&lt;% if false %&gt;<br />
&lt;b&gt;Hello&lt;/b&gt;&lt;%= @article.author %&gt;<br />
&lt;% end %&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://balpreetpankaj.com/blog/2008/12/31/insert-comments-in-an-erb-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rfeedparser and Hpricot</title>
		<link>http://balpreetpankaj.com/blog/2008/11/15/rfeedparser-and-hpricot/</link>
		<comments>http://balpreetpankaj.com/blog/2008/11/15/rfeedparser-and-hpricot/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 05:49:45 +0000</pubDate>
		<dc:creator>balpreetspankaj</dc:creator>
				<category><![CDATA[Feed Parser]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[feedparser]]></category>
		<category><![CDATA[hpricot]]></category>
		<category><![CDATA[Mark Pilgrim]]></category>
		<category><![CDATA[rfeedparser]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">http://balpreetpankaj.com/blog/?p=19</guid>
		<description><![CDATA[RFeedParser is one of the ruby gems to parse rss feeds. Its a translation of Mark Pilgrims's Universal Feed Parser from Python into Ruby. It has a few dependencies and requires you to install a few other gems. The installation instructions are simple and the usage is simple.
One of the dependencies for this was hpricot. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rfeedparser.rubyforge.org/">RFeedParser</a> is one of the ruby gems to parse rss feeds. Its a translation of Mark Pilgrims's <a href="http://feedparser.org/">Universal Feed Parser</a> from Python into Ruby. It has a few dependencies and requires you to install a few other gems. The installation instructions are simple and the usage is simple.</p>
<p>One of the dependencies for this was <a href="https://code.whytheluckystiff.net/hpricot/">hpricot</a>. Everything was working fine till one day, I updated my hpricot gem and did a cleanup of my rubygems.  I started getting an error:</p>
<p><code>balpreet-pankajs-macbook:digg balpreetpankaj$ ruby bloo.rb<br />
/Library/Ruby/Site/1.8/rubygems.rb:142:in `activate': can't activate hpricot (= 0.6, runtime), already activated hpricot-0.6.164 (Gem::Exception)<br />
	from /Library/Ruby/Site/1.8/rubygems.rb:158:in `activate'<br />
	from /Library/Ruby/Site/1.8/rubygems.rb:157:in `each'<br />
	from /Library/Ruby/Site/1.8/rubygems.rb:157:in `activate'<br />
	from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'<br />
	from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:510:in `require'<br />
	from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:355:in `new_constants_in'<br />
	from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:510:in `require'</code></p>
<p>After a little digging arnd with rubygems, I figured out that the rfeedparser has a requirement of running with a hpricot gem with version = 0.6. I changed that to >= 0.6 and things started working fine. I was using version 0.9.951 of rfeedparser. If you use rfeedparser and run into a similar problem, this is how you fix it:</p>
<p>1) Update the gemspec for rfeedparser. Go to your gem installation dir. You can find this by doing:<br />
    <code>gem env gempath</code><br />
    Then edit the $gemPATH/specifications/rfeedparser0.9.951.gemspec and update all references of hpricot from "=0.6" to ">=0.6".<br />
2). Go to $GEMPATH/gems/rfeedparser-0.9.951/lib/rfeedparser.rb and again update the reference of hpricot.</p>
<p>This should get you rolling with all new versions of hpricot.   </p>
]]></content:encoded>
			<wfw:commentRss>http://balpreetpankaj.com/blog/2008/11/15/rfeedparser-and-hpricot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Crawling the web with Ruby</title>
		<link>http://balpreetpankaj.com/blog/2008/10/30/crawling-the-web-with-ruby/</link>
		<comments>http://balpreetpankaj.com/blog/2008/10/30/crawling-the-web-with-ruby/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 10:10:12 +0000</pubDate>
		<dc:creator>balpreetspankaj</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[amazon sqs]]></category>
		<category><![CDATA[hpricot]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[spider]]></category>
		<category><![CDATA[web crawler]]></category>

		<guid isPermaLink="false">http://balpreetpankaj.com/blog/?p=3</guid>
		<description><![CDATA[Recently for one of my projects, I needed to write my own custom crawler to crawl some of my favorite blogs. I am a recent Ruby convert and I am totally in love with the language. So i decided to have the crawler in Ruby. After some Googling around, I found out this very neat [...]]]></description>
			<content:encoded><![CDATA[<p>Recently for one of my projects, I needed to write my own custom crawler to crawl some of my favorite blogs. I am a recent Ruby convert and I am totally in love with the language. So i decided to have the crawler in Ruby. After some Googling around, I found out this very neat crawler, <a href="http://mikeburnscoder.wordpress.com/2007/03/31/spider-the-web-with-ruby/">Spider</a> written in Ruby by <a href="http://mike-burns.com">Mike Burns</a>. You can find the source code <a href="http://github.com/psq/spider/tree/master/README">here</a>. The code is currently maintained by John Nagro.</p>
<p>The crawler is simple and yet has support for Amazon SQS and memcahed, so that you can run multiple crawler processes at the same time.  There are also some drawbacks:</p>
<p>1. The urls ae just crawled in the order they are discovered ( breadth-first search). There is no way to specify the ordering in which the urls should be searched.</p>
<p>2. There is no HTML parsing on top of the crawled data.</p>
<p>The first drawback was not much of a problem for my purposes, coz I needed to crawl all the web pages of a blog. Order of crawling was not a deal for me. The crawler has a way in which you can specify the urls in a regex form which are to be crawled. This served my purposes.</p>
<p>I needed HTML parsing though. But this was easy. I just used the <a href="http://code.whytheluckystiff.net/hpricot/">hpricot</a> gem to do HTML parsing on top of the crawled data:</p>
<p>Here is a sample code, on how to crawl a particular blog using Spider and using hpricot to print out the meta content on each page.</p>
<pre class="ruby"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'spider'</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'hpricot'</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Spider.<span style="color:#9900CC;">start_at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'http://simpliflying.com/'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |s|</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#008000; font-style:italic;"># Limit the pages to just this domain.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  s.<span style="color:#9900CC;">add_url_check</span> <span style="color:#9966CC; font-weight:bold;">do</span> |a_url|</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    a_url =~ %r<span style="color:#006600; font-weight:bold;">&#123;</span>^http://simpliflying.<span style="color:#9900CC;">com</span>.<span style="color:#9900CC;">*</span><span style="color:#006600; font-weight:bold;">&#125;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#9966CC; font-weight:bold;">end</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#008000; font-style:italic;"># Handle 404s.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  s.<span style="color:#9900CC;">on</span> <span style="color:#006666;">404</span> <span style="color:#9966CC; font-weight:bold;">do</span> |a_url, err_code|</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;URL not found: #{a_url}&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#9966CC; font-weight:bold;">end</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#008000; font-style:italic;"># Handle 2xx.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  s.<span style="color:#9900CC;">on</span> <span style="color:#ff3333; font-weight:bold;">:success</span> <span style="color:#9966CC; font-weight:bold;">do</span> |a_url, resp, prior_url|</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{a_url}: #{resp.code}&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    doc = Hpricot<span style="color:#006600; font-weight:bold;">&#40;</span>resp.<span style="color:#9900CC;">body</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color:#006600; font-weight:bold;">&#40;</span>doc/<span style="color:#996600;">&quot;meta&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |meta|</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">      <span style="color:#CC0066; font-weight:bold;">puts</span> meta.<span style="color:#9900CC;">attributes</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'content'</span><span style="color:#006600; font-weight:bold;">&#93;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color:#9966CC; font-weight:bold;">end</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#9966CC; font-weight:bold;">end</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#008000; font-style:italic;"># Handle everything.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  s.<span style="color:#9900CC;">on</span> <span style="color:#ff3333; font-weight:bold;">:any</span> <span style="color:#9966CC; font-weight:bold;">do</span> |a_url, resp|</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;URL returned anything: #{a_url} with this code #{resp.code}&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">  <span style="color:#9966CC; font-weight:bold;">end</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li></ol></pre>
<p>A very good Hpricot documentation is available <a href="http://code.whytheluckystiff.net/hpricot/wiki/AnHpricotShowcase">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://balpreetpankaj.com/blog/2008/10/30/crawling-the-web-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

