Skip to content

Commit 0a75e37

Browse files
committed
Initial documentation for the binding objects.
Closes #70.
1 parent 0e76861 commit 0a75e37

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

doc/api/core.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ Core
3030

3131
.. autofunction:: repr_string
3232

33-
.. autoclass:: GithubCommand(type)
33+
.. autoclass:: GithubCommand
3434

35-
.. autoclass:: Attribute(type)
35+
.. autoclass:: Attribute
3636

37-
.. autoclass:: DateAttribute(type)
37+
.. autoclass:: DateAttribute(help, format)
3838

39-
.. autoclass:: BaseDataType(type)
39+
.. autoclass:: BaseData()

github2/core.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,24 @@ def enhanced_by_auth(f):
137137
class GithubCommand(object):
138138

139139
def __init__(self, request):
140+
"""Main API binding interface
141+
142+
:param github2.request.GithubRequest request: HTTP request handler
143+
"""
140144
self.request = request
141145

142146
def make_request(self, command, *args, **kwargs):
147+
"""Make an API request
148+
149+
Various options are supported if they exist in ``kwargs``:
150+
151+
* The value of a ``method`` argument will define the HTTP method
152+
to perform for this request, the default is ``GET``
153+
* The value of a ``filter`` argument will restrict the response to that
154+
data
155+
* The value of a ``page`` argument will be used to fetch a specific
156+
page of results, default of 1 is assumed if not given
157+
"""
143158
filter = kwargs.get("filter")
144159
post_data = kwargs.get("post_data") or {}
145160
page = kwargs.pop("page", 1)
@@ -162,6 +177,11 @@ def make_request(self, command, *args, **kwargs):
162177
return response
163178

164179
def get_value(self, *args, **kwargs):
180+
"""Process a single-value response from the API
181+
182+
If a ``datatype`` parameter is given it defines the
183+
:class:`BaseData`-derived class we should build from the provided data
184+
"""
165185
datatype = kwargs.pop("datatype", None)
166186
value = self.make_request(*args, **kwargs)
167187
if datatype:
@@ -176,6 +196,10 @@ def get_value(self, *args, **kwargs):
176196
return value
177197

178198
def get_values(self, *args, **kwargs):
199+
"""Process a multi-value response from the API
200+
201+
:see: :meth:`get_value`
202+
"""
179203
datatype = kwargs.pop("datatype", None)
180204
values = self.make_request(*args, **kwargs)
181205
if datatype:
@@ -208,8 +232,11 @@ def bullet(title, text):
208232

209233

210234
class Attribute(object):
211-
212235
def __init__(self, help):
236+
"""Generic object attribute for use with :class:`BaseData`
237+
238+
:param str help: Attribute description
239+
"""
213240
self.help = help
214241

215242
def to_python(self, value):
@@ -228,6 +255,11 @@ class DateAttribute(Attribute):
228255
}
229256

230257
def __init__(self, *args, **kwargs):
258+
"""Date handling attribute for use with :class:`BaseData`
259+
260+
:param str format: The date format to support, see
261+
:data:`convertor_for_format` for supported options
262+
"""
231263
self.format = kwargs.pop("format", self.format)
232264
super(DateAttribute, self).__init__(*args, **kwargs)
233265

@@ -281,6 +313,12 @@ def iterate(self):
281313
# Ugly base class definition for Python 2 and 3 compatibility, where metaclass
282314
# syntax is incompatible
283315
class BaseData(BaseDataType('BaseData', (object, ), {})):
316+
"""Wrapper for API responses
317+
318+
.. warning::
319+
Supports subscript attribute access purely for backwards compatibility,
320+
you shouldn't rely on that functionality in new code
321+
"""
284322
def __getitem__(self, key):
285323
"""Access objects's attribute using subscript notation
286324
@@ -297,7 +335,7 @@ def __getitem__(self, key):
297335
def __setitem__(self, key, value):
298336
"""Update object's attribute using subscript notation
299337
300-
:see: ``BaseData.__getitem__``
338+
:see: :meth:`BaseData.__getitem__`
301339
"""
302340
LOGGER.warning("Subscript access on %r is deprecated, use object "
303341
"attributes" % self.__class__.__name__,

0 commit comments

Comments
 (0)