public
Description: simple logging/caching proxy for Net::HTTP
Homepage: http://livsey.org
Clone URL: git://github.com/rlivsey/middleman.git
name age message
file .gitignore Fri May 08 06:37:58 -0700 2009 added .gitignore [rlivsey]
file MIT-LICENSE Fri May 08 03:46:13 -0700 2009 add MIT-LICENSE [rlivsey]
file README.markdown Fri May 08 06:21:28 -0700 2009 setup basic options & add stub net/http interce... [rlivsey]
file RakeFile Fri May 08 05:18:16 -0700 2009 updated gem summary [rlivsey]
file VERSION Fri May 08 04:06:03 -0700 2009 Version bump to 0.0.0 [rlivsey]
directory lib/ Fri May 08 09:01:06 -0700 2009 initial intercept and store implementation [rlivsey]
file middleman.gemspec Fri May 08 09:03:54 -0700 2009 update gemspec [rlivsey]
directory spec/ Fri May 08 09:01:06 -0700 2009 initial intercept and store implementation [rlivsey]
README.markdown

About

Middleman is a simple logging/caching proxy for Net::HTTP which can make developing against remote services easier (especially if they have API limits).

By default, it caches to a file, so the cache is persistent across multiple runs of your app.

Installation

gem sources -a http://gems.github.com sudo gem install rlivsey-middleman

Example usage

require 'rubygems'
require 'twitter'
gem 'middleman'
require 'middleman'

Twitter::Search.new('bacon') # makes the request to Twitter
Twitter::Search.new('bacon') # same search, so returns from the cache

Options

Output information to the console

Middleman.options[:verbose] = true

Change the store used for the cache, see the 'stores' section below for more information, but it's basically an object which acts like a Hash

Middleman.options[:store] = {}

Change where verbose output is sent, by default it's STDOUT

Middleman.options[:logger] = Logger.new('middleman.log')

Stores

By default Middleman uses Middleman::Store::File to cache the requests to files in a directory. The file names are MD5 hashes of the request details.

The interface to Middleman::Store::File is basically a Hash, so any object which responds to [], []= and is enumerable can be used as a store.

Using a Hash for the store will work fine, but will not persist across runs of your application.

Notes

At the moment this only works against Net::HTTP. I've got plans to make it easier to extend and add the ability to work with other libraries such as Curb etc...

Feel free to fork and send in patches.

Me

  • Home & Contact info: http://livsey.org
  • Twitter: http://twitter.com/rlivsey
  • GitHub: http://github.com/rlivsey
  • Recommend: http://www.workingwithrails.com/person/5436-richard-livsey