1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

CAPI: Remove unuses Session.query/profile()

* Session.profile() was unused (used to be called from stats.py, but
  that uses cached data now).
* Session.query() was unused, other than by itself.  Normal calls will
  currently be via companion.Session.station().  Future CAPI queries
  like `/fleetcarrier` might add their own companion.Session function.
* And in doing so get --capi-pretend-down working again.
* Small tweak to EDMarketConnector to not throw extra exception if there
  was a CAPI query exception.
This commit is contained in:
Athanasius 2021-08-31 14:06:56 +01:00
parent 60379892ee
commit 796bb1f863
No known key found for this signature in database
GPG Key ID: AE3E527847057C7D
2 changed files with 5 additions and 67 deletions

View File

@ -1106,6 +1106,8 @@ class AppWindow(object):
self.suit['text'] = f'{suitname} ({loadout_name})'
self.suit_show_if_set()
# Update Odyssey Suit data
companion.session.suit_update(capi_response.capi_data)
if capi_response.capi_data['commander'].get('credits') is not None:
monitor.state['Credits'] = capi_response.capi_data['commander']['credits']
@ -1174,9 +1176,6 @@ class AppWindow(object):
if capi_response.play_sound and play_bad:
hotkeymgr.play_bad()
# Update Odyssey Suit data
companion.session.suit_update(capi_response.capi_data)
logger.trace_if('capi.worker', 'Updating suit and cooldown...')
self.update_suit_text()
self.suit_show_if_set()

View File

@ -747,6 +747,9 @@ class Session(object):
capi_data: CAPIData
try:
logger.trace_if('capi.worker', 'Sending HTTP request...')
if conf_module.capi_pretend_down:
raise ServerConnectionError(f'Pretending CAPI down: {capi_endpoint}')
r = self.requests_session.get(self.server + capi_endpoint, timeout=timeout) # type: ignore
logger.trace_if('capi.worker', '... got result...')
r.raise_for_status() # Typically 403 "Forbidden" on token expiry
@ -933,70 +936,6 @@ class Session(object):
)
)
def query(
self, endpoint: str, query_time: int,
tk_response_event: Optional[str] = None,
play_sound: bool = False, auto_update: bool = False
) -> None:
"""
Perform a query against the specified CAPI endpoint.
:param endpoint: The CAPI endpoint to query.
:param tk_response_event: Name of tk event to generate when response queued.
:param query_time: When this query was initiated.
:param play_sound: Whether the app should play a sound on error.
:param auto_update: Whether this request was triggered automatically.
"""
logger.trace_if('capi.query', f'Performing query for endpoint "{endpoint}"')
if self.state == Session.STATE_INIT:
if self.login():
self.query(
endpoint, query_time, tk_response_event=tk_response_event, play_sound=play_sound,
auto_update=auto_update
)
return
elif self.state == Session.STATE_AUTH:
logger.error('cannot make a query when unauthorized')
raise CredentialsError('cannot make a query when unauthorized')
logger.trace_if('capi.query', 'Trying...')
if conf_module.capi_pretend_down:
raise ServerConnectionError(f'Pretending CAPI down: {endpoint}')
self.capi_request_queue.put(
EDMCCAPIRequest(
endpoint=endpoint,
tk_response_event=tk_response_event,
query_time=query_time,
play_sound=play_sound,
auto_update=auto_update
)
)
def profile(
self,
query_time: int = 0,
tk_response_event: Optional[str] = None,
play_sound: bool = False, auto_update: bool = False
) -> None:
"""
Perform general CAPI /profile endpoint query.
:param query_time: When this query was initiated.
:param tk_response_event: Name of tk event to generate when response queued.
:param play_sound: Whether the app should play a sound on error.
:param auto_update: Whether this request was triggered automatically.
"""
if query_time == 0:
query_time = int(time.time())
self.query(
self.FRONTIER_CAPI_PATH_PROFILE, query_time=query_time,
tk_response_event=tk_response_event,
play_sound=play_sound, auto_update=auto_update
)
def station(
self, query_time: int, tk_response_event: Optional[str] = None,
play_sound: bool = False, auto_update: bool = False