Feedalizer wordmark in a serif face with the red RSS icon standing in for the final letter

Here is a little code snippet which monkey-patch Feedalizer to let it grab web content through a HTTP proxy:

# HTTP proxy settings
HTTP_PROXY_HOST = "123.456.78.90"
HTTP_PROXY_PORT = 8080

# Calculate proxy URL
HTTP_PROXY_URL = "http://#{HTTP_PROXY_HOST}:#{HTTP_PROXY_PORT}"

# Monkey patch feedalizer to support page grabbing through a proxy
require 'feedalizer'
class Feedalizer
  # Backup original grab_page method
  alias_method :grab_page_orig, :grab_page
  # Define new grab_page() method with proxy support
  def grab_page(url)
    open(url, :proxy => HTTP_PROXY_URL) { |io| Hpricot(io) }
  end
end

This fix, written for a Ruby on Rails -based project, lay in the environment.rb file, but I wonder if this is the right place and the right way of doing it… Anyway, it works for me! :)

Update : A post from Matthew Higgins’ blog that answer my question above has just shown up in my feed aggregator. What’s he telling us? That I’m a naughty programmer :

Previous to 2.0, naughty developers pasted code at the bottom of environment.rb , and the config/initializer folder was a welcome convention to help organize this madness.

For your instance, the code in this post is extracted from an “old” (prior to RoR 2.0) project, thus explaining my naughtyness… ;)

6 archived comments

Comments are closed. These were posted on Disqus, and are archived here.

  1. Apologies, I did not mean to be so harsh! Still, it would be better to move this into a feedalizer.rb file and just have

    require 'feedalizer'
    

    in environments.rb.

    1. Kevin Deldycke Author

      Don't worry Matthew, your statement was quite funny ! And it's good to read someone that can speak his mind.

      And thanks for your comment and the tip. I'll probably rename the feedalizer.rb you suggest by something like monkey-patch-feedalizer.rb, as I like having very explicit names that pop up, especially when they belongs to hacks and workarounds...

  2. Hi,

    Would you be willing to share your Rails code, so I can see how you made feedalizer work in the context of a Rails app? I'm having trouble getting that to work, and (afaik) there's not really any documentation for feedalizer (other than just using the .methods method and trying them each out to see what they do, which still doesn't solve my problem of context).

    Thanks!

    1. Whoops... forgot to check "Notify me of followup comments via e-mail"

    2. Christoffer

      I think the best way to make Feedalizer use an HTTP proxy is to set the http_proxy environment variable (that OpenURI respects).

      @B: You're supposed to study the source code. (It's only 49 SLOC.) I know I'm a bit late reading this, but I wrote you an example: http://code.vemod.net/svn/misc/feedalizer/trunk/examples/slashdot_feedalizer_controller.rb

    3. Kevin Deldycke Author

      @B: I've just released the project in which I used Feedalizer under an Open-Source license. The code your looking for is available on GitHub.