-
Notifications
You must be signed in to change notification settings - Fork 0
/
GithubApi.py
37 lines (30 loc) · 1.13 KB
/
GithubApi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import logging
from requests.auth import HTTPBasicAuth
import requests
logger = logging.getLogger()
class GithubApi(object):
__HOST = "http://api.github.com/repos"
def __init__(self, username, password):
self.username = username
self.password = password
self.logger = logging.getLogger(__name__)
def _get_auth(self):
return HTTPBasicAuth(self.username, self.password)
def _get_github_response(self, url, headers=None):
host = self.__HOST
url = host + "/" + url
auth = self._get_auth()
if headers:
resp = requests.get(url, auth=auth, headers=headers)
else:
resp = requests.get(url, auth=auth)
return resp
def repoDetails(self,url):
logger.info("Start with API: repoDetails")
response = self._get_github_response(url)
return response.json()
def starGazerDetails(self,url):
logger.info("Start with API: starGazerDetails")
headers = {"Accept": "application/vnd.github.v3.star+json"}
response = self._get_github_response(url, headers = headers)
return response.json()