Extract implementation of the client to allow embedding

Change-Id: I2de1e1ec1ef714c442fa45d72d66765c1aafd703
Reviewed-on: http://review.couchbase.org/29625
Tested-by: Sergey Avseyev <sergey.avseyev@gmail.com>
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>