Yep, scripting gradients is not well documented (or implemented in my opinion). You'll need to use scriptlistener to glean the correct code. Keep in mind, the start and end positions of the gradient will be hard coded. If you want to vary the gradient's position by the selection's size, set it each point relative to activeDocuments.selection.bounds
.
If you want to save a gradient for re-use, create a new layer and apply a gradient overlay. See this answer on the graphic design SE site for more details.