I think my stackoverflow search-fu is broken today, because it can't be that I'm the only one who's ever asked this. Cripes, I hope not, because I could really use some help figuring this out. Switching between data-sources is the big part, but 'best way to abstract' is the logical next-question on this, too.
Anyway: I have something like three dozen widgets. Each widget has one of three data sources (API-full, API-short, json file). I'll have users just coming in from the intarnets, users with a sales-provided temporary login, and users who've logged in with their own API key.
- no login = dummy data/json
- temp login = data from abridged endpoint
- API key = full data set endpoint
Logicking this out, I'll have $scope.access for user access + $scope.widget for which widget the user clicked. Falling back on old functional habits, it seems like I could use those two in a case break, and return a value for the appropriate endpoint. But I can't seem to get a variable to work the $http call, like this:
$http.get($scope.call).success(function(data) {
$scope.group = data;
});
So my question boils down to:
What's the best way (or can I) re-use an $http with a variable, so I can just insert the variable and not have to do a separate $http for every combination?
How should I (or should I) abstract this logic and get this out of my controller?
What would be really excellent is just something I could call in my controller, maybe like so:
var X = getEndpoint($scope.access, $scope.widget);
var Y = getEndpoint($scope.access, $scope.widget);
var Z = getEndpoint($scope.access, $scope.widget);
and the rest be hidden under the hood elsewhere. Any ideas on how to tackle this?
Many thanks in advance.