Last active
March 23, 2017 08:50
-
-
Save renesansz/d4d7ba80b5b0b32c446a4b90666c11a2 to your computer and use it in GitHub Desktop.
Github API Provider Factory
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('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