Skip to content

Instantly share code, notes, and snippets.

@renesansz
Last active March 23, 2017 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renesansz/d4d7ba80b5b0b32c446a4b90666c11a2 to your computer and use it in GitHub Desktop.
Save renesansz/d4d7ba80b5b0b32c446a4b90666c11a2 to your computer and use it in GitHub Desktop.
Github API Provider Factory
angular.module('app.services', [])
.factory('GithubProvider', ['$http', '$q', function($http, $q){
return {
fetchUser: fetchUser,
fetchRepo: fetchRepo
};
/**
* Fetch users
*/
function fetchUser(username) {
var d = $q.defer();
if ( ! username) {
username = '';
} else {
username = '/' + username;
}
$http({
url: 'https://api.github.com/users' + username,
method: 'GET'
}).then(function (res) {
d.resolve(res);
}).catch(function (err) {
d.reject(err);
});
return d.promise;
}
/**
* Fetch user public repo
*/
function fetchRepo(repo) {
var d = $q.defer();
$http({
url: repo,
method: 'GET'
}).then(function (res) {
d.resolve(res);
}).catch(function (err) {
d.reject(err);
});
return d.promise;
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment