Skip to content

Commit df261f1

Browse files
authored
Create user client (#34)
* Create user client * update * model init * model init * model init * alias
1 parent c07ee45 commit df261f1

File tree

23 files changed

+514
-29
lines changed

23 files changed

+514
-29
lines changed

packages/api/src/microsoft/teams/api/clients/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
from .bot import __all__ as bot_all
88
from .conversation import * # noqa: F403
99
from .conversation import __all__ as conversation_all
10+
from .user import * # noqa: F403
11+
from .user import __all__ as user_all
1012

1113
__all__ = [
1214
*conversation_all,
15+
*user_all,
1316
*bot_all,
1417
]

packages/api/src/microsoft/teams/api/clients/base_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ def __init__(self, options: Optional[Union[Client, ClientOptions]] = None) -> No
1717
Args:
1818
options: Optional Client or ClientOptions instance. If not provided, a default Client will be created.
1919
"""
20-
self._http = Client(options or ClientOptions())
20+
if options is None:
21+
self._http = Client(ClientOptions())
22+
elif isinstance(options, Client):
23+
self._http = options
24+
else:
25+
self._http = Client(options)
2126

2227
@property
2328
def http(self) -> Client:

packages/api/src/microsoft/teams/api/clients/bot/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ def __init__(self, options: Optional[Union[Client, ClientOptions]] = None) -> No
2424
super().__init__(options)
2525
self.token = BotTokenClient(self.http)
2626
self.sign_in = BotSignInClient(self.http)
27+
28+
@property
29+
def http(self) -> Client:
30+
"""Get the HTTP client instance."""
31+
return self._http
32+
33+
@http.setter
34+
def http(self, value: Client) -> None:
35+
"""Set the HTTP client instance and propagate to sub-clients."""
36+
self._http = value
37+
self.token.http = value
38+
self.sign_in.http = value

packages/api/src/microsoft/teams/api/clients/bot/params.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
from typing import Optional
77

8-
from pydantic import AliasGenerator, BaseModel, ConfigDict
8+
from pydantic import BaseModel, ConfigDict
99
from pydantic.alias_generators import to_camel
1010

1111

1212
class GetBotSignInUrlParams(BaseModel):
1313
"""Parameters for getting a bot sign-in URL."""
1414

1515
model_config = ConfigDict(
16-
alias_generator=AliasGenerator(serialization_alias=to_camel),
16+
alias_generator=to_camel,
1717
extra="allow",
1818
)
1919

@@ -39,7 +39,7 @@ class GetBotSignInResourceParams(BaseModel):
3939
"""Parameters for getting a bot sign-in resource."""
4040

4141
model_config = ConfigDict(
42-
alias_generator=AliasGenerator(serialization_alias=to_camel),
42+
alias_generator=to_camel,
4343
extra="allow",
4444
)
4545

packages/api/src/microsoft/teams/api/clients/conversation/client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ def __init__(self, service_url: str, options: Optional[Union[Client, ClientOptio
7474
self._activities = ConversationActivityClient(service_url, self.http)
7575
self._members = ConversationMemberClient(service_url, self.http)
7676

77+
@property
78+
def http(self) -> Client:
79+
"""Get the HTTP client instance."""
80+
return self._http
81+
82+
@http.setter
83+
def http(self, value: Client) -> None:
84+
"""Set the HTTP client instance and propagate to sub-clients."""
85+
self._http = value
86+
self._activities.http = value
87+
self._members.http = value
88+
7789
def activities(self, conversation_id: str) -> ActivityOperations:
7890
"""Get activity operations for a conversation.
7991
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from .client import UserClient
7+
from .params import (
8+
ExchangeUserTokenParams,
9+
GetUserAADTokenParams,
10+
GetUserTokenParams,
11+
GetUserTokenStatusParams,
12+
SignOutUserParams,
13+
)
14+
from .token_client import UserTokenClient
15+
16+
__all__ = [
17+
"UserClient",
18+
"UserTokenClient",
19+
"GetUserTokenParams",
20+
"GetUserAADTokenParams",
21+
"GetUserTokenStatusParams",
22+
"SignOutUserParams",
23+
"ExchangeUserTokenParams",
24+
]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from typing import Optional, Union
7+
8+
from microsoft.teams.common.http import Client, ClientOptions
9+
10+
from ..base_client import BaseClient
11+
from .token_client import UserTokenClient
12+
13+
14+
class UserClient(BaseClient):
15+
"""Client for managing Teams users."""
16+
17+
def __init__(self, options: Optional[Union[Client, ClientOptions]] = None) -> None:
18+
"""
19+
Initialize the UserClient.
20+
21+
Args:
22+
options: Optional Client or ClientOptions instance. If not provided, a default Client will be created.
23+
"""
24+
super().__init__(options)
25+
26+
self.token = UserTokenClient(self.http)
27+
28+
@property
29+
def http(self) -> Client:
30+
"""Get the HTTP client instance."""
31+
return self._http
32+
33+
@http.setter
34+
def http(self, value: Client) -> None:
35+
"""Set the HTTP client instance and propagate to sub-clients."""
36+
self._http = value
37+
self.token.http = value
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
"""
2+
Copyright (c) Microsoft Corporation. All rights reserved.
3+
Licensed under the MIT License.
4+
"""
5+
6+
from typing import List, Optional
7+
8+
from pydantic import AliasGenerator, BaseModel, ConfigDict
9+
from pydantic.alias_generators import to_camel
10+
11+
from ...models import ChannelID, TokenExchangeRequest
12+
13+
14+
class GetUserTokenParams(BaseModel):
15+
"""Parameters for getting a user token."""
16+
17+
model_config = ConfigDict(
18+
alias_generator=AliasGenerator(
19+
serialization_alias=to_camel,
20+
),
21+
extra="allow",
22+
)
23+
24+
user_id: str
25+
"""
26+
The user ID.
27+
"""
28+
connection_name: str
29+
"""
30+
The connection name.
31+
"""
32+
channel_id: Optional[ChannelID] = None
33+
"""
34+
The channel ID.
35+
"""
36+
code: Optional[str] = None
37+
"""
38+
The authorization code.
39+
"""
40+
41+
42+
class GetUserAADTokenParams(BaseModel):
43+
"""Parameters for getting AAD tokens for a user."""
44+
45+
model_config = ConfigDict(
46+
alias_generator=AliasGenerator(
47+
serialization_alias=to_camel,
48+
),
49+
extra="allow",
50+
)
51+
52+
user_id: str
53+
"""
54+
The user ID.
55+
"""
56+
connection_name: str
57+
"""
58+
The connection name.
59+
"""
60+
resource_urls: List[str]
61+
"""
62+
The resource URLs.
63+
"""
64+
channel_id: ChannelID
65+
"""
66+
The channel ID.
67+
"""
68+
69+
70+
class GetUserTokenStatusParams(BaseModel):
71+
"""Parameters for getting token status for a user."""
72+
73+
model_config = ConfigDict(
74+
alias_generator=AliasGenerator(
75+
serialization_alias=to_camel,
76+
),
77+
extra="allow",
78+
)
79+
80+
user_id: str
81+
"""
82+
The user ID.
83+
"""
84+
channel_id: ChannelID
85+
"""
86+
The channel ID.
87+
"""
88+
include_filter: str
89+
"""
90+
The include filter.
91+
"""
92+
93+
94+
class SignOutUserParams(BaseModel):
95+
"""Parameters for signing out a user."""
96+
97+
model_config = ConfigDict(
98+
alias_generator=AliasGenerator(
99+
serialization_alias=to_camel,
100+
),
101+
extra="allow",
102+
)
103+
104+
user_id: str
105+
"""
106+
The user ID.
107+
"""
108+
connection_name: str
109+
"""
110+
The connection name.
111+
"""
112+
channel_id: ChannelID
113+
"""
114+
The channel ID.
115+
"""
116+
117+
118+
class ExchangeUserTokenParams(BaseModel):
119+
"""Parameters for exchanging a user token."""
120+
121+
model_config = ConfigDict(
122+
alias_generator=AliasGenerator(
123+
serialization_alias=to_camel,
124+
),
125+
extra="allow",
126+
)
127+
128+
user_id: str
129+
"""
130+
The user ID.
131+
"""
132+
connection_name: str
133+
"""
134+
The connection name.
135+
"""
136+
channel_id: ChannelID
137+
"""
138+
The channel ID.
139+
"""
140+
exchange_request: TokenExchangeRequest
141+
"""
142+
The token exchange request.
143+
"""

0 commit comments

Comments
 (0)