-
Notifications
You must be signed in to change notification settings - Fork 156
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
Added a check when performing a post. #102
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
from requests.adapters import HTTPAdapter | ||
from requests.packages.urllib3.util.retry import Retry | ||
|
||
GATEWAY_URL = 'https://kic.lgthinq.com:46030/api/common/gatewayUriList' | ||
GATEWAY_URL = 'https://kic.lgthinq.com:46030' | ||
APP_KEY = 'wideq' | ||
SECURITY_KEY = 'nuts_securitykey' | ||
DATA_ROOT = 'lgedmRoot' | ||
|
@@ -177,7 +177,7 @@ def __init__(self, device_id, code): | |
} | ||
|
||
|
||
def lgedm_post(url, data=None, access_token=None, session_id=None): | ||
def lgedm_post(api_root, path, data=None, access_token=None, session_id=None): | ||
"""Make an HTTP request in the format used by the API servers. | ||
|
||
In this format, the request POST data sent as JSON under a special | ||
|
@@ -199,7 +199,18 @@ def lgedm_post(url, data=None, access_token=None, session_id=None): | |
headers['x-thinq-jsessionId'] = session_id | ||
|
||
with retry_session() as session: | ||
res = session.post(url, json={DATA_ROOT: data}, headers=headers) | ||
res = session.post(urljoin(api_root + '/', path), | ||
json={DATA_ROOT: data}, headers=headers) | ||
|
||
if "rtiControl" in path: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this from I think that might juts mean |
||
session.post( | ||
urljoin(api_root + '/', 'rti/delControlPermission'), | ||
json={ | ||
DATA_ROOT: {'deviceId': data.get('deviceId')} | ||
}, headers=headers | ||
) | ||
# Ignore the response, since it's not a breaking error! | ||
|
||
out = res.json()[DATA_ROOT] | ||
|
||
# Check for API errors. | ||
|
@@ -248,14 +259,13 @@ def login(api_root, access_token, country, language): | |
return information about the session. | ||
""" | ||
|
||
url = urljoin(api_root + '/', 'member/login') | ||
data = { | ||
'countryCode': country, | ||
'langCode': language, | ||
'loginType': 'EMP', | ||
'token': access_token, | ||
} | ||
return lgedm_post(url, data) | ||
return lgedm_post(api_root, 'member/login', data) | ||
|
||
|
||
def refresh_auth(oauth_root, refresh_token): | ||
|
@@ -315,7 +325,7 @@ def discover(cls, country, language) -> 'Gateway': | |
`country` and `language` are codes, like "US" and "en-US," | ||
respectively. | ||
""" | ||
gw = lgedm_post(GATEWAY_URL, | ||
gw = lgedm_post(GATEWAY_URL, '/api/common/gatewayUriList', | ||
{'countryCode': country, 'langCode': language}) | ||
return cls(gw['empUri'], gw['thinqUri'], gw['oauthUri'], | ||
country, language) | ||
|
@@ -390,8 +400,8 @@ def post(self, path, data=None): | |
request from an active Session. | ||
""" | ||
|
||
url = urljoin(self.auth.gateway.api_root + '/', path) | ||
return lgedm_post(url, data, self.auth.access_token, self.session_id) | ||
return lgedm_post(self.auth.gateway.api_root, path, data, | ||
self.auth.access_token, self.session_id) | ||
|
||
def get_devices(self) -> List[Dict[str, Any]]: | ||
"""Get a list of devices associated with the user's account. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave this change where we split up the base URL and path out for now—it looks interesting, but I would love to review it carefully in a separate PR.