Skip to content

[EXC-782] - Added Types #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "firefly_exchange_client"
version = "0.2.2"
version = "0.3.0"
description = "Library to interact with firefly exchange protocol including its off-chain api-gateway and on-chain contracts"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
32 changes: 17 additions & 15 deletions src/firefly_exchange_client/api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
from .interfaces import *

class APIService():
def __init__(self, url):
def __init__(self, url:str) -> None:
self.server_url = url
self.auth_token = None
self.client = aiohttp.ClientSession()

async def close_session(self):
async def close_session(self) -> None:
if self.client is not None:
return await self.client.close()

async def get(self, service_url, query={}, auth_required=False):
async def get(self, service_url:str, query:dict={}, auth_required:bool=False) -> dict:
"""
Makes a GET request and returns the results
Inputs:
- service_url(str): the url to make the request to.
- query(dict): the get query.
- auth_required(bool): indicates whether authorization is required for the call or not.
- service_url: the url to make the request to.
- query: the get query.
- auth_required: indicates whether authorization is required for the call or not.
"""
url = self._create_url(service_url)

Expand All @@ -35,13 +35,13 @@ async def get(self, service_url, query={}, auth_required=False):
except:
raise Exception("Error while getting {}: {}".format(url, response))

async def post(self, service_url, data, auth_required=False):
async def post(self, service_url:str, data:dict, auth_required:bool=False) -> dict:
"""
Makes a POST request and returns the results
Inputs:
- service_url(str): the url to make the request to.
- data(dict): the data to post with POST request.
- auth_required(bool): indicates whether authorization is required for the call or not.
- service_url: the url to make the request to.
- data: the data to post with POST request.
- auth_required: indicates whether authorization is required for the call or not.
"""
url = self._create_url(service_url)
response = None
Expand All @@ -59,13 +59,13 @@ async def post(self, service_url, data, auth_required=False):
except:
raise Exception("Error while posting to {}: {}".format(url, response))

async def delete(self,service_url, data, auth_required=False):
async def delete(self,service_url:str, data:dict, auth_required:bool=False) -> dict:
"""
Makes a DELETE request and returns the results
Inputs:
- service_url(str): the url to make the request to.
- data(dict): the data to post with POST request.
- auth_required(bool): indicates whether authorization is required for the call or not.
- service_url: the url to make the request to.
- data: the data to post with POST request.
- auth_required: indicates whether authorization is required for the call or not.
"""
url = self._create_url(service_url)

Expand All @@ -86,8 +86,10 @@ async def delete(self,service_url, data, auth_required=False):
'''
Private methods
'''
def _create_url(self, path):
def _create_url(self, path:str) -> str:
"""
Appends namespace to server url
Inputs:
- path: the route name/path
"""
return "{}{}".format(self.server_url, path)
Loading