diff options
Diffstat (limited to 'addons/google_account')
| -rw-r--r-- | addons/google_account/__init__.py | 1 | ||||
| -rw-r--r-- | addons/google_account/models/google_service.py | 26 |
2 files changed, 11 insertions, 16 deletions
diff --git a/addons/google_account/__init__.py b/addons/google_account/__init__.py index 314d8d4bff4..9afb106a80f 100644 --- a/addons/google_account/__init__.py +++ b/addons/google_account/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. + from . import models from . import controllers diff --git a/addons/google_account/models/google_service.py b/addons/google_account/models/google_service.py index 86d099eb745..5a69f35bd2f 100644 --- a/addons/google_account/models/google_service.py +++ b/addons/google_account/models/google_service.py @@ -8,10 +8,7 @@ import logging import requests from werkzeug import urls -from odoo import api, fields, models, registry, _ -from odoo.exceptions import UserError -from odoo.http import request - +from odoo import api, fields, models, _ _logger = logging.getLogger(__name__) @@ -113,7 +110,7 @@ class GoogleService(models.AbstractModel): 'redirect_uri': base_url + '/google_account/authentication' } try: - dummy, response, dummy = self._do_request(GOOGLE_TOKEN_ENDPOINT, params=data, headers=headers, type='POST', preuri='') + dummy, response, dummy = self._do_request(GOOGLE_TOKEN_ENDPOINT, params=data, headers=headers, method='POST', preuri='') access_token = response.get('access_token') refresh_token = response.get('refresh_token') ttl = response.get('expires_in') @@ -122,14 +119,13 @@ class GoogleService(models.AbstractModel): error_msg = _("Something went wrong during your token generation. Maybe your Authorization Code is invalid") raise self.env['res.config.settings'].get_config_warning(error_msg) - # TODO JEM : remove preuri param, and rename type into method @api.model - def _do_request(self, uri, params=None, headers=None, type='POST', preuri="https://www.googleapis.com", timeout=TIMEOUT): + def _do_request(self, uri, params=None, headers=None, method='POST', preuri="https://www.googleapis.com", timeout=TIMEOUT): """ Execute the request to Google API. Return a tuple ('HTTP_CODE', 'HTTP_RESPONSE') :param uri : the url to contact :param params : dict or already encoded parameters for the request to make :param headers : headers of request - :param type : the method to use to make the request + :param method : the method to use to make the request :param preuri : pre url to prepend to param uri. """ if params is None: @@ -137,16 +133,16 @@ class GoogleService(models.AbstractModel): if headers is None: headers = {} - _logger.debug("Uri: %s - Type : %s - Headers: %s - Params : %s !", (uri, type, headers, params)) + _logger.debug("Uri: %s - Type : %s - Headers: %s - Params : %s !", (uri, method, headers, params)) ask_time = fields.Datetime.now() try: - if type.upper() in ('GET', 'DELETE'): - res = requests.request(type.lower(), preuri + uri, params=params, timeout=timeout) - elif type.upper() in ('POST', 'PATCH', 'PUT'): - res = requests.request(type.lower(), preuri + uri, data=params, headers=headers, timeout=timeout) + if method.upper() in ('GET', 'DELETE'): + res = requests.request(method.lower(), preuri + uri, params=params, timeout=timeout) + elif method.upper() in ('POST', 'PATCH', 'PUT'): + res = requests.request(method.lower(), preuri + uri, data=params, headers=headers, timeout=timeout) else: - raise Exception(_('Method not supported [%s] not in [GET, POST, PUT, PATCH or DELETE]!') % (type)) + raise Exception(_('Method not supported [%s] not in [GET, POST, PUT, PATCH or DELETE]!') % (method)) res.raise_for_status() status = res.status_code @@ -160,8 +156,6 @@ class GoogleService(models.AbstractModel): except: pass except requests.HTTPError as error: - # if error.response.status_code == 401: - # raise InvalidToken if error.response.status_code in (204, 404): status = error.response.status_code response = "" |
