Skip to content

Commit 03bed39

Browse files
authored
[Communication] - SDK - Synced SMS and Phone Numbers shared folders (#17985)
* Sync SMS and PNM shared folders * Added typing extensions * Sync other shared folder files
1 parent 5bf3d84 commit 03bed39

File tree

11 files changed

+353
-447
lines changed

11 files changed

+353
-447
lines changed

sdk/communication/azure-communication-phonenumbers/azure/communication/phonenumbers/_shared/models.py

Lines changed: 119 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -6,210 +6,151 @@
66

77
from enum import Enum, EnumMeta
88
from six import with_metaclass
9+
from typing import Mapping, Optional, Union, Any
10+
try:
11+
from typing import Protocol, TypedDict
12+
except ImportError:
13+
from typing_extensions import Protocol, TypedDict
914

10-
import msrest
15+
from azure.core import CaseInsensitiveEnumMeta
1116

12-
class CommunicationError(msrest.serialization.Model):
13-
"""The Communication Services error.
1417

15-
Variables are only populated by the server, and will be ignored when sending a request.
18+
class CommunicationIdentifierKind(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)):
19+
"""Communication Identifier Kind."""
1620

17-
All required parameters must be populated in order to send to Azure.
21+
UNKNOWN = "unknown"
22+
COMMUNICATION_USER = "communication_user"
23+
PHONE_NUMBER = "phone_number"
24+
MICROSOFT_TEAMS_USER = "microsoft_teams_user"
25+
26+
27+
class CommunicationCloudEnvironment(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)):
28+
"""The cloud enviornment that the identifier belongs to"""
29+
30+
PUBLIC = "PUBLIC"
31+
DOD = "DOD"
32+
GCCH = "GCCH"
1833

19-
:param code: Required. The error code.
20-
:type code: str
21-
:param message: Required. The error message.
22-
:type message: str
23-
:ivar target: The error target.
24-
:vartype target: str
25-
:ivar details: Further details about specific errors that led to this error.
26-
:vartype details: list[~communication.models.CommunicationError]
27-
:ivar inner_error: The inner error if any.
28-
:vartype inner_error: ~communication.models.CommunicationError
29-
"""
3034

31-
_validation = {
32-
'code': {'required': True},
33-
'message': {'required': True},
34-
'target': {'readonly': True},
35-
'details': {'readonly': True},
36-
'inner_error': {'readonly': True},
37-
}
38-
39-
_attribute_map = {
40-
'code': {'key': 'code', 'type': 'str'},
41-
'message': {'key': 'message', 'type': 'str'},
42-
'target': {'key': 'target', 'type': 'str'},
43-
'details': {'key': 'details', 'type': '[CommunicationError]'},
44-
'inner_error': {'key': 'innererror', 'type': 'CommunicationError'},
45-
}
46-
47-
def __init__(
48-
self,
49-
**kwargs
50-
):
51-
super(CommunicationError, self).__init__(**kwargs)
52-
self.code = kwargs['code']
53-
self.message = kwargs['message']
54-
self.target = None
55-
self.details = None
56-
self.inner_error = None
57-
58-
59-
class CommunicationErrorResponse(msrest.serialization.Model):
60-
"""The Communication Services error.
61-
62-
All required parameters must be populated in order to send to Azure.
63-
64-
:param error: Required. The Communication Services error.
65-
:type error: ~communication.models.CommunicationError
35+
class CommunicationIdentifier(Protocol):
36+
"""Communication Identifier.
37+
38+
:ivar str raw_id: Optional raw ID of the identifier.
39+
:ivar kind: The type of identifier.
40+
:vartype kind: str or CommunicationIdentifierKind
41+
:ivar Mapping[str, Any] properties: The properties of the identifier.
6642
"""
43+
raw_id = None # type: Optional[str]
44+
kind = None # type: Optional[Union[CommunicationIdentifierKind, str]]
45+
properties = {} # type: Mapping[str, Any]
6746

68-
_validation = {
69-
'error': {'required': True},
70-
}
7147

72-
_attribute_map = {
73-
'error': {'key': 'error', 'type': 'CommunicationError'},
74-
}
48+
CommunicationUserProperties = TypedDict(
49+
'CommunicationUserProperties',
50+
id=str
51+
)
7552

76-
def __init__(
77-
self,
78-
**kwargs
79-
):
80-
super(CommunicationErrorResponse, self).__init__(**kwargs)
81-
self.error = kwargs['error']
8253

8354
class CommunicationUserIdentifier(object):
55+
"""Represents a user in Azure Communication Service.
56+
57+
:ivar str raw_id: Optional raw ID of the identifier.
58+
:ivar kind: The type of identifier.
59+
:vartype kind: str or CommunicationIdentifierKind
60+
:ivar Mapping[str, Any] properties: The properties of the identifier.
61+
The keys in this mapping include:
62+
- `id`(str): ID of the Communication user as returned from Azure Communication Identity.
63+
64+
:param str id: ID of the Communication user as returned from Azure Communication Identity.
8465
"""
85-
Represents a user in Azure Communication Service.
86-
:ivar identifier: Communication user identifier.
87-
:vartype identifier: str
88-
:param identifier: Identifier to initialize CommunicationUserIdentifier.
89-
:type identifier: str
90-
"""
91-
def __init__(self, identifier):
92-
self.identifier = identifier
66+
kind = CommunicationIdentifierKind.COMMUNICATION_USER
67+
68+
def __init__(self, id, **kwargs):
69+
# type: (str, Any) -> None
70+
self.raw_id = kwargs.get('raw_id')
71+
self.properties = CommunicationUserProperties(id=id)
72+
73+
74+
PhoneNumberProperties = TypedDict(
75+
'PhoneNumberProperties',
76+
value=str
77+
)
78+
9379

9480
class PhoneNumberIdentifier(object):
81+
"""Represents a phone number.
82+
83+
:ivar str raw_id: Optional raw ID of the identifier.
84+
:ivar kind: The type of identifier.
85+
:vartype kind: str or CommunicationIdentifierKind
86+
:ivar Mapping properties: The properties of the identifier.
87+
The keys in this mapping include:
88+
- `value`(str): The phone number in E.164 format.
89+
90+
:param str value: The phone number.
9591
"""
96-
Represents a phone number.
97-
:param phone_number: The phone number in E.164 format.
98-
:type phone_number: str
99-
:param raw_id: The full id of the phone number.
100-
:type raw_id: str
101-
"""
102-
def __init__(self, phone_number, raw_id=None):
103-
self.phone_number = phone_number
104-
self.raw_id = raw_id
92+
kind = CommunicationIdentifierKind.PHONE_NUMBER
93+
94+
def __init__(self, value, **kwargs):
95+
# type: (str, Any) -> None
96+
self.raw_id = kwargs.get('raw_id')
97+
self.properties = PhoneNumberProperties(value=value)
98+
10599

106100
class UnknownIdentifier(object):
107-
"""
108-
Represents an identifier of an unknown type.
101+
"""Represents an identifier of an unknown type.
102+
109103
It will be encountered in communications with endpoints that are not
110104
identifiable by this version of the SDK.
111-
:ivar raw_id: Unknown communication identifier.
112-
:vartype raw_id: str
113-
:param identifier: Value to initialize UnknownIdentifier.
114-
:type identifier: str
105+
106+
:ivar str raw_id: Optional raw ID of the identifier.
107+
:ivar kind: The type of identifier.
108+
:vartype kind: str or CommunicationIdentifierKind
109+
:ivar Mapping properties: The properties of the identifier.
110+
:param str identifier: The ID of the identifier.
115111
"""
112+
kind = CommunicationIdentifierKind.UNKNOWN
113+
116114
def __init__(self, identifier):
115+
# type: (str) -> None
117116
self.raw_id = identifier
117+
self.properties = {}
118118

119-
class CommunicationIdentifierModel(msrest.serialization.Model):
120-
"""Communication Identifier Model.
121-
All required parameters must be populated in order to send to Azure.
122-
:param kind: Required. Kind of Communication Identifier.
123-
:type kind: CommunicationIdentifierKind
124-
:param id: Full id of the identifier.
125-
:type id: str
126-
:param phone_number: phone number in case the identifier is a phone number.
127-
:type phone_number: str
128-
:param is_anonymous: True if the identifier is anonymous.
129-
:type is_anonymous: bool
130-
:param microsoft_teams_user_id: Microsoft Teams user id.
131-
:type microsoft_teams_user_id: str
132-
:param communication_cloud_environment: Cloud environment that the user belongs to.
133-
:type communication_cloud_environment: CommunicationCloudEnvironment
134-
"""
135119

136-
_validation = {
137-
'kind': {'required': True},
138-
}
139-
140-
_attribute_map = {
141-
'kind': {'key': 'kind', 'type': 'str'},
142-
'id': {'key': 'id', 'type': 'str'},
143-
'phone_number': {'key': 'phoneNumber', 'type': 'str'},
144-
'is_anonymous': {'key': 'isAnonymous', 'type': 'bool'},
145-
'microsoft_teams_user_id': {'key': 'microsoftTeamsUserId', 'type': 'str'},
146-
'communication_cloud_environment': {'key': 'communicationCloudEnvironment', 'type': 'str'},
147-
}
148-
149-
def __init__(
150-
self,
151-
**kwargs
152-
):
153-
super(CommunicationIdentifierModel, self).__init__(**kwargs)
154-
self.kind = kwargs['kind']
155-
self.id = kwargs.get('id', None)
156-
self.phone_number = kwargs.get('phone_number', None)
157-
self.is_anonymous = kwargs.get('is_anonymous', None)
158-
self.microsoft_teams_user_id = kwargs.get('microsoft_teams_user_id', None)
159-
self.communication_cloud_environment = kwargs.get('communication_cloud_environment', None)
160-
161-
class _CaseInsensitiveEnumMeta(EnumMeta):
162-
def __getitem__(self, name):
163-
return super().__getitem__(name.upper())
164-
165-
def __getattr__(cls, name):
166-
"""Return the enum member matching `name`
167-
We use __getattr__ instead of descriptors or inserting into the enum
168-
class' __dict__ in order to support `name` and `value` being both
169-
properties for enum members (which live in the class' __dict__) and
170-
enum members themselves.
171-
"""
172-
try:
173-
return cls._member_map_[name.upper()]
174-
except KeyError:
175-
raise AttributeError(name)
176-
177-
class CommunicationIdentifierKind(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)):
178-
"""Communication Identifier Kind.
179-
"""
180-
Unknown = "UNKNOWN"
181-
CommunicationUser = "COMMUNICATIONUSER"
182-
PhoneNumber = "PHONENUMBER"
183-
CallingApplication = "CALLINGAPPLICATION"
184-
MicrosoftTeamsUser = "MICROSOFTTEAMSUSER"
120+
MicrosoftTeamsUserProperties = TypedDict(
121+
'MicrosoftTeamsUserProperties',
122+
user_id=str,
123+
is_anonymous=bool,
124+
cloud=Union[CommunicationCloudEnvironment, str]
125+
)
185126

186-
class CommunicationCloudEnvironment(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)):
187-
"""
188-
The cloud enviornment that the identifier belongs to
189-
"""
190-
191-
Public = "PUBLIC"
192-
Dod = "DOD"
193-
Gcch = "GCCH"
194127

195128
class MicrosoftTeamsUserIdentifier(object):
129+
"""Represents an identifier for a Microsoft Teams user.
130+
131+
:ivar str raw_id: Optional raw ID of the identifier.
132+
:ivar kind: The type of identifier.
133+
:vartype kind: str or CommunicationIdentifierKind
134+
:ivar Mapping properties: The properties of the identifier.
135+
The keys in this mapping include:
136+
- `user_id`(str): The id of the Microsoft Teams user. If the user isn't anonymous,
137+
the id is the AAD object id of the user.
138+
- `is_anonymous` (bool): Set this to true if the user is anonymous for example when joining
139+
a meeting with a share link.
140+
- `cloud` (str): Cloud environment that this identifier belongs to.
141+
142+
:param str user_id: Microsoft Teams user id.
143+
:keyword bool is_anonymous: `True` if the identifier is anonymous. Default value is `False`.
144+
:keyword cloud: Cloud environment that the user belongs to. Default value is `PUBLIC`.
145+
:paramtype cloud: str or ~azure.communication.chat.CommunicationCloudEnvironment
196146
"""
197-
Represents an identifier for a Microsoft Teams user.
198-
:ivar user_id: The id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user.
199-
:vartype user_id: str
200-
:param user_id: Value to initialize MicrosoftTeamsUserIdentifier.
201-
:type user_id: str
202-
:ivar raw_id: Raw id of the Microsoft Teams user.
203-
:vartype raw_id: str
204-
:ivar cloud: Cloud environment that this identifier belongs to
205-
:vartype cloud: CommunicationCloudEnvironment
206-
:ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link
207-
:vartype is_anonymous: bool
208-
:param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier.
209-
:type is_anonymous: bool
210-
"""
211-
def __init__(self, user_id, raw_id=None, cloud=CommunicationCloudEnvironment.Public, is_anonymous=False):
212-
self.raw_id = raw_id
213-
self.user_id = user_id
214-
self.is_anonymous = is_anonymous
215-
self.cloud = cloud
147+
kind = CommunicationIdentifierKind.MICROSOFT_TEAMS_USER
148+
149+
def __init__(self, user_id, **kwargs):
150+
# type: (str, Any) -> None
151+
self.raw_id = kwargs.get('raw_id')
152+
self.properties = MicrosoftTeamsUserProperties(
153+
user_id=user_id,
154+
is_anonymous=kwargs.get('is_anonymous', False),
155+
cloud=kwargs.get('cloud') or CommunicationCloudEnvironment.PUBLIC
156+
)

0 commit comments

Comments
 (0)