From 660470df670ceab6e2bc83a39f64483a76ba846b Mon Sep 17 00:00:00 2001
From: vtexier <vit@free.fr>
Date: Wed, 11 Dec 2019 19:13:31 +0100
Subject: [PATCH] [fix] #58 fix reverse_url path bug

---
 duniterpy/api/client.py                 | 41 +++++++++++++------------
 examples/create_and_publish_identity.py |  4 +--
 examples/request_data.py                |  4 +--
 examples/request_data_async.py          |  4 +--
 examples/request_data_elasticsearch.py  |  4 +--
 examples/request_web_socket_block.py    |  4 +--
 examples/request_ws2p.py                |  6 ++--
 examples/save_revoke_document.py        |  4 +--
 examples/send_certification.py          |  4 +--
 examples/send_membership.py             |  4 +--
 examples/send_transaction.py            |  4 +--
 11 files changed, 43 insertions(+), 40 deletions(-)

diff --git a/duniterpy/api/client.py b/duniterpy/api/client.py
index 9392975d..9818f846 100644
--- a/duniterpy/api/client.py
+++ b/duniterpy/api/client.py
@@ -181,9 +181,9 @@ class API:
     """
 
     def __init__(
-            self,
-            connection_handler: endpoint.ConnectionHandler,
-            headers: Optional[dict] = None,
+        self,
+        connection_handler: endpoint.ConnectionHandler,
+        headers: Optional[dict] = None,
     ) -> None:
         """
         Asks a module in order to create the url used then by derivated classes.
@@ -207,8 +207,11 @@ class API:
 
         server, port = self.connection_handler.server, self.connection_handler.port
         if self.connection_handler.path:
-            url = "{scheme}://{server}:{port}/{path}".format(
-                scheme=scheme, server=server, port=port, path=path
+            url = "{scheme}://{server}:{port}/{api_path}".format(
+                scheme=scheme,
+                server=server,
+                port=port,
+                api_path=self.connection_handler.path,
             )
         else:
             url = "{scheme}://{server}:{port}/".format(
@@ -299,10 +302,10 @@ class Client:
     """
 
     def __init__(
-            self,
-            _endpoint: Union[str, endpoint.Endpoint],
-            session: ClientSession = None,
-            proxy: str = None,
+        self,
+        _endpoint: Union[str, endpoint.Endpoint],
+        session: ClientSession = None,
+        proxy: str = None,
     ) -> None:
         """
         Init Client instance
@@ -331,11 +334,11 @@ class Client:
         self.proxy = proxy
 
     async def get(
-            self,
-            url_path: str,
-            params: dict = None,
-            rtype: str = RESPONSE_JSON,
-            schema: dict = None,
+        self,
+        url_path: str,
+        params: dict = None,
+        rtype: str = RESPONSE_JSON,
+        schema: dict = None,
     ) -> Any:
         """
         GET request on self.endpoint + url_path
@@ -369,11 +372,11 @@ class Client:
         return result
 
     async def post(
-            self,
-            url_path: str,
-            params: dict = None,
-            rtype: str = RESPONSE_JSON,
-            schema: dict = None,
+        self,
+        url_path: str,
+        params: dict = None,
+        rtype: str = RESPONSE_JSON,
+        schema: dict = None,
     ) -> Any:
         """
         POST request on self.endpoint + url_path
diff --git a/examples/create_and_publish_identity.py b/examples/create_and_publish_identity.py
index a451502f..4b5ab771 100644
--- a/examples/create_and_publish_identity.py
+++ b/examples/create_and_publish_identity.py
@@ -8,8 +8,8 @@ from duniterpy.key import SigningKey
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
 # Here we use the secure BASIC_MERKLED_API (BMAS)
 BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
 
diff --git a/examples/request_data.py b/examples/request_data.py
index 68b67366..07abf02f 100644
--- a/examples/request_data.py
+++ b/examples/request_data.py
@@ -4,8 +4,8 @@ from duniterpy.api import bma
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
 # Here we use the secure BASIC_MERKLED_API (BMAS)
 BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
 
diff --git a/examples/request_data_async.py b/examples/request_data_async.py
index 77ad4992..7e1f1ba9 100644
--- a/examples/request_data_async.py
+++ b/examples/request_data_async.py
@@ -5,8 +5,8 @@ from duniterpy.api.client import Client
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
 # Here we use the secure BASIC_MERKLED_API (BMAS)
 BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
 
diff --git a/examples/request_data_elasticsearch.py b/examples/request_data_elasticsearch.py
index f389eadb..89bcd9ac 100644
--- a/examples/request_data_elasticsearch.py
+++ b/examples/request_data_elasticsearch.py
@@ -7,8 +7,8 @@ from duniterpy.api.client import Client
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
 # Here we use the secure BASIC_MERKLED_API (BMAS)
 ES_CORE_ENDPOINT = "ES_CORE_API g1-test.data.duniter.fr 443"
 ES_USER_ENDPOINT = "ES_USER_API g1-test.data.duniter.fr 443"
diff --git a/examples/request_web_socket_block.py b/examples/request_web_socket_block.py
index 4a05dac1..696c5be3 100644
--- a/examples/request_web_socket_block.py
+++ b/examples/request_web_socket_block.py
@@ -10,8 +10,8 @@ from duniterpy.api.client import Client
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
 # Here we use the secure BASIC_MERKLED_API (BMAS)
 BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
 
diff --git a/examples/request_ws2p.py b/examples/request_ws2p.py
index 6b8b7813..2001acb4 100644
--- a/examples/request_ws2p.py
+++ b/examples/request_ws2p.py
@@ -17,9 +17,9 @@ from duniterpy.api.client import Client
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
-# Here we use the WS2P API (WS2P [UUID] [DOMAIN] [PORT])
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
+# Here we use the WS2P API (WS2P [UUID] [DOMAIN] [PORT] [PATH])
 # You can find the UUID of a node with the /network/ws2p/heads BMA API request
 # or in your node user interface in the network view in the WS2PID column
 WS2P_ENDPOINT = "WS2P 96675302 g1-test.duniter.org 443"
diff --git a/examples/save_revoke_document.py b/examples/save_revoke_document.py
index ffac355d..4f4241cd 100644
--- a/examples/save_revoke_document.py
+++ b/examples/save_revoke_document.py
@@ -20,8 +20,8 @@ else:
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
 # Here we use the secure BASIC_MERKLED_API (BMAS)
 BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
 
diff --git a/examples/send_certification.py b/examples/send_certification.py
index 1b103c47..6f4eda41 100644
--- a/examples/send_certification.py
+++ b/examples/send_certification.py
@@ -10,8 +10,8 @@ from duniterpy.key import SigningKey
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
 # Here we use the secure BASIC_MERKLED_API (BMAS)
 BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
 
diff --git a/examples/send_membership.py b/examples/send_membership.py
index f259213d..1035c4ce 100644
--- a/examples/send_membership.py
+++ b/examples/send_membership.py
@@ -8,8 +8,8 @@ from duniterpy.key import SigningKey
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
 # Here we use the secure BASIC_MERKLED_API (BMAS)
 BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
 
diff --git a/examples/send_transaction.py b/examples/send_transaction.py
index fc34e869..333abb64 100644
--- a/examples/send_transaction.py
+++ b/examples/send_transaction.py
@@ -15,8 +15,8 @@ from duniterpy.key import SigningKey
 
 # CONFIG #######################################
 
-# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
-# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
+# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
+# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
 # Here we use the secure BASIC_MERKLED_API (BMAS)
 BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
 
-- 
GitLab