move all API related code into StackApi class