Created
October 12, 2010 17:15
-
-
Save bhb/622551 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # something like this | |
| handle(status, body) do |handler| | |
| # handle Not Modified specially | |
| handler.304? do | |
| end | |
| # all (other) 200, 300 status codes | |
| handler.success? do | |
| # automatically gives a nice error if body does not parse as JSON | |
| handler.json do |body| | |
| # treat hash keys like array methods and automatically give nice error | |
| # if foo or foo.bar is not found | |
| body.foo.bar | |
| end | |
| end | |
| # all failure codes | |
| # if not specified, gives default exception | |
| handler.fail? do | |
| end | |
| handler.else do | |
| #anything not handled | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment