Add an api_call method to the MspAccount model (refs #5573)
This commit is contained in:
parent
00feb5836c
commit
0c681581e2
10
models.py
10
models.py
|
@ -1,7 +1,9 @@
|
|||
import requests
|
||||
import json
|
||||
import logging
|
||||
import urlparse
|
||||
|
||||
from requests_oauthlib import OAuth2Session
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
|
@ -14,6 +16,14 @@ class MspAccount(models.Model):
|
|||
agc = models.CharField(max_length=64, verbose_name=_('access grant code'))
|
||||
token = models.TextField(verbose_name=_('access token'))
|
||||
|
||||
def api_call(self, api_path, method='get', **kwargs):
|
||||
url = urlparse.urljoin(app_settings.api_url, api_path)
|
||||
session = OAuth2Session(app_settings.client_id,
|
||||
token=self.token)
|
||||
return getattr(session, method)(url,
|
||||
verify=app_settings.verify_certificate,
|
||||
cert=app_settings.client_certificate, **kwargs)
|
||||
|
||||
def refresh_token(self):
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
Reference in New Issue