diff --git a/duniterpy/api/client.py b/duniterpy/api/client.py index 1599fbfeb0c23393615c52fb7ece21d62694e567..1df294cc2df29953c9bb6dcd4a0646dc2ff91f62 100644 --- a/duniterpy/api/client.py +++ b/duniterpy/api/client.py @@ -1,13 +1,13 @@ # Authors: # Caner Candan <caner@candan.fr>, http://caner.candan.fr # Inso <insomniak.fr at gmail.com> - +from typing import Callable import json import logging import aiohttp import jsonschema from .errors import DuniterError -from duniterpy.api.endpoint import endpoint +import duniterpy.api.endpoint as endpoint logger = logging.getLogger("duniter") @@ -180,7 +180,7 @@ class Client: :param proxy: Proxy server as hostname:port """ # Endpoint Protocol detection - self.endpoint = endpoint(_endpoint) + self.endpoint = endpoint.endpoint(_endpoint) # if no user session... if session is None: @@ -219,3 +219,14 @@ class Client: """ await self.session.close() + async def __call__(self, _function: Callable, *args: any, **kwargs: any) -> any: + """ + Call the _function given with the args given + So we can have use many packages wrapping a REST API + + :param _function: The function to call + :param args: The parameters + :param kwargs: The key/value parameters + :return: + """ + return await _function(self, *args, **kwargs) diff --git a/examples/request_data.py b/examples/request_data.py index baac93dbeb0ff7a3131b17c7be6b3cfa4971d020..472235169c65a99a9c6108e6fcf55c2a918a481a 100644 --- a/examples/request_data.py +++ b/examples/request_data.py @@ -24,19 +24,19 @@ async def main(): print(response) # Get the node summary infos by dedicated method (with json schema validation) - response = await bma.node.summary(client) + response = await client(bma.node.summary) print(response) # Get the money parameters located in the first block - response = await bma.blockchain.parameters(client) + response = await client(bma.blockchain.parameters) print(response) # Get the current block - response = await bma.blockchain.current(client) + response = await client(bma.blockchain.current) print(response) # Get the block number 10 - response = await bma.blockchain.block(client, 10) + response = await client(bma.blockchain.block, 10) print(response) # Close client aiohttp session