Skip to content

Commit ac97e1d

Browse files
reformat and bump version
1 parent 7370263 commit ac97e1d

File tree

9 files changed

+26
-23
lines changed

9 files changed

+26
-23
lines changed

sonicbit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from sonicbit.sonicbit import SonicBit
44

5-
__version__ = "0.1.1"
5+
__version__ = "0.2.1"
66
__all__ = ["SonicBit"]
77

88
logging.basicConfig(

sonicbit/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class SonicBitBase:
88

99
session = Session
1010

11-
1211
@staticmethod
1312
def url(path: str) -> str:
14-
return f"{Constants.API_BASE_URL}{path}"
13+
return f"{Constants.API_BASE_URL}{path}"

sonicbit/modules/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from .auth import Auth
22
from .file import File
33
from .remote_download import RemoteDownload
4+
from .signup import Signup
45
from .torrent import Torrent
56
from .user import User
6-
from .signup import Signup
77

88
__all__ = [
99
"Auth",

sonicbit/modules/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def login(email: str, password: str) -> AuthResponse:
4444
response = request(
4545
"POST",
4646
Auth.url("/web/login"),
47-
data={"email": email, "password": password},
47+
json={"email": email, "password": password},
4848
headers=Constants.API_HEADERS,
4949
)
5050

sonicbit/modules/remote_download.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def add_remote_download(self, url: str, path: PathInfo) -> bool:
1515

1616
data = {"url": url, "path": path.path}
1717

18-
reponse = self.session.post(self.url("/remote_download/task/add"), data=data)
18+
reponse = self.session.post(self.url("/remote_download/task/add"), json=data)
1919

2020
json_data = reponse.json()
2121
if json_data.get("success", False):
@@ -42,7 +42,7 @@ def delete_remote_download(self, id: int) -> bool:
4242
"task_id": id,
4343
}
4444
response = self.session.post(
45-
self.url("/remote_download/task/delete"), data=data
45+
self.url("/remote_download/task/delete"), json=data
4646
)
4747

4848
json_data = response.json()

sonicbit/modules/signup.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from sonicbit.base import SonicBitBase
2-
from sonicbit.error.error import SonicbitError
3-
import requests
4-
from sonicbit.constants import Constants
51
import logging
62

3+
import requests
4+
5+
from sonicbit.base import SonicBitBase
6+
from sonicbit.constants import Constants
7+
from sonicbit.error.error import SonicbitError
78

89
logger = logging.getLogger(__name__)
910

@@ -24,7 +25,6 @@ def signup(name: str, email: str, password: str, otp_callback: callable = None):
2425
SonicBitBase.url("/user/register"), json=data, headers=Constants.API_HEADERS
2526
).json()
2627

27-
2828
if response["success"] == True:
2929
if otp_callback:
3030
otp = otp_callback(email)
@@ -51,13 +51,14 @@ def submit_otp(otp: str):
5151
headers=Constants.API_HEADERS,
5252
).json()
5353

54-
5554
if response["success"] == True:
56-
token = response['data']['token']
55+
token = response["data"]["token"]
5756
Signup._complete_tutorial(token)
5857
return True
5958
else:
60-
raise SonicbitError(f"Failed to submit OTP: {response.get('msg', response)}")
59+
raise SonicbitError(
60+
f"Failed to submit OTP: {response.get('msg', response)}"
61+
)
6162

6263
@staticmethod
6364
def _complete_tutorial(token: str):
@@ -66,17 +67,18 @@ def _complete_tutorial(token: str):
6667
data = {"delete": True}
6768

6869
headers = Constants.API_HEADERS
69-
headers['Authorization'] = f"Bearer {token}"
70+
headers["Authorization"] = f"Bearer {token}"
7071

7172
logger.debug(f"Marking tutorial as completed")
7273
response = requests.post(
7374
SonicBitBase.url("/user/account/welcome_completed"),
7475
json=data,
75-
headers=headers
76+
headers=headers,
7677
).json()
7778

78-
79-
if response.get('success') == True:
79+
if response.get("success") == True:
8080
return True
8181
else:
82-
raise SonicbitError(f"Failed to complete signup: {response.get('message', response.get('msg', response))}")
82+
raise SonicbitError(
83+
f"Failed to complete signup: {response.get('message', response.get('msg', response))}"
84+
)

sonicbit/sonicbit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from sonicbit.modules.auth import Auth
44
from sonicbit.modules.file import File
55
from sonicbit.modules.remote_download import RemoteDownload
6+
from sonicbit.modules.signup import Signup
67
from sonicbit.modules.torrent import Torrent
78
from sonicbit.modules.user import User
8-
from sonicbit.modules.signup import Signup
99

1010

1111
class SonicBit(Auth, Signup, User, File, Torrent, RemoteDownload):

sonicbit/types/auth_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def from_response(response: Response) -> "AuthResponse":
3333
)
3434
else:
3535
raise AuthError(
36-
f"Login failed: {json_data.get('error')} - {json_data.get('msg')}"
36+
f"Login failed: {json_data.get('error')} - {json_data.get('msg', json_data)}"
3737
)
3838

3939
def __str__(self):

sonicbit/types/user_details.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def from_response(response: Response) -> "UserDetails":
4242

4343
user_data = json_data.get("user_data")
4444
if json_data.get("message") or not user_data:
45-
raise SonicbitError(f"User details not found: {json_data.get('message')}")
45+
raise SonicbitError(
46+
f"User details not found: {json_data.get('message', json_data)}"
47+
)
4648

4749
return UserDetails(
4850
id=user_data["id"],

0 commit comments

Comments
 (0)