Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
s00d committed Nov 24, 2022
1 parent 22c2921 commit fda96e8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
2 changes: 1 addition & 1 deletion onlinesimru/GetNumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get(
extension: bool = False,
number: bool = False,
):
_response = self._get(
_response = self._post(
f"/getNum",
{
"service": service,
Expand Down
2 changes: 1 addition & 1 deletion onlinesimru/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.17"
__version__ = "1.0.18"
47 changes: 19 additions & 28 deletions onlinesimru/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,25 @@ def _get(self, endpoint: str, params: dict = None):
raise RequestException(data.get("response"))
return data

# async def _post(self, endpoint: str, params: dict = None, path: str = None):
# files = None
#
# if path:
# async with aiofiles.open(path, 'rb') as content:
# files = await content.read()
# files = {'file': files}
#
# if params is None:
# params = {}
# params['apikey'] = self.apikey
# params['lang'] = self.lang
# params['dev_id'] = self.dev_id
# payload = {k: v for k, v in params.items() if v is not None}
#
# if 'attachments' in payload:
# payload['attachments'] = json.dumps(payload['attachments'])
#
# async with self._semaphore:
# async with aiohttp.ClientSession() as session:
# url = f'https://onlinesim.ru/api/' + endpoint + '.php'
# data = payload if not path else files
#
# logger.info(f'[POST]: url={url} | data={payload} | files={files}')
# async with session.post(url, headers=self.headers, data=data) as response:
# response.raise_for_status()
#
# return await response.json()
def _post(self, endpoint: str, params: dict = None):
if params is None:
params = {}
if self.apikey != "":
params["apikey"] = self.apikey
params["lang"] = self.lang
params["dev_id"] = self.dev_id
payload = {k: v for k, v in params.items() if v is not None}
response = httpx.post(
f"https://onlinesim.ru/api" + endpoint + ".php",
headers=self.headers,
json=payload,

)
data = response.json()
if "response" in data:
if str(data.get("response")) != "1":
raise RequestException(data.get("response"))
return data

async def getPrice(self, service: str):
return await self._get(f"/getPrice", {"service": service})

0 comments on commit fda96e8

Please sign in to comment.