Read about our upcoming Code of Conduct on this issue

Commit d5e055d5 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Project: new api_request() method

Amazingly, the `owner_api_request()` shortcut was all we needed
for a long time, but we'll now will need to be able to pass the
user explicitely.
parent a2feeb18f2de
......@@ -97,8 +97,8 @@ class Project(object):
def owner_api_hg_heptapod_config(self):
return self.owner_api_get(subpath='hg_heptapod_config')
def owner_api_request(self, method, subpath='', **kwargs):
"""Perform a simple API HTTP request as the owner.
def api_request(self, method, user, subpath='', **kwargs):
"""Perform a simple API HTTP request as the given user.
`method` is the HTTP method to use, same as in `requests.request`.
......@@ -110,37 +110,44 @@ class Project(object):
All kwargs are passed to `requests.request()`
"""
headers = kwargs.pop('headers', {})
headers['Private-Token'] = self.owner_token
headers['Private-Token'] = user.token
return requests.request(method,
'/'.join((self.api_url, subpath)),
headers=headers,
**kwargs)
def owner_api_request(self, method, *args, **kwargs):
"""Perform a simple API HTTP request as the owner.
See :meth:`api_request` for more details.
"""
return self.api_request(method, self.owner_user, *args, **kwargs)
def owner_api_get(self, **kwargs):
"""Perform a simple HTTP API GET as the owner.
See `owner_api_request` for details.
See :meth:`api_request` for details.
"""
return self.owner_api_request('GET', **kwargs)
def owner_api_put(self, **kwargs):
"""Perform a simple HTTP API PUT as the owner.
See `owner_api_request` for details.
See :meth:`api_request` for details.
"""
return self.owner_api_request('PUT', **kwargs)
def owner_api_post(self, **kwargs):
"""Perform a simple HTTP API POST as the owner.
See `owner_api_request` for details.
See :meth:`api_request` for details.
"""
return self.owner_api_request('POST', **kwargs)
def owner_api_delete(self, **kwargs):
"""Perform a simple HTTP API DELETE as the owner.
See `owner_api_request` for details.
See :meth:`api_request` for details.
"""
return self.owner_api_request('DELETE', **kwargs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment