-
Notifications
You must be signed in to change notification settings - Fork 176
Methods for adding, accepting and deleting friends #366
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -416,3 +416,39 @@ def get_wallet_balance(self, convert_to_decimal: bool = True, on_hold: bool = Fa | |
| return Decimal(balance_dict[balance_dict_key]) / 100 | ||
| else: | ||
| return balance_dict[balance_dict_key] | ||
|
|
||
| @login_required | ||
| def add_friend(self, steam_id: str) -> bool: | ||
| response = self._friend_ajax_request(steam_id) | ||
| return True if response else False | ||
|
|
||
| @login_required | ||
| def accept_friend(self, steam_id: str) -> bool: | ||
| return self._friend_ajax_request(steam_id, accept=1) | ||
|
|
||
| _headers = { | ||
|
Owner
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. why put it here |
||
| "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" | ||
| } | ||
|
|
||
| def _friend_ajax_request(self, steam_id: str, accept: int = 0) -> dict: | ||
| url = f'{SteamUrl.COMMUNITY_URL}/actions/AddFriendAjax' | ||
| data = { | ||
| "sessionID": self._get_session_id(), | ||
| "steamid": steam_id, | ||
| "accept_invite": accept | ||
| } | ||
| # returns True or json object if request was succes, otherwise False | ||
| return self._session.post(url, data=data, headers=self._headers).json() | ||
|
Owner
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. Should raise exception if something was wrong, otherwise return datatype should be specified not bool or dict |
||
|
|
||
| @login_required | ||
| def remove_friend(self, steam_id: str) -> bool: | ||
| url = f'{SteamUrl.COMMUNITY_URL}/actions/RemoveFriendAjax' | ||
| data = { | ||
| "sessionID": self._get_session_id(), | ||
| "steamid": steam_id | ||
| } | ||
| # returns True if request was succes, otherwise False | ||
| # returns True even if `steam_id` has never been a friend | ||
|
Owner
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. again if request was not succesed due to error, it should be an exception |
||
| return self._session.post( | ||
| url, data=data, headers=self._headers).json() | ||
|
|
||
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.
what is the difference between add_friend and accept_friend? seems like the only diffrerence is checking the response