Skip to content

Commit

Permalink
Support POST endpoints with query vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeo committed Nov 22, 2023
1 parent 347f34b commit 6fede62
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions preston/preston.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,11 @@ def get_path(self, path: str, data: dict) -> Tuple[dict, dict]:
if cached_data:
return cached_data
self._try_refresh_access_token()
r = self.session.get(target_url)
self.cache.set(r)
return r.json()
resp = self.session.get(target_url)
self.cache.set(resp)
if resp.text:
return resp.json()
return None

def get_op(self, id: str, **kwargs: str) -> dict:
"""Queries the ESI by looking up an operation id.
Expand Down Expand Up @@ -357,10 +359,19 @@ def post_path(
Returns:
ESI data
"""
path = self._insert_vars(path, path_data or {})[0]
path = self.BASE_URL + path
var_insert = self._insert_vars(path, path_data)
path = var_insert[0]
target_url = self.BASE_URL + path
if len(var_insert[1]) > 0:
req = requests.models.PreparedRequest()
req.prepare_url(target_url, var_insert[1])
target_url = req.url

self._try_refresh_access_token()
return self.session.post(path, json=post_data).json()
resp = self.session.post(target_url, json=post_data)
if resp.text:
return resp.json()
return None

def post_op(self, id: str, path_data: Union[dict, None], post_data: Any) -> dict:
"""Modifies the ESI by looking up an operation id.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "preston"
version = "4.3.0"
version = "4.4.0"
description = "EVE ESI API access tool"
authors = ["Celeo <mattboulanger@fastmail.com>"]
license = "MIT"
Expand Down

0 comments on commit 6fede62

Please sign in to comment.