Created
February 5, 2015 15:45
Blogin App services step 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('starter.services', []) | |
.factory('Categories', ['$http', '$q', function($http, $q) { | |
//Endpoints Variables. | |
var categoriesEndpoint = '', | |
categoryEndpoint = ''; | |
return { | |
/* | |
* Return All Categories. | |
*/ | |
all: function() { | |
var defer = $q.defer(); | |
$http({ | |
method : 'GET', | |
url : categoriesEndpoint, | |
dataType : 'json' | |
}) | |
.success(function(data, status, headers, config){ | |
defer.resolve(data); | |
}) | |
.error(function(data, status, headers, config){ | |
defer.reject(data); | |
}); | |
return defer.promise; | |
}, | |
/* | |
* Return Category by ID. | |
*/ | |
get: function(catId) { | |
var defer = $q.defer(); | |
$http({ | |
method : 'GET', | |
url : categoryEndpoint + catId, | |
dataType : 'json' | |
}) | |
.success(function(data, status, headers, config){ | |
defer.resolve(data); | |
}) | |
.error(function(data, status, headers, config){ | |
defer.reject(data); | |
}); | |
return defer.promise; | |
} | |
} | |
}]) | |
.factory('Articles', ['$http', '$q', function($http, $q) { | |
//Endpoints Variables. | |
var blogEndpoint = '', | |
articleEndpoint = ''; | |
return { | |
/* | |
* Return All Articles. | |
*/ | |
all: function() { | |
var defer = $q.defer(); | |
$http({ | |
method : 'GET', | |
url : blogEndpoint, | |
dataType : 'json' | |
}) | |
.success(function(data, status, headers, config){ | |
defer.resolve(data); | |
}) | |
.error(function(data, status, headers, config){ | |
defer.reject(data); | |
}); | |
return defer.promise; | |
}, | |
/* | |
* Return Article by ID. | |
*/ | |
get: function(articleId) { | |
var defer = $q.defer(); | |
$http({ | |
method : 'GET', | |
url : articleEndpoint + articleId, | |
dataType : 'json' | |
}) | |
.success(function(data, status, headers, config){ | |
defer.resolve(data); | |
}) | |
.error(function(data, status, headers, config){ | |
defer.reject(data); | |
}); | |
return defer.promise; | |
} | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment