[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-merchant-demos] branch master updated: reducing code
From: |
gnunet |
Subject: |
[taler-taler-merchant-demos] branch master updated: reducing code |
Date: |
Wed, 22 Jul 2020 17:18:50 +0200 |
This is an automated email from the git hooks/post-receive script.
ms pushed a commit to branch master
in repository taler-merchant-demos.
The following commit(s) were added to refs/heads/master by this push:
new 4231d0d reducing code
4231d0d is described below
commit 4231d0d5bb576aa3d742a75567f017355496059e
Author: MS <ms@taler.net>
AuthorDate: Wed Jul 22 17:18:23 2020 +0200
reducing code
---
talermerchantdemos/donations/donations.py | 47 ++-----------------------------
1 file changed, 3 insertions(+), 44 deletions(-)
diff --git a/talermerchantdemos/donations/donations.py
b/talermerchantdemos/donations/donations.py
index c6c03e5..08b4cfe 100644
--- a/talermerchantdemos/donations/donations.py
+++ b/talermerchantdemos/donations/donations.py
@@ -32,6 +32,7 @@ import urllib
import uuid
from taler.util.talerconfig import TalerConfig
from urllib.parse import urljoin, parse_qsl
+from .httpcommon import backend_post, backend_get
LOGGER = logging.getLogger(__name__)
@@ -81,26 +82,7 @@ def err_abort(abort_status_code, **params):
# if something unexpected happens.
def backend_instanced_get(instance, endpoint, params):
backend_url = urljoin(BACKEND_BASE_URL, f"instances/{instance}/")
- headers = {"Authorization": "ApiKey " + APIKEY}
- try:
- resp = requests.get(
- urljoin(backend_url, endpoint), params=params, headers=headers
- )
- except requests.ConnectionError:
- err_abort(500, message="Could not establish connection to backend")
- try:
- response_json = resp.json()
- except ValueError:
- err_abort(500, message="Could not parse response from backend")
- if resp.status_code != 200:
- err_abort(
- 500,
- message="Backend returned error status",
- json=response_json,
- status_code=resp.status_code
- )
- return response_json
-
+ return backend_get(backend_url, endpoint, params)
##
# POST a request to the backend, and return a error
@@ -112,30 +94,7 @@ def backend_instanced_get(instance, endpoint, params):
# @return the backend response (JSON format).
def backend_instanced_post(instance, endpoint, json):
backend_url = urljoin(BACKEND_BASE_URL, f"instances/{instance}/")
- headers = {"Authorization": "ApiKey " + APIKEY}
- try:
- resp = requests.post(
- urljoin(backend_url, endpoint), json=json, headers=headers
- )
- except requests.ConnectionError:
- err_abort(500, message=f"Could not establish connection to backend
(url={url})")
- try:
- response_json = resp.json()
- except ValueError:
- err_abort(
- 500,
- message="Could not parse response from backend",
- status_code=resp.status_code
- )
- if resp.status_code != 200:
- err_abort(
- 500,
- message="Backend returned error status",
- json=response_json,
- status_code=resp.status_code
- )
- return response_json
-
+ return backend_post(backend_url, endpoint, params)
##
# Inspect GET arguments in the look for a parameter.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-merchant-demos] branch master updated: reducing code,
gnunet <=