@@ -38,34 +38,25 @@ def _get(self, endpoint: str, params: dict = None):
38
38
raise RequestException (data .get ("response" ))
39
39
return data
40
40
41
- # async def _post(self, endpoint: str, params: dict = None, path: str = None):
42
- # files = None
43
- #
44
- # if path:
45
- # async with aiofiles.open(path, 'rb') as content:
46
- # files = await content.read()
47
- # files = {'file': files}
48
- #
49
- # if params is None:
50
- # params = {}
51
- # params['apikey'] = self.apikey
52
- # params['lang'] = self.lang
53
- # params['dev_id'] = self.dev_id
54
- # payload = {k: v for k, v in params.items() if v is not None}
55
- #
56
- # if 'attachments' in payload:
57
- # payload['attachments'] = json.dumps(payload['attachments'])
58
- #
59
- # async with self._semaphore:
60
- # async with aiohttp.ClientSession() as session:
61
- # url = f'https://onlinesim.ru/api/' + endpoint + '.php'
62
- # data = payload if not path else files
63
- #
64
- # logger.info(f'[POST]: url={url} | data={payload} | files={files}')
65
- # async with session.post(url, headers=self.headers, data=data) as response:
66
- # response.raise_for_status()
67
- #
68
- # return await response.json()
41
+ def _post (self , endpoint : str , params : dict = None ):
42
+ if params is None :
43
+ params = {}
44
+ if self .apikey != "" :
45
+ params ["apikey" ] = self .apikey
46
+ params ["lang" ] = self .lang
47
+ params ["dev_id" ] = self .dev_id
48
+ payload = {k : v for k , v in params .items () if v is not None }
49
+ response = httpx .post (
50
+ f"https://onlinesim.ru/api" + endpoint + ".php" ,
51
+ headers = self .headers ,
52
+ json = payload ,
53
+
54
+ )
55
+ data = response .json ()
56
+ if "response" in data :
57
+ if str (data .get ("response" )) != "1" :
58
+ raise RequestException (data .get ("response" ))
59
+ return data
69
60
70
61
async def getPrice (self , service : str ):
71
62
return await self ._get (f"/getPrice" , {"service" : service })
0 commit comments