Skip to content

Commit 696ecc9

Browse files
authored
Merge pull request #38 from khornberg/feature/new-data
Version: 0.9.0
2 parents 9f90ddd + 9dd47a5 commit 696ecc9

File tree

9 files changed

+41736
-10732
lines changed

9 files changed

+41736
-10732
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ include tox.ini .travis.yml
1919
include requirements.txt
2020
include .pyup.yml
2121
include *.json
22+
include *.sh
2223

2324
global-exclude *.py[cod] __pycache__ *.so *.dylib

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def read(*names, **kwargs):
2121

2222
setup(
2323
name='octokitpy',
24-
version='0.8.0',
24+
version='0.9.0',
2525
license='MIT license',
2626
description='Python client for GitHub API',
2727
long_description='%s\n%s' % (

src/octokit/__init__.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515

1616
class Base(object):
1717

18-
headers = {'accept': 'application/vnd.github.v3+json', 'Content-Type': 'application/json'}
1918
base_url = 'https://api.github.com'
2019

21-
def _get_headers(self, definition):
22-
return dict(ChainMap(definition.get('headers', {}), self.headers))
20+
def __init__(self):
21+
self.headers = {'accept': 'application/vnd.github.v3+json', 'Content-Type': 'application/json'}
22+
23+
def _get_headers(self, method_headers):
24+
return dict(ChainMap(method_headers, self.headers))
2325

2426
def _validate(self, kwargs, params):
2527
cached_kwargs = dict(ChainMap(kwargs, self._attribute_cache['url']))
@@ -155,7 +157,8 @@ def _auth(self, requests_kwargs):
155157
class Octokit(Base):
156158

157159
def __init__(self, *args, **kwargs):
158-
self._create(utils.get_json_data('rest.json'))
160+
super().__init__()
161+
self._create(utils.get_json_data('index.json'))
159162
self._setup_authentication(kwargs)
160163
self._attribute_cache = defaultdict(dict)
161164

@@ -167,21 +170,23 @@ def _create(self, definitions):
167170

168171
def _create_client(self, name, methods):
169172
class_attributes = {}
170-
for _name, method in methods.items():
171-
method_name = utils.snake_case(str(_name))
172-
class_attributes.update({method_name: self._create_method(method_name, method)})
173+
for method in methods:
174+
for method_name in [utils.snake_case(str(method['name'])), utils.snake_case(str(method['idName']))]:
175+
class_attributes.update({method_name: self._create_method(method_name, method)})
173176
bases = [object]
174177
cls = type(name, tuple(bases), class_attributes)
175178
return cls
176179

177180
def _create_method(self, name, definition):
178181

179182
def _api_call(*args, **kwargs):
180-
self._validate(kwargs, definition.get('params'))
183+
method_headers = kwargs.pop('headers') if kwargs.get('headers') else {}
184+
parameter_map = utils.parameter_transform(definition.get('params'))
185+
self._validate(kwargs, parameter_map)
181186
method = definition['method'].lower()
182-
requests_kwargs = {'headers': self._get_headers(definition)}
183-
url, data_kwargs = self._form_url(kwargs, definition['url'], definition.get('params'))
184-
requests_kwargs.update(self._data(data_kwargs, definition.get('params'), method))
187+
requests_kwargs = {'headers': self._get_headers(method_headers)}
188+
url, data_kwargs = self._form_url(kwargs, definition['path'], parameter_map)
189+
requests_kwargs.update(self._data(data_kwargs, parameter_map, method))
185190
requests_kwargs.update(self._auth(requests_kwargs))
186191
_response = getattr(requests, method)(url, **requests_kwargs)
187192
try:

0 commit comments

Comments
 (0)