Skip to content

Instantly share code, notes, and snippets.

@bhb
Created October 12, 2010 17:15
Show Gist options
  • Save bhb/622551 to your computer and use it in GitHub Desktop.
Save bhb/622551 to your computer and use it in GitHub Desktop.
# 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