blob: e0703a5b4c0741430158eff0d2a305550578b7bb (
plain) (
blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# -*- coding: utf-8 -*-
"""
github3.core
~~~~~~~~~~~~
This module contains the core GitHub 3 interface.
"""
from .api import API_URL, get
class GitHub(object):
"""Central GitHub object."""
rate_limit = None
rate_left = None
per_page = 30
def __init__(self, apiurl=API_URL):
self.__basic_auth = None
def _get(self, *path):
r = get(*path, auth=self.__basic_auth)
rate_limit = r.headers.get('x-ratelimit-remaining', None)
rate_left = r.headers.get('x-ratelimit-limit', None)
if (rate_limit is not None) or (rate_left is not None):
self.rate_limit = rate_limit
self.rate_left = rate_left
return r
def auth(self, username, password):
self.__basic_auth = (username, password)
return self.logged_in
def oauth(self):
# TODO: oAuth
pass
@property
def logged_in(self):
r = self._get('')
# print r
if r.status_code == 200:
return True
else:
return False
# Default instance
github = GitHub()
|