Skip to content

Commit 4cfd932

Browse files
author
Kenneth Reitz
committed
core api
1 parent e31c743 commit 4cfd932

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

github3/api.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
github3.api
5+
~~~~~~~~~~~
6+
7+
This module provies the core GitHub3 API interface.
8+
"""
9+
10+
import omnijson as json
11+
12+
from .helpers import is_collection, to_python, to_api, get_scope
13+
14+
def GithubCore(object):
15+
pass
16+
17+
18+
@staticmethod
19+
def _resource_serialize(o):
20+
"""Returns JSON serialization of given object."""
21+
return json.dumps(o)
22+
23+
24+
@staticmethod
25+
def _resource_deserialize(s):
26+
"""Returns dict deserialization of a given JSON string."""
27+
28+
try:
29+
return json.loads(s)
30+
except ValueError:
31+
raise ResponseError('The API Response was not valid.')
32+
33+
34+
def _to_map(self, obj, iterable):
35+
"""Maps given dict iterable to a given Resource object."""
36+
37+
a = []
38+
39+
for it in iterable:
40+
a.append(obj.new_from_dict(it, rdd=self))
41+
42+
return a
43+
44+
45+
def _get_resources(self, key, obj, limit=None, **kwargs):
46+
"""GETs resources of given path, maps them to objects, and
47+
handles paging.
48+
"""
49+
pass
50+
51+
52+
def _get_resource(self, http_resource, obj, **kwargs):
53+
"""GETs API Resource of given path."""
54+
55+
item = self._get_http_resource(http_resource, params=kwargs)
56+
item = self._resource_deserialize(item)
57+
58+
return obj.new_from_dict(item, rdd=self)
59+
60+
61+
def _post_resource(self, http_resource, **kwargs):
62+
"""POSTs API Resource of given path."""
63+
64+
r = self._post_http_resource(http_resource, params=kwargs)
65+
66+
return r
67+
68+
def _delete_resource(self, http_resource):
69+
"""DELETEs API Resource of given path."""
70+
71+
r = self._delete_http_resource(http_resource)
72+
73+
if r['status'] in ('200', '204'):
74+
return True
75+
else:
76+
return False
77+
78+
79+
80+
class Github(GithubCore):
81+
"""docstring for Github"""
82+
83+
def __init__(self):
84+
super(Github, self).__init__()
85+
86+
87+
88+
89+
class ResponseError(Exception):
90+
"""The API Response was unexpected."""
91+

0 commit comments

Comments
 (0)