Refactor getApiKey method to be testable