1515
1616class 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):
155157class 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