Skip to content
This repository has been archived by the owner on May 21, 2023. It is now read-only.

Commit

Permalink
feat(breaking change): add more features and rename functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroday0619 committed Sep 16, 2022
1 parent f1c930c commit 0e66971
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ nso_res = NintendoSwitchOnlineAPI(
session_token=session_token,
)
nso_res.sync_login()
print(json.dumps(nso_res.getSelf(), indent=4, ensure_ascii=False))
print(json.dumps(nso_res.getCurrentUser(), indent=4, ensure_ascii=False))

```

Expand Down
66 changes: 63 additions & 3 deletions nso_bridge/nso.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_response(self):
if api_resp.status_code != 200:
raise Exception(f"{api_resp.json()}")
rs = api_resp.json()
print(rs)
f = rs["f"]
uuid = rs["request_id"]
timestamp = rs["timestamp"]
Expand Down Expand Up @@ -120,9 +121,11 @@ def __init__(

self.login = {"login": None, "time": 0}

def getSelf(self):
"""Get information of My Nintendo Switch Account."""
resp = requests.post(url=self.url + "/v3/User/ShowSelf", headers=self.headers)
def getAnnouncements(self):
"""Get information of announcements."""
resp = requests.post(
url=self.url + "/v3/Announcement/List", headers=self.headers
)
if resp.status_code != 200:
raise Exception(f"Error: {resp.status_code}")
return resp.json()
Expand All @@ -134,6 +137,63 @@ def getFriends(self):
raise Exception(f"Error: {resp.status_code}")
return resp.json()

def getWebServices(self):
"""Get information of web services registered to Nintendo Switch account."""
resp = requests.post(
url=self.url + "/v1/Game/ListWebServices", headers=self.headers
)
if resp.status_code != 200:
raise Exception(f"Error: {resp.status_code}")
return resp.json()

def getActiveEvent(self):
"""Get information of active events."""
resp = requests.post(
url=self.url + "/v1/Event/GetActiveEvent", headers=self.headers
)
if resp.status_code != 200:
raise Exception(f"Error: {resp.status_code}")
return resp.json()

def getEvent(self):
"""Get information of events."""
resp = requests.post(url=self.url + "/v1/Event/Show", headers=self.headers)
if resp.status_code != 200:
raise Exception(f"Error: {resp.status_code}")
return resp.json()

def getUser(self):
"""Get information of user."""
resp = requests.post(url=self.url + "/v1/User/Show", headers=self.headers)
if resp.status_code != 200:
raise Exception(f"Error: {resp.status_code}")
return resp.json()

def getCurrentUser(self):
"""Get information of My Nintendo Switch Account."""
resp = requests.post(url=self.url + "/v3/User/ShowSelf", headers=self.headers)
if resp.status_code != 200:
raise Exception(f"Error: {resp.status_code}")
return resp.json()

def getFriendCodeUrl(self):
"""Get information of friend code URL."""
resp = requests.post(
url=self.url + "/v3/Friend/CreateFriendCodeUrl", headers=self.headers
)
if resp.status_code != 200:
raise Exception(f"Error: {resp.status_code}")
return resp.json()

def getCurrentUserPermissions(self):
"""Get information of current user permissions."""
resp = requests.post(
url=self.url + "/v3/User/Permissions/ShowSelf", headers=self.headers
)
if resp.status_code != 200:
raise Exception(f"Error: {resp.status_code}")
return resp.json()

def sync_login(self):
wasc_access_token = keyring.get_password("nso-bridge", "login")
wasc_time = keyring.get_password("nso-bridge", "wasc_time")
Expand Down
180 changes: 180 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
from nso_bridge.nso import NintendoSwitchOnlineAPI


def test_get_nso_app_version():
try:
app = NintendoSwitchAccount()
app.get_nso_app_version()
assert True
except Exception:
assert False


def test_nso_login():
try:
app = NintendoSwitchAccount()
Expand All @@ -20,3 +29,174 @@ def test_nso_login():
assert True
except Exception:
assert False


def test_getAnnouncements():
try:
app = NintendoSwitchAccount()

# override the nso_app_version
app.nso_app_version = app.get_nso_app_version()
session_token = keyring.get_password("nso-bridge", "session_token")

nso_res = NintendoSwitchOnlineAPI(
nso_app_version=app.nso_app_version,
session_token=session_token,
)
nso_res.sync_login()
nso_res.getAnnouncements()
assert True
except Exception:
assert False


def test_getFriends():
try:
app = NintendoSwitchAccount()

# override the nso_app_version
app.nso_app_version = app.get_nso_app_version()
session_token = keyring.get_password("nso-bridge", "session_token")

nso_res = NintendoSwitchOnlineAPI(
nso_app_version=app.nso_app_version,
session_token=session_token,
)
nso_res.sync_login()
nso_res.getFriends()
assert True
except Exception:
assert False


def test_getWebServices():
try:
app = NintendoSwitchAccount()

# override the nso_app_version
app.nso_app_version = app.get_nso_app_version()
session_token = keyring.get_password("nso-bridge", "session_token")

nso_res = NintendoSwitchOnlineAPI(
nso_app_version=app.nso_app_version,
session_token=session_token,
)
nso_res.sync_login()
nso_res.getWebServices()
assert True
except Exception:
assert False


def test_getActiveEvent():
try:
app = NintendoSwitchAccount()

# override the nso_app_version
app.nso_app_version = app.get_nso_app_version()
session_token = keyring.get_password("nso-bridge", "session_token")

nso_res = NintendoSwitchOnlineAPI(
nso_app_version=app.nso_app_version,
session_token=session_token,
)
nso_res.sync_login()
nso_res.getActiveEvent()
assert True
except Exception:
assert False


def test_getEvent():
try:
app = NintendoSwitchAccount()

# override the nso_app_version
app.nso_app_version = app.get_nso_app_version()
session_token = keyring.get_password("nso-bridge", "session_token")

nso_res = NintendoSwitchOnlineAPI(
nso_app_version=app.nso_app_version,
session_token=session_token,
)
nso_res.sync_login()
nso_res.getEvent()
assert True
except Exception:
assert False


def test_getUser():
try:
app = NintendoSwitchAccount()

# override the nso_app_version
app.nso_app_version = app.get_nso_app_version()
session_token = keyring.get_password("nso-bridge", "session_token")

nso_res = NintendoSwitchOnlineAPI(
nso_app_version=app.nso_app_version,
session_token=session_token,
)
nso_res.sync_login()
nso_res.getUser()
assert True
except Exception:
assert False


def test_getCurrentUser():
try:
app = NintendoSwitchAccount()

# override the nso_app_version
app.nso_app_version = app.get_nso_app_version()
session_token = keyring.get_password("nso-bridge", "session_token")

nso_res = NintendoSwitchOnlineAPI(
nso_app_version=app.nso_app_version,
session_token=session_token,
)
nso_res.sync_login()
nso_res.getCurrentUser()
assert True
except Exception:
assert False


def test_getFriendCodeUrl():
try:
app = NintendoSwitchAccount()

# override the nso_app_version
app.nso_app_version = app.get_nso_app_version()
session_token = keyring.get_password("nso-bridge", "session_token")

nso_res = NintendoSwitchOnlineAPI(
nso_app_version=app.nso_app_version,
session_token=session_token,
)
nso_res.sync_login()
nso_res.getFriendCodeUrl()
assert True
except Exception:
assert False


def test_getCurrentUserPermissions():
try:
app = NintendoSwitchAccount()

# override the nso_app_version
app.nso_app_version = app.get_nso_app_version()
session_token = keyring.get_password("nso-bridge", "session_token")

nso_res = NintendoSwitchOnlineAPI(
nso_app_version=app.nso_app_version,
session_token=session_token,
)
nso_res.sync_login()
nso_res.getCurrentUserPermissions()
assert True
except Exception:
assert False

0 comments on commit 0e66971

Please sign in to comment.