remove duplication in api.rb