Skip to content

Commit

Permalink
switch to Restangular
Browse files Browse the repository at this point in the history
  • Loading branch information
kultpower committed Jan 20, 2014
1 parent ff0af8a commit bfbe7ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
22 changes: 5 additions & 17 deletions app/scripts/services/gamesService.js
@@ -1,30 +1,18 @@
'use strict';

angular.module('oregamiClientApp')
.service('gamesService', [ 'mySettings' , '$http', function gamesService($mySettings, $http) {
.service('gamesService', [ '$http', 'Restangular',
function gamesService($http, Restangular) {

return {
test: function(callback) {
console.log('gamesService.test() called');
},
getGames: function() {
// $http returns a promise, which has a then function, which also returns a promise
var url = $mySettings.apiUri + '/games';
if (getCookie("customUrl")!=null && getCookie("customUrl").length>1 ) {
url = getCookie("customUrl") + '/games'
}
console.log('gamesService.test() called => ' + url);
var promise = $http.get(url).then(function (response) {
// The then function here is an opportunity to modify the response
console.log(url + '->' + response);
// The return value gets picked up by the then in the controller.
return response.data;
});
// Return the promise to the controller
return promise;
} ,
return Restangular.all("games").getList();
}
/*
updateGame: function(game) {
,updateGame: function(game) {
var url = $mySettings.apiUri + '/games';
if (game.id==null) {
$http({
Expand Down
17 changes: 3 additions & 14 deletions app/scripts/services/regionService.js
@@ -1,22 +1,11 @@
'use strict';

angular.module('oregamiClientApp')
.service('regionService', ['mySettings', '$http', function regionService($mySettings, $http) {
.service('regionService', ['$http', 'Restangular',
function regionService( $http, Restangular) {
return {
getRegions: function() {
// $http returns a promise, which has a then function, which also returns a promise
var url = $mySettings.apiUri + '/region';
if (getCookie("customUrl")!=null && getCookie("customUrl").length>1 ) {
url = getCookie("customUrl") + '/region'
}
var promise = $http.get(url).then(function (response) {
// The then function here is an opportunity to modify the response
console.log(url + '->' + response);
// The return value gets picked up by the then in the controller.
return response.data;
});
// Return the promise to the controller
return promise;
return Restangular.all("region").getList();
}
}
}]);

0 comments on commit bfbe7ef

Please sign in to comment.