TooTallNate/node-spotify-web — pull request #20 by adammw (2013-06-18 13:10:51+00:00)
Title: Refactor MercuryRequest code into sendProtobufRequest function

@TooTallNate: I'm not sure how to do that lint I always see in the commit logs (assuming that there is such a tool and you are not just doing it by-hand), so you may have to bear with some ugly code again. I was planning to have a crack at implementing Playlists but I ended up finding I needed to clean this part up first.

Previously, all functions which required MecuryRequest for communications
(such as `metadata()`, `playlist()` and `rootlist()`) ) had to do the
construction of requests and callback processing themselves.

This commit refactors the logic into a separate `sendProtobufRequest()` function
which handles these sorts of communication.

This commit also updates the MercuryRequest protobuf format with new fields and
field names as found in the official client, and it turns out that the reply
of a MercuryRequest is actually MercuryRequest protobuf and not a MercuryReply
as was it being parsed as previously, so it is used instead for parsing replies.

Fixes #11 - properly this time.

Suggestions or code improvements welcome, this is just a first attempt. I did a quick test using the albumArt example to make sure it was still working, but this affects many code-paths so a more extensive testing regime may be required to make sure I haven't introduced any bugs.