Refactored links from JSON API.

The tests didn't change significantly but the code is easier to
understand now.
Merge branch 'refactor_relations' into projects