Skip to content

Commit 0e95063

Browse files
add param checking and removed default values
1 parent 98451c7 commit 0e95063

File tree

11 files changed

+768
-179
lines changed

11 files changed

+768
-179
lines changed

appwrite/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def __init__(self):
88
self._endpoint = 'https://appwrite.io/v1'
99
self._global_headers = {
1010
'content-type': '',
11-
'x-sdk-version': 'appwrite:python:0.2.1',
11+
'x-sdk-version': 'appwrite:python:0.2.2',
1212
'X-Appwrite-Response-Format' : '0.8.0',
1313
}
1414

appwrite/services/account.py

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ..service import Service
2-
2+
from ..exception import AppwriteException
33

44
class Account(Service):
55

@@ -29,10 +29,20 @@ def delete(self):
2929
def update_email(self, email, password):
3030
"""Update Account Email"""
3131

32+
if email is None:
33+
raise AppwriteException('Missing required parameter: "email"')
34+
35+
if password is None:
36+
raise AppwriteException('Missing required parameter: "password"')
37+
3238
params = {}
3339
path = '/account/email'
34-
params['email'] = email
35-
params['password'] = password
40+
41+
if email is not None:
42+
params['email'] = email
43+
44+
if password is not None:
45+
params['password'] = password
3646

3747
return self.client.call('patch', path, {
3848
'content-type': 'application/json',
@@ -51,21 +61,33 @@ def get_logs(self):
5161
def update_name(self, name):
5262
"""Update Account Name"""
5363

64+
if name is None:
65+
raise AppwriteException('Missing required parameter: "name"')
66+
5467
params = {}
5568
path = '/account/name'
56-
params['name'] = name
69+
70+
if name is not None:
71+
params['name'] = name
5772

5873
return self.client.call('patch', path, {
5974
'content-type': 'application/json',
6075
}, params)
6176

62-
def update_password(self, password, old_password=''):
77+
def update_password(self, password, old_password = None):
6378
"""Update Account Password"""
6479

80+
if password is None:
81+
raise AppwriteException('Missing required parameter: "password"')
82+
6583
params = {}
6684
path = '/account/password'
67-
params['password'] = password
68-
params['oldPassword'] = old_password
85+
86+
if password is not None:
87+
params['password'] = password
88+
89+
if old_password is not None:
90+
params['oldPassword'] = old_password
6991

7092
return self.client.call('patch', path, {
7193
'content-type': 'application/json',
@@ -84,9 +106,14 @@ def get_prefs(self):
84106
def update_prefs(self, prefs):
85107
"""Update Account Preferences"""
86108

109+
if prefs is None:
110+
raise AppwriteException('Missing required parameter: "prefs"')
111+
87112
params = {}
88113
path = '/account/prefs'
89-
params['prefs'] = prefs
114+
115+
if prefs is not None:
116+
params['prefs'] = prefs
90117

91118
return self.client.call('patch', path, {
92119
'content-type': 'application/json',
@@ -95,10 +122,20 @@ def update_prefs(self, prefs):
95122
def create_recovery(self, email, url):
96123
"""Create Password Recovery"""
97124

125+
if email is None:
126+
raise AppwriteException('Missing required parameter: "email"')
127+
128+
if url is None:
129+
raise AppwriteException('Missing required parameter: "url"')
130+
98131
params = {}
99132
path = '/account/recovery'
100-
params['email'] = email
101-
params['url'] = url
133+
134+
if email is not None:
135+
params['email'] = email
136+
137+
if url is not None:
138+
params['url'] = url
102139

103140
return self.client.call('post', path, {
104141
'content-type': 'application/json',
@@ -107,12 +144,32 @@ def create_recovery(self, email, url):
107144
def update_recovery(self, user_id, secret, password, password_again):
108145
"""Complete Password Recovery"""
109146

147+
if user_id is None:
148+
raise AppwriteException('Missing required parameter: "user_id"')
149+
150+
if secret is None:
151+
raise AppwriteException('Missing required parameter: "secret"')
152+
153+
if password is None:
154+
raise AppwriteException('Missing required parameter: "password"')
155+
156+
if password_again is None:
157+
raise AppwriteException('Missing required parameter: "password_again"')
158+
110159
params = {}
111160
path = '/account/recovery'
112-
params['userId'] = user_id
113-
params['secret'] = secret
114-
params['password'] = password
115-
params['passwordAgain'] = password_again
161+
162+
if user_id is not None:
163+
params['userId'] = user_id
164+
165+
if secret is not None:
166+
params['secret'] = secret
167+
168+
if password is not None:
169+
params['password'] = password
170+
171+
if password_again is not None:
172+
params['passwordAgain'] = password_again
116173

117174
return self.client.call('put', path, {
118175
'content-type': 'application/json',
@@ -141,6 +198,9 @@ def delete_sessions(self):
141198
def delete_session(self, session_id):
142199
"""Delete Account Session"""
143200

201+
if session_id is None:
202+
raise AppwriteException('Missing required parameter: "session_id"')
203+
144204
params = {}
145205
path = '/account/sessions/{sessionId}'
146206
path = path.replace('{sessionId}', session_id)
@@ -152,9 +212,14 @@ def delete_session(self, session_id):
152212
def create_verification(self, url):
153213
"""Create Email Verification"""
154214

215+
if url is None:
216+
raise AppwriteException('Missing required parameter: "url"')
217+
155218
params = {}
156219
path = '/account/verification'
157-
params['url'] = url
220+
221+
if url is not None:
222+
params['url'] = url
158223

159224
return self.client.call('post', path, {
160225
'content-type': 'application/json',
@@ -163,10 +228,20 @@ def create_verification(self, url):
163228
def update_verification(self, user_id, secret):
164229
"""Complete Email Verification"""
165230

231+
if user_id is None:
232+
raise AppwriteException('Missing required parameter: "user_id"')
233+
234+
if secret is None:
235+
raise AppwriteException('Missing required parameter: "secret"')
236+
166237
params = {}
167238
path = '/account/verification'
168-
params['userId'] = user_id
169-
params['secret'] = secret
239+
240+
if user_id is not None:
241+
params['userId'] = user_id
242+
243+
if secret is not None:
244+
params['secret'] = secret
170245

171246
return self.client.call('put', path, {
172247
'content-type': 'application/json',

appwrite/services/avatars.py

Lines changed: 91 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
11
from ..service import Service
2-
2+
from ..exception import AppwriteException
33

44
class Avatars(Service):
55

66
def __init__(self, client):
77
super(Avatars, self).__init__(client)
88

9-
def get_browser(self, code, width=100, height=100, quality=100):
9+
def get_browser(self, code, width = None, height = None, quality = None):
1010
"""Get Browser Icon"""
1111

12+
if code is None:
13+
raise AppwriteException('Missing required parameter: "code"')
14+
1215
params = {}
1316
path = '/avatars/browsers/{code}'
1417
path = path.replace('{code}', code)
15-
params['width'] = width
16-
params['height'] = height
17-
params['quality'] = quality
18+
19+
if width is not None:
20+
params['width'] = width
21+
22+
if height is not None:
23+
params['height'] = height
24+
25+
if quality is not None:
26+
params['quality'] = quality
1827

1928
return self.client.call('get', path, {
2029
'content-type': 'application/json',
2130
}, params)
2231

23-
def get_credit_card(self, code, width=100, height=100, quality=100):
32+
def get_credit_card(self, code, width = None, height = None, quality = None):
2433
"""Get Credit Card Icon"""
2534

35+
if code is None:
36+
raise AppwriteException('Missing required parameter: "code"')
37+
2638
params = {}
2739
path = '/avatars/credit-cards/{code}'
2840
path = path.replace('{code}', code)
29-
params['width'] = width
30-
params['height'] = height
31-
params['quality'] = quality
41+
42+
if width is not None:
43+
params['width'] = width
44+
45+
if height is not None:
46+
params['height'] = height
47+
48+
if quality is not None:
49+
params['quality'] = quality
3250

3351
return self.client.call('get', path, {
3452
'content-type': 'application/json',
@@ -37,65 +55,109 @@ def get_credit_card(self, code, width=100, height=100, quality=100):
3755
def get_favicon(self, url):
3856
"""Get Favicon"""
3957

58+
if url is None:
59+
raise AppwriteException('Missing required parameter: "url"')
60+
4061
params = {}
4162
path = '/avatars/favicon'
42-
params['url'] = url
63+
64+
if url is not None:
65+
params['url'] = url
4366

4467
return self.client.call('get', path, {
4568
'content-type': 'application/json',
4669
}, params)
4770

48-
def get_flag(self, code, width=100, height=100, quality=100):
71+
def get_flag(self, code, width = None, height = None, quality = None):
4972
"""Get Country Flag"""
5073

74+
if code is None:
75+
raise AppwriteException('Missing required parameter: "code"')
76+
5177
params = {}
5278
path = '/avatars/flags/{code}'
5379
path = path.replace('{code}', code)
54-
params['width'] = width
55-
params['height'] = height
56-
params['quality'] = quality
80+
81+
if width is not None:
82+
params['width'] = width
83+
84+
if height is not None:
85+
params['height'] = height
86+
87+
if quality is not None:
88+
params['quality'] = quality
5789

5890
return self.client.call('get', path, {
5991
'content-type': 'application/json',
6092
}, params)
6193

62-
def get_image(self, url, width=400, height=400):
94+
def get_image(self, url, width = None, height = None):
6395
"""Get Image from URL"""
6496

97+
if url is None:
98+
raise AppwriteException('Missing required parameter: "url"')
99+
65100
params = {}
66101
path = '/avatars/image'
67-
params['url'] = url
68-
params['width'] = width
69-
params['height'] = height
102+
103+
if url is not None:
104+
params['url'] = url
105+
106+
if width is not None:
107+
params['width'] = width
108+
109+
if height is not None:
110+
params['height'] = height
70111

71112
return self.client.call('get', path, {
72113
'content-type': 'application/json',
73114
}, params)
74115

75-
def get_initials(self, name='', width=500, height=500, color='', background=''):
116+
def get_initials(self, name = None, width = None, height = None, color = None, background = None):
76117
"""Get User Initials"""
77118

78119
params = {}
79120
path = '/avatars/initials'
80-
params['name'] = name
81-
params['width'] = width
82-
params['height'] = height
83-
params['color'] = color
84-
params['background'] = background
121+
122+
if name is not None:
123+
params['name'] = name
124+
125+
if width is not None:
126+
params['width'] = width
127+
128+
if height is not None:
129+
params['height'] = height
130+
131+
if color is not None:
132+
params['color'] = color
133+
134+
if background is not None:
135+
params['background'] = background
85136

86137
return self.client.call('get', path, {
87138
'content-type': 'application/json',
88139
}, params)
89140

90-
def get_q_r(self, text, size=400, margin=1, download=False):
141+
def get_q_r(self, text, size = None, margin = None, download = None):
91142
"""Get QR Code"""
92143

144+
if text is None:
145+
raise AppwriteException('Missing required parameter: "text"')
146+
93147
params = {}
94148
path = '/avatars/qr'
95-
params['text'] = text
96-
params['size'] = size
97-
params['margin'] = margin
98-
params['download'] = download
149+
150+
if text is not None:
151+
params['text'] = text
152+
153+
if size is not None:
154+
params['size'] = size
155+
156+
if margin is not None:
157+
params['margin'] = margin
158+
159+
if download is not None:
160+
params['download'] = download
99161

100162
return self.client.call('get', path, {
101163
'content-type': 'application/json',

0 commit comments

Comments
 (0)