Refactor into functions and patterns only

I just watched Dave's ElixirConf talk and it prompted me to think about refactoring this code after I had reviewed it a few days ago. No need to accept this, but I thought it did clean up the call path nicely and would make the DIGEST auth easier to implement.