swipely/docker-api — pull request #222 by mrflip (2014-11-29 12:57:06+00:00)
Title: Push and Pull send progress steps to supplied block; pushing raises an error if unauthorized.

This patch lets me show feedback during the long slow process of pushing or pulling an image.

* A block supplied to `Image#push` or `Image.create` will be called with the parsed hash of each json message streamed back from the server.
* create and push now raise errors if an error response is returned from the server
* The VCR example for creating an image was actually that of a 401 Unauthorized request. I faked data from a successful pull into the 'pushes_the_Image.yml' VCR record, and used the old version as the test case for an unauthorized call.

I'm not quite sure how I should be handling exceptions in all this.

First, I'm assuming it's fair to raise an exception if any response from the server shows an error -- but if there are known-harmless errors out there, they will now be explodey.

Also, if an error condition occurs in the response_block, it is caught and re-thrown as an Excon error. So I'm throwing a generic error inside the block, then catching all excon errors and re-throwing only the ones I recognize (Unauthorized for push, Not Found for pull) as Docker errors. Let me know if you prefer some other strategy.

This obviates the PR in #209, as the last ID is retrieved naturally in the response block