Skip to content

Commit e875a2c

Browse files
author
Kenneth Reitz
committed
clean slate
1 parent b260547 commit e875a2c

File tree

3 files changed

+1
-338
lines changed

3 files changed

+1
-338
lines changed

github3/api.py

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -10,87 +10,3 @@
1010
1111
"""
1212

13-
14-
from . import models
15-
from .packages.anyjson import deserialize
16-
17-
import requests
18-
19-
20-
21-
22-
API_URL = 'https://api.github.com'
23-
API_MIME = 'application/vnd.github.v3+json'
24-
25-
26-
27-
28-
# =======
29-
# Helpers
30-
# =======
31-
32-
def _safe_response(r, error=None):
33-
34-
try:
35-
r.raise_for_status()
36-
return r
37-
except requests.HTTPError:
38-
if (r.status_code == 404) or (r.status_code == 401):
39-
raise LoginFailed
40-
else:
41-
raise APIError(error) if error else APIError
42-
43-
44-
def get(*path, **params):
45-
"""
46-
Accepts optional error parameter, which will be passed in the event of a
47-
non-401 HTTP error.
48-
49-
api.get('groups')
50-
api.get('groups', 'id')
51-
api.get('accounts', 'verify')
52-
"""
53-
54-
path = list(path)
55-
path.insert(0, '')
56-
57-
url = '{0}{1}'.format(API_URL, '/'.join(map(str, path)))
58-
print url
59-
# params = kwargs.get('params', None)
60-
61-
r = requests.get(url, params=params, auth=None)
62-
63-
return _safe_response(r)
64-
65-
66-
def post(params, *path):
67-
68-
path += API_URL
69-
url = '%s%s' % ('/'.join(map(str, path)), '.json')
70-
r = requests.post(url, params=params, auth=auth)
71-
return _safe_response(r)
72-
73-
74-
# ==========
75-
# Exceptions
76-
# ==========
77-
78-
class LoginFailed(RuntimeError):
79-
"""Login falied!"""
80-
81-
class APIError(RuntimeError):
82-
"""There was a problem properly accessing the Convore API."""
83-
84-
85-
86-
def login(username, password):
87-
"""Configured API Credentials"""
88-
global auth
89-
90-
auth = (username, password)
91-
# print requests.auth_manager.__dict__
92-
93-
# ==========
94-
# End Points
95-
# ==========
96-

github3/core.py

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -4,119 +4,7 @@
44
github3.core
55
~~~~~~~~~~~~
66
7-
This module contains the core GitHub 3 interface.
7+
This module contains the core GitHub3 interface.
88
99
"""
1010

11-
12-
from .api import API_URL, get
13-
import json
14-
import models
15-
# TODO: switch to anyjson
16-
17-
18-
class GitHub(object):
19-
"""Central GitHub object."""
20-
21-
rate_limit = None
22-
rate_left = None
23-
per_page = 30
24-
accept = 'application/vnd.github.v3+json'
25-
26-
def __init__(self, apiurl=API_URL):
27-
self.__basic_auth = None
28-
29-
30-
def _get(self, *path, **kwargs):
31-
"""optional json=False, paged=False"""
32-
33-
headers = {'Accept': self.accept}
34-
35-
is_json = kwargs.get('json', False)
36-
is_paged = kwargs.get('paged', False)
37-
38-
r = get(*path, auth=self.__basic_auth, headers=headers)
39-
40-
rate_left = r.headers.get('x-ratelimit-remaining', None)
41-
rate_limit = r.headers.get('x-ratelimit-limit', None)
42-
43-
if (rate_limit is not None) or (rate_left is not None):
44-
self.rate_limit = rate_limit
45-
self.rate_left = rate_left
46-
47-
if is_json:
48-
r = json.loads(r.content)
49-
50-
if is_paged:
51-
pass
52-
# TODO: paged support (__iter__)
53-
return r
54-
55-
56-
57-
def auth(self, username, password):
58-
self.__basic_auth = (username, password)
59-
return self.logged_in
60-
61-
62-
def oauth(self):
63-
# TODO: oAuth
64-
pass
65-
66-
67-
@property
68-
def logged_in(self):
69-
r = self._get('')
70-
print
71-
72-
if r.status_code == 200 and self.__basic_auth:
73-
return True
74-
else:
75-
return False
76-
77-
def repo(self, username, reponame):
78-
d = self._get('repos', username, '{0}.json'.format(reponame), json=True)
79-
80-
81-
repo = models.Repo()
82-
repo.from_dict(d)
83-
84-
return repo
85-
86-
87-
# {
88-
# "has_downloads": true,
89-
# "forks": 10,
90-
# "url": "https://api.github.com/repos/kennethreitz/requests.json",
91-
# "created_at": "2011-02-13T18:38:17Z",
92-
# "watchers": 166,
93-
# "description": "Python HTTP modules suck. This one doesn't.",
94-
# "master_branch": "develop",
95-
# "has_wiki": true,
96-
# "open_issues": 5,
97-
# "fork": false,
98-
# "html_url": "https://github.com/kennethreitz/requests",
99-
# "homepage": "http://pypi.python.org/pypi/requests/",
100-
# "has_issues": true,
101-
# "pushed_at": "2011-04-21T21:39:45Z",
102-
# "language": "Python",
103-
# "private": false,
104-
# "size": 2748,
105-
# "integrate_branch": null,
106-
# "owner": {
107-
# "email": "_@kennethreitz.com",
108-
# "type": "User",
109-
# "url": "https://api.github.com/users/kennethreitz.json",
110-
# "login": "kennethreitz",
111-
# "created_at": "2009-08-26T21:17:47Z",
112-
# "gravatar_url": "https://secure.gravatar.com/avatar/2eccc4005572c1e2b12a9c00580bc86f?s=30&d=https://d3nwyuy0nl342s.cloudfront.net%2Fimages%2Fgravatars%2Fgravatar-140.png",
113-
# "blog": "http://kennethreitz.com",
114-
# "name": "Kenneth Reitz",
115-
# "company": "NetApp, Inc",
116-
# "location": "Washington, DC"
117-
# },
118-
# "name": "requests"
119-
# }
120-
121-
# Default instance
122-
github = GitHub()

github3/models.py

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -8,144 +8,3 @@
88
99
"""
1010

11-
12-
class GitHubModel(object):
13-
14-
def __init__(self):
15-
pass
16-
17-
18-
19-
class User(GitHubModel):
20-
pass
21-
22-
def __init__(self):
23-
self.email = None
24-
self.type = None
25-
self.url = None
26-
self.login = None
27-
self.created_at = None
28-
self.gravatar_url = None
29-
self.blog = None
30-
self.name = None
31-
self.company = None
32-
self.location = None
33-
34-
def __repr__(self):
35-
return '<user \'{0}\'>'.format(self.login)
36-
37-
def from_dict(self, d):
38-
self.email = d.get('email', None)
39-
self.type = d.get('type', None)
40-
self.url = d.get('url', None)
41-
self.login = d.get('login', None)
42-
self.created_at = d.get('created_at', None)
43-
self.gravatar_url = d.get('gravatar_url', None)
44-
self.blog = d.get('blog', None)
45-
self.name = d.get('name', None)
46-
self.company = d.get('company', None)
47-
self.location = d.get('location', None)
48-
49-
50-
51-
52-
53-
54-
class Repo(GitHubModel):
55-
"""GitHub Repository."""
56-
57-
def __init__(self):
58-
self.has_downloads = None
59-
self.forks = None
60-
self.url = None
61-
self.created_at = None
62-
self.watchers = None
63-
self.description = None
64-
self.master_branch = None
65-
self.has_wiki = None
66-
self.open_issues = None
67-
self.fork = None
68-
self.html_url = None
69-
self.homepage = None
70-
self.has_issues = None
71-
self.pushed_at = None
72-
self.language = None
73-
self.private = None
74-
self.size = None
75-
self.integrate_branch = None
76-
self.owner = None
77-
self.name = None
78-
79-
def __repr__(self):
80-
return '<repo \'{0}/{1}\'>'.format(self.owner.login, self.name)
81-
82-
def from_dict(self, d):
83-
self.has_downloads = d.get('has_downloads', None)
84-
self.forks = d.get('forks', None)
85-
self.url = d.get('url', None)
86-
self.created_at = d.get('created_at', None)
87-
self.watchers = d.get('watchers', None)
88-
self.description = d.get('description', None)
89-
self.master_branch = d.get('master_branch', None)
90-
self.has_wiki = d.get('has_wiki', None)
91-
self.open_issues = d.get('open_issues', None)
92-
self.fork = d.get('fork', None)
93-
self.html_url = d.get('html_url', None)
94-
self.homepage = d.get('homepage', None)
95-
self.has_issues = d.get('has_issues', None)
96-
self.pushed_at = d.get('pushed_at', None)
97-
self.language = d.get('language', None)
98-
self.private = d.get('private', None)
99-
self.size = d.get('size', None)
100-
self.integrate_branch = d.get('integrate_branch', None)
101-
self.owner = User()
102-
self.owner.from_dict(d.get('owner', dict()))
103-
self.name = d.get('name', None)
104-
105-
106-
107-
class Gist(GitHubModel):
108-
"""GitHub Gist.
109-
110-
gist.files['filename.py']
111-
"""
112-
113-
def __init__(self):
114-
self.api_url = None
115-
116-
117-
118-
class GistComment(GitHubModel):
119-
"""GitHub GistComment."""
120-
121-
def __init__(self):
122-
pass
123-
124-
125-
class Issue(GitHubModel):
126-
127-
128-
def __init__(self):
129-
self.number = None
130-
self.updated_at = None
131-
self.closed_at = None
132-
self.labels = []
133-
self.title= None
134-
self.comments = []
135-
self.user = None
136-
self.body = None
137-
self.url = None
138-
self.state = None
139-
self.api_url = None
140-
141-
# api
142-
self.milestone = None
143-
self.assignee = None
144-
145-
146-
147-
class Milestone(GitHubModel):
148-
149-
def __init__(self):
150-
self.api_url = None
151-

0 commit comments

Comments
 (0)