Skip to content

Instantly share code, notes, and snippets.

@mmourafiq
Created August 19, 2013 20:39
Show Gist options
  • Save mmourafiq/6273880 to your computer and use it in GitHub Desktop.
Save mmourafiq/6273880 to your computer and use it in GitHub Desktop.
Blog.factory('TagService', function ($http, $q) {
var api_url = "/tags/";
var api_suffixe = "/posts/";
return {
get: function(tag_id){
var url = api_url + tag_id+ "/";
var defer = $q.defer();
$http({method: 'GET', url: url}).
success(function(data, status, headers, config) {
defer.resolve(data);
}).
error(function(data, status, headers, config) {
defer.reject(status);
});
return defer.promise;
},
list: function(){
var defer = $q.defer();
$http({method: 'GET', url: api_url}).
success(function(data, status, headers, config) {
defer.resolve(data);
}).
error(function(data, status, headers, config) {
defer.reject(status);
});
return defer.promise;
},
query: function(text){
var url = api_url + '?q=' + text;
var defer = $q.defer();
$http({method: 'GET', url: url}).
success(function(data, status, headers, config) {
defer.resolve(data);
}).
error(function(data, status, headers, config) {
defer.reject(status);
});
return defer.promise;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment