Reduce duplicate code; add rudimentary test for a cloud API.