Skip to content

Commit 18be093

Browse files
committed
Started test cases, fixed admins API schema inconsistency
1 parent 887db00 commit 18be093

35 files changed

+1320
-928
lines changed

docs/intercom_python_sdk/apis/admins/api.html

Lines changed: 59 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ <h1 id="admins-api">Admins API</h1>
3535
<summary>
3636
<span>Expand source code</span>
3737
</summary>
38-
<pre><code class="python">&#34;&#34;&#34;
38+
<pre><code class="python">&#34;&#34;&#34;
3939
# Admins API
4040

4141
`apis/admins/api.py`
@@ -49,22 +49,20 @@ <h1 id="admins-api">Admins API</h1>
4949
&#34;&#34;&#34;
5050

5151
# Built-ins
52-
import functools
53-
from typing import Union, cast
52+
from typing import Union
5453

5554
# External
5655
from uplink import (
57-
get, put, post,
58-
returns, args,
59-
error_handler, response_handler,
60-
Field, Body, json, Url, Path, Query
56+
get, put,
57+
returns, json,
58+
response_handler,
59+
Body
6160
)
6261

6362
# From Current API
6463
from .schemas import (
65-
AdminSchema,
64+
AdminSchema,
6665
AdminListSchema,
67-
TeamPriorityLevelSchema
6866
)
6967
from .models import Admin, AdminList
7068

@@ -79,18 +77,18 @@ <h1 id="admins-api">Admins API</h1>
7977
&#34;&#34;&#34; Admins API Client. &#34;&#34;&#34;
8078
URI = &#34;/admins/&#34;
8179

82-
@returns(AdminSchema) # type: ignore
83-
@get(&#34;/me&#34;) # We are adding a leading slash here because we actually WANT to ignore the /admins URI in this case.
80+
@returns(AdminSchema) # type: ignore
81+
@get(&#34;/me&#34;) # We are adding a leading slash here because we actually WANT to ignore the /admins URI in this case.
8482
def me(self):
85-
&#34;&#34;&#34; Get the current admin user.
86-
83+
&#34;&#34;&#34; Get the current admin user.
84+
8785
Returns:
8886
Admin: The current admin user.
8987
&#34;&#34;&#34;
9088

91-
@returns(AdminSchema) # type: ignore
89+
@returns(AdminSchema) # type: ignore
9290
@put(&#34;{admin_id}/away&#34;)
93-
def __set_away_by_id(self, admin_id: Union[str, int], data: Body(type=dict)): # type: ignore
91+
def __set_away_by_id(self, admin_id: Union[str, int], data: Body(type=dict)): # type: ignore
9492
&#34;&#34;&#34; Set the away status of an admin. Internal method for `set_away_by_id`.&#34;&#34;&#34;
9593

9694
def set_away_by_id(self, admin_id: Union[str, int], away: bool = True, reassign: bool = True):
@@ -104,21 +102,21 @@ <h1 id="admins-api">Admins API</h1>
104102
Returns:
105103
HTTPResponse: The response from the API.
106104
&#34;&#34;&#34;
107-
return self.__set_away_by_id(admin_id, {&#34;away_mode_enabled&#34;:away, &#34;away_mode_reassign&#34;:reassign})
108-
109-
@returns(AdminListSchema) # type: ignore
105+
return self.__set_away_by_id(admin_id, {&#34;away_mode_enabled&#34;: away, &#34;away_mode_reassign&#34;: reassign})
106+
107+
@returns(AdminListSchema) # type: ignore
110108
@get(&#34;&#34;)
111109
def list_admins(self):
112-
&#34;&#34;&#34; List all admins.
113-
110+
&#34;&#34;&#34; List all admins.
111+
114112
Returns:
115113
AdminList: The list of admins.
116114
&#34;&#34;&#34;
117115

118-
@returns(AdminSchema) # type: ignore
116+
@returns(AdminSchema) # type: ignore
119117
@get(&#34;{admin_id}&#34;)
120118
def get_admin_by_id(self, admin_id: Union[str, int]):
121-
&#34;&#34;&#34; Get an admin by ID.
119+
&#34;&#34;&#34; Get an admin by ID.
122120

123121
Args:
124122
admin_id (Union[str, int]): The ID of the admin.
@@ -132,14 +130,13 @@ <h1 id="admins-api">Admins API</h1>
132130

133131
Args:
134132
email (str): The email of the admin.
135-
133+
136134
Returns:
137135
Admin: The matching Admin object. None if no match found.
138136
&#34;&#34;&#34;
139137
admins_list = self.list_admins()
140-
for admin in admins_list.admins: # type: ignore
141-
if admin.email == email:
142-
return admin
138+
admins_list.admins = [admin for admin in admins_list.admins if admin.email == email] # type: ignore
139+
return admins_list.admins[0] if admins_list.admins else None
143140

144141
def get_admins_by_team_id(self, team_id: Union[int, str]) -&gt; AdminList:
145142
&#34;&#34;&#34; Get all admins by team ID.
@@ -151,15 +148,8 @@ <h1 id="admins-api">Admins API</h1>
151148
AdminList: The list of admins. None if no match found.
152149
&#34;&#34;&#34;
153150
admins_list = self.list_admins()
154-
155-
# Loop over list in reverse so we can delete from the list as we go.
156-
for index, admin in reversed(list(enumerate(admins_list.admins))): # type: ignore
157-
if team_id not in admin.team_ids:
158-
del admins_list.admins[index]
159-
160-
return admins_list
161-
162-
</code></pre>
151+
admins_list.admins = [admin for admin in admins_list.admins if team_id in admin.team_ids] # type: ignore
152+
return admins_list</code></pre>
163153
</details>
164154
</section>
165155
<section>
@@ -195,18 +185,18 @@ <h2 id="args">Args</h2>
195185
&#34;&#34;&#34; Admins API Client. &#34;&#34;&#34;
196186
URI = &#34;/admins/&#34;
197187

198-
@returns(AdminSchema) # type: ignore
199-
@get(&#34;/me&#34;) # We are adding a leading slash here because we actually WANT to ignore the /admins URI in this case.
188+
@returns(AdminSchema) # type: ignore
189+
@get(&#34;/me&#34;) # We are adding a leading slash here because we actually WANT to ignore the /admins URI in this case.
200190
def me(self):
201-
&#34;&#34;&#34; Get the current admin user.
202-
191+
&#34;&#34;&#34; Get the current admin user.
192+
203193
Returns:
204194
Admin: The current admin user.
205195
&#34;&#34;&#34;
206196

207-
@returns(AdminSchema) # type: ignore
197+
@returns(AdminSchema) # type: ignore
208198
@put(&#34;{admin_id}/away&#34;)
209-
def __set_away_by_id(self, admin_id: Union[str, int], data: Body(type=dict)): # type: ignore
199+
def __set_away_by_id(self, admin_id: Union[str, int], data: Body(type=dict)): # type: ignore
210200
&#34;&#34;&#34; Set the away status of an admin. Internal method for `set_away_by_id`.&#34;&#34;&#34;
211201

212202
def set_away_by_id(self, admin_id: Union[str, int], away: bool = True, reassign: bool = True):
@@ -220,21 +210,21 @@ <h2 id="args">Args</h2>
220210
Returns:
221211
HTTPResponse: The response from the API.
222212
&#34;&#34;&#34;
223-
return self.__set_away_by_id(admin_id, {&#34;away_mode_enabled&#34;:away, &#34;away_mode_reassign&#34;:reassign})
224-
225-
@returns(AdminListSchema) # type: ignore
213+
return self.__set_away_by_id(admin_id, {&#34;away_mode_enabled&#34;: away, &#34;away_mode_reassign&#34;: reassign})
214+
215+
@returns(AdminListSchema) # type: ignore
226216
@get(&#34;&#34;)
227217
def list_admins(self):
228-
&#34;&#34;&#34; List all admins.
229-
218+
&#34;&#34;&#34; List all admins.
219+
230220
Returns:
231221
AdminList: The list of admins.
232222
&#34;&#34;&#34;
233223

234-
@returns(AdminSchema) # type: ignore
224+
@returns(AdminSchema) # type: ignore
235225
@get(&#34;{admin_id}&#34;)
236226
def get_admin_by_id(self, admin_id: Union[str, int]):
237-
&#34;&#34;&#34; Get an admin by ID.
227+
&#34;&#34;&#34; Get an admin by ID.
238228

239229
Args:
240230
admin_id (Union[str, int]): The ID of the admin.
@@ -248,14 +238,13 @@ <h2 id="args">Args</h2>
248238

249239
Args:
250240
email (str): The email of the admin.
251-
241+
252242
Returns:
253243
Admin: The matching Admin object. None if no match found.
254244
&#34;&#34;&#34;
255245
admins_list = self.list_admins()
256-
for admin in admins_list.admins: # type: ignore
257-
if admin.email == email:
258-
return admin
246+
admins_list.admins = [admin for admin in admins_list.admins if admin.email == email] # type: ignore
247+
return admins_list.admins[0] if admins_list.admins else None
259248

260249
def get_admins_by_team_id(self, team_id: Union[int, str]) -&gt; AdminList:
261250
&#34;&#34;&#34; Get all admins by team ID.
@@ -267,12 +256,7 @@ <h2 id="args">Args</h2>
267256
AdminList: The list of admins. None if no match found.
268257
&#34;&#34;&#34;
269258
admins_list = self.list_admins()
270-
271-
# Loop over list in reverse so we can delete from the list as we go.
272-
for index, admin in reversed(list(enumerate(admins_list.admins))): # type: ignore
273-
if team_id not in admin.team_ids:
274-
del admins_list.admins[index]
275-
259+
admins_list.admins = [admin for admin in admins_list.admins if team_id in admin.team_ids] # type: ignore
276260
return admins_list</code></pre>
277261
</details>
278262
<h3>Ancestors</h3>
@@ -315,21 +299,20 @@ <h2 id="returns">Returns</h2>
315299

316300
Args:
317301
email (str): The email of the admin.
318-
302+
319303
Returns:
320304
Admin: The matching Admin object. None if no match found.
321305
&#34;&#34;&#34;
322306
admins_list = self.list_admins()
323-
for admin in admins_list.admins: # type: ignore
324-
if admin.email == email:
325-
return admin</code></pre>
307+
admins_list.admins = [admin for admin in admins_list.admins if admin.email == email] # type: ignore
308+
return admins_list.admins[0] if admins_list.admins else None</code></pre>
326309
</details>
327310
</dd>
328311
<dt id="intercom_python_sdk.apis.admins.api.AdminsAPI.get_admin_by_id"><code class="name flex">
329312
<span>def <span class="ident">get_admin_by_id</span></span>(<span>self, admin_id: Union[str, int])</span>
330313
</code></dt>
331314
<dd>
332-
<div class="desc"><p>Get an admin by ID. </p>
315+
<div class="desc"><p>Get an admin by ID.</p>
333316
<h2 id="args">Args</h2>
334317
<dl>
335318
<dt><strong><code>admin_id</code></strong> :&ensp;<code>Union[str, int]</code></dt>
@@ -344,10 +327,10 @@ <h2 id="returns">Returns</h2>
344327
<summary>
345328
<span>Expand source code</span>
346329
</summary>
347-
<pre><code class="python">@returns(AdminSchema) # type: ignore
330+
<pre><code class="python">@returns(AdminSchema) # type: ignore
348331
@get(&#34;{admin_id}&#34;)
349332
def get_admin_by_id(self, admin_id: Union[str, int]):
350-
&#34;&#34;&#34; Get an admin by ID.
333+
&#34;&#34;&#34; Get an admin by ID.
351334

352335
Args:
353336
admin_id (Union[str, int]): The ID of the admin.
@@ -386,20 +369,15 @@ <h2 id="returns">Returns</h2>
386369
AdminList: The list of admins. None if no match found.
387370
&#34;&#34;&#34;
388371
admins_list = self.list_admins()
389-
390-
# Loop over list in reverse so we can delete from the list as we go.
391-
for index, admin in reversed(list(enumerate(admins_list.admins))): # type: ignore
392-
if team_id not in admin.team_ids:
393-
del admins_list.admins[index]
394-
372+
admins_list.admins = [admin for admin in admins_list.admins if team_id in admin.team_ids] # type: ignore
395373
return admins_list</code></pre>
396374
</details>
397375
</dd>
398376
<dt id="intercom_python_sdk.apis.admins.api.AdminsAPI.list_admins"><code class="name flex">
399377
<span>def <span class="ident">list_admins</span></span>(<span>self)</span>
400378
</code></dt>
401379
<dd>
402-
<div class="desc"><p>List all admins. </p>
380+
<div class="desc"><p>List all admins.</p>
403381
<h2 id="returns">Returns</h2>
404382
<dl>
405383
<dt><code>AdminList</code></dt>
@@ -409,11 +387,11 @@ <h2 id="returns">Returns</h2>
409387
<summary>
410388
<span>Expand source code</span>
411389
</summary>
412-
<pre><code class="python">@returns(AdminListSchema) # type: ignore
390+
<pre><code class="python">@returns(AdminListSchema) # type: ignore
413391
@get(&#34;&#34;)
414392
def list_admins(self):
415-
&#34;&#34;&#34; List all admins.
416-
393+
&#34;&#34;&#34; List all admins.
394+
417395
Returns:
418396
AdminList: The list of admins.
419397
&#34;&#34;&#34;</code></pre>
@@ -423,7 +401,7 @@ <h2 id="returns">Returns</h2>
423401
<span>def <span class="ident">me</span></span>(<span>self)</span>
424402
</code></dt>
425403
<dd>
426-
<div class="desc"><p>Get the current admin user. </p>
404+
<div class="desc"><p>Get the current admin user.</p>
427405
<h2 id="returns">Returns</h2>
428406
<dl>
429407
<dt><code>Admin</code></dt>
@@ -433,11 +411,11 @@ <h2 id="returns">Returns</h2>
433411
<summary>
434412
<span>Expand source code</span>
435413
</summary>
436-
<pre><code class="python">@returns(AdminSchema) # type: ignore
437-
@get(&#34;/me&#34;) # We are adding a leading slash here because we actually WANT to ignore the /admins URI in this case.
414+
<pre><code class="python">@returns(AdminSchema) # type: ignore
415+
@get(&#34;/me&#34;) # We are adding a leading slash here because we actually WANT to ignore the /admins URI in this case.
438416
def me(self):
439-
&#34;&#34;&#34; Get the current admin user.
440-
417+
&#34;&#34;&#34; Get the current admin user.
418+
441419
Returns:
442420
Admin: The current admin user.
443421
&#34;&#34;&#34;</code></pre>
@@ -477,7 +455,7 @@ <h2 id="returns">Returns</h2>
477455
Returns:
478456
HTTPResponse: The response from the API.
479457
&#34;&#34;&#34;
480-
return self.__set_away_by_id(admin_id, {&#34;away_mode_enabled&#34;:away, &#34;away_mode_reassign&#34;:reassign})</code></pre>
458+
return self.__set_away_by_id(admin_id, {&#34;away_mode_enabled&#34;: away, &#34;away_mode_reassign&#34;: reassign})</code></pre>
481459
</details>
482460
</dd>
483461
</dl>

0 commit comments

Comments
 (0)