File size: 18,340 Bytes
550665c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
from typing import Union, List
from uuid import uuid4
class SolutionType:
"""
* HANGOUT - for Hangouts for consumers (hangouts.google.com)
* NAMED_HANGOUT - for classic Hangouts for Google Workspace users (hangouts.google.com)
* HANGOUTS_MEET - for Google Meet (meet.google.com)
* ADD_ON - for 3P conference providers
"""
HANGOUT = 'eventHangout'
NAMED_HANGOUT = 'eventNamedHangout'
HANGOUTS_MEET = 'hangoutsMeet'
ADD_ON = 'addOn'
class _BaseConferenceSolution:
"""General conference-related information."""
def __init__(
self,
conference_id: str = None,
signature: str = None,
notes: str = None,
_status: str = 'success'
):
"""
:param conference_id:
The ID of the conference. Optional.
Can be used by developers to keep track of conferences, should not be displayed to users.
Values for solution types (see :py:class:`~gcsa.conference.SolutionType`):
* HANGOUT: unset
* NAMED_HANGOUT: the name of the Hangout
* HANGOUTS_MEET: the 10-letter meeting code, for example "aaa-bbbb-ccc"
* ADD_ON: defined by 3P conference provider
:param signature:
The signature of the conference data.
Generated on server side. Must be preserved while copying the conference data between events,
otherwise the conference data will not be copied.
None for a conference with a failed create request.
Optional for a conference with a pending create request.
:param notes:
String of additional notes (such as instructions from the domain administrator, legal notices)
to display to the user. Can contain HTML. The maximum length is 2048 characters
:param _status:
The current status of the conference create request. Should not be set by developer.
The possible values are:
* "pending": the conference create request is still being processed.
* "failure": the conference create request failed, there are no entry points.
* "success": the conference create request succeeded, the entry points are populated.
In this case `ConferenceSolution` with created entry points
is stored in the event's `conference_data`. And `ConferenceSolutionCreateRequest` is omitted.
Create requests are asynchronous. Check ``status`` field of event's ``conference_solution`` to find it's
status. If the status is ``"success"``, ``conference_solution`` will contain a
:py:class:`~gcsa.conference.ConferenceSolution` object and you'll be able to access it's field (like
``entry_points``). Otherwise (if ``status`` is ``""pending"`` or ``"failure"``), ``conference_solution``
will contain a :py:class:`~gcsa.conference.ConferenceSolutionCreateRequest` object.
"""
if notes and len(notes) > 2048:
raise ValueError('Maximum notes length is 2048 characters.')
self.conference_id = conference_id
self.signature = signature
self.notes = notes
self.status = _status
def __eq__(self, other):
if not isinstance(other, _BaseConferenceSolution):
return NotImplemented
elif self is other:
return True
else:
return (
self.conference_id == other.conference_id
and self.signature == other.signature
and self.notes == other.notes
)
class EntryPoint:
"""Information about individual conference entry points, such as URLs or phone numbers."""
VIDEO = 'video'
PHONE = 'phone'
SIP = 'sip'
MORE = 'more'
ENTRY_POINT_TYPES = (VIDEO, PHONE, SIP, MORE)
def __init__(
self,
entry_point_type: str,
uri: str = None,
label: str = None,
pin: str = None,
access_code: str = None,
meeting_code: str = None,
passcode: str = None,
password: str = None
):
"""
When creating new conference data, populate only the subset of `meeting_code`, `access_code`, `passcode`,
`password`, and `pin` fields that match the terminology that the conference provider uses.
Only the populated fields should be displayed.
:param entry_point_type:
The type of the conference entry point.
Possible values are:
* VIDEO - joining a conference over HTTP.
A conference can have zero or one `VIDEO` entry point.
* PHONE - joining a conference by dialing a phone number.
A conference can have zero or more `PHONE` entry points.
* SIP - joining a conference over SIP.
A conference can have zero or one `SIP` entry point.
* MORE - further conference joining instructions, for example additional phone numbers.
A conference can have zero or one `MORE` entry point.
A conference with only a `MORE` entry point is not a valid conference.
:param uri:
The URI of the entry point. The maximum length is 1300 characters.
Format:
* for `VIDEO`, http: or https: schema is required.
* for `PHONE`, tel: schema is required.
The URI should include the entire dial sequence (e.g., tel:+12345678900,,,123456789;1234).
* for `SIP`, sip: schema is required, e.g., sip:[email protected].
* for `MORE`, http: or https: schema is required.
:param label:
The label for the URI.
Visible to end users. Not localized. The maximum length is 512 characters.
Examples:
* for `VIDEO`: meet.google.com/aaa-bbbb-ccc
* for `PHONE`: +1 123 268 2601
* for `SIP`: [email protected]
* for `MORE`: should not be filled
:param pin:
The PIN to access the conference. The maximum length is 128 characters.
:param access_code:
The access code to access the conference. The maximum length is 128 characters. Optional.
:param meeting_code:
The meeting code to access the conference. The maximum length is 128 characters.
:param passcode:
The passcode to access the conference. The maximum length is 128 characters.
:param password:
The password to access the conference. The maximum length is 128 characters.
"""
if entry_point_type and entry_point_type not in self.ENTRY_POINT_TYPES:
raise ValueError('"entry_point" must be one of {}. {} was provided.'.format(
', '.join(self.ENTRY_POINT_TYPES),
entry_point_type
))
if label and len(label) > 512:
raise ValueError('Maximum label length is 512 characters.')
if pin and len(pin) > 128:
raise ValueError('Maximum pin length is 128 characters.')
if access_code and len(access_code) > 128:
raise ValueError('Maximum access_code length is 128 characters.')
if meeting_code and len(meeting_code) > 128:
raise ValueError('Maximum meeting_code length is 128 characters.')
if passcode and len(passcode) > 128:
raise ValueError('Maximum passcode length is 128 characters.')
if password and len(password) > 128:
raise ValueError('Maximum password length is 128 characters.')
self.entry_point_type = entry_point_type
self.uri = uri
self.label = label
self.pin = pin
self.access_code = access_code
self.meeting_code = meeting_code
self.passcode = passcode
self.password = password
def __eq__(self, other):
if not isinstance(other, EntryPoint):
return NotImplemented
elif self is other:
return True
else:
return (
self.entry_point_type == other.entry_point_type
and self.uri == other.uri
and self.label == other.label
and self.pin == other.pin
and self.access_code == other.access_code
and self.meeting_code == other.meeting_code
and self.passcode == other.passcode
and self.password == other.password
)
def __str__(self):
return "{} - '{}'".format(self.entry_point_type, self.uri)
def __repr__(self):
return '<EntryPoint {}>'.format(self.__str__())
class ConferenceSolution(_BaseConferenceSolution):
"""Information about the conference solution, such as Hangouts or Google Meet."""
def __init__(
self,
entry_points: Union[EntryPoint, List[EntryPoint]],
solution_type: str = None,
name: str = None,
icon_uri: str = None,
conference_id: str = None,
signature: str = None,
notes: str = None
):
"""
:param entry_points:
:py:class:`~gcsa.conference.EntryPoint` or list of :py:class:`~gcsa.conference.EntryPoint` s.
Information about individual conference entry points, such as URLs or phone numbers.
All of them must belong to the same conference.
:param solution_type:
Solution type. See :py:class:`~gcsa.conference.SolutionType`
The possible values are:
* HANGOUT - for Hangouts for consumers (hangouts.google.com)
* NAMED_HANGOUT - for classic Hangouts for Google Workspace users (hangouts.google.com)
* HANGOUTS_MEET - for Google Meet (meet.google.com)
* ADD_ON - for 3P conference providers
:param name:
The user-visible name of this solution. Not localized.
:param icon_uri:
The user-visible icon for this solution.
:param conference_id:
The ID of the conference. Optional.
Can be used by developers to keep track of conferences, should not be displayed to users.
Values for solution types (see :py:class:`~gcsa.conference.SolutionType`):
* HANGOUT: unset
* NAMED_HANGOUT: the name of the Hangout
* HANGOUTS_MEET: the 10-letter meeting code, for example "aaa-bbbb-ccc"
* ADD_ON: defined by 3P conference provider
:param signature:
The signature of the conference data.
Generated on server side. Must be preserved while copying the conference data between events,
otherwise the conference data will not be copied.
None for a conference with a failed create request.
Optional for a conference with a pending create request.
:param notes:
String of additional notes (such as instructions from the domain administrator, legal notices)
to display to the user. Can contain HTML. The maximum length is 2048 characters
"""
super().__init__(conference_id=conference_id, signature=signature, notes=notes)
self.entry_points = [entry_points] if isinstance(entry_points, EntryPoint) else entry_points
self._check_entry_points()
self.solution_type = solution_type
self.name = name
self.icon_uri = icon_uri
def _check_entry_points(self):
"""
Checks counts of entry points types.
* A conference can have zero or one `VIDEO` entry point.
* A conference can have zero or more `PHONE` entry points.
* A conference can have zero or one `SIP` entry point.
* A conference can have zero or one `MORE` entry point.
A conference with only a `MORE` entry point is not a valid conference.
"""
if len(self.entry_points) == 0:
raise ValueError('At least one entry point has to be provided.')
video_count = 0
sip_count = 0
more_count = 0
for ep in self.entry_points:
if ep.entry_point_type == EntryPoint.VIDEO:
video_count += 1
elif ep.entry_point_type == EntryPoint.SIP:
sip_count += 1
elif ep.entry_point_type == EntryPoint.MORE:
more_count += 1
if video_count > 1:
raise ValueError('A conference can have zero or one `VIDEO` entry point.')
if sip_count > 1:
raise ValueError('A conference can have zero or one `SIP` entry point.')
if more_count > 1:
raise ValueError('A conference can have zero or one `MORE` entry point.')
if more_count == len(self.entry_points):
raise ValueError('A conference with only a `MORE` entry point is not a valid conference.')
def __eq__(self, other):
if not isinstance(other, ConferenceSolution):
return NotImplemented
elif self is other:
return True
else:
return (
super().__eq__(other)
and self.entry_points == other.entry_points
and self.solution_type == other.solution_type
and self.name == other.name
and self.icon_uri == other.icon_uri
)
def __str__(self):
return '{} - {}'.format(self.solution_type, self.entry_points)
def __repr__(self):
return '<ConferenceSolution {}>'.format(self.__str__())
class ConferenceSolutionCreateRequest(_BaseConferenceSolution):
"""
A request to generate a new conference and attach it to the event.
The data is generated asynchronously. To see whether the data is present check the status field.
"""
def __init__(
self,
solution_type: str = None,
request_id: str = None,
_status: str = None,
conference_id: str = None,
signature: str = None,
notes: str = None
):
"""
:param solution_type:
Solution type. See :py:class:`~gcsa.conference.SolutionType`
The possible values are:
* HANGOUT - for Hangouts for consumers (hangouts.google.com)
* NAMED_HANGOUT - for classic Hangouts for Google Workspace users (hangouts.google.com)
* HANGOUTS_MEET - for Google Meet (meet.google.com)
* ADD_ON - for 3P conference providers
:param request_id:
The client-generated unique ID for this request.
By default it is generated as UUID.
If you specify request_id manually, they should be unique for every new CreateRequest,
otherwise request will be ignored.
:param _status:
The current status of the conference create request. Should not be set by developer.
The possible values are:
* "pending": the conference create request is still being processed.
* "failure": the conference create request failed, there are no entry points.
* "success": the conference create request succeeded, the entry points are populated.
In this case `ConferenceSolution` with created entry points
is stored in the event's `conference_data`. And `ConferenceSolutionCreateRequest` is omitted.
:param conference_id:
The ID of the conference. Optional.
Can be used by developers to keep track of conferences, should not be displayed to users.
Values for solution types (see :py:class:`~gcsa.conference.SolutionType`):
* HANGOUT: unset
* NAMED_HANGOUT: the name of the Hangout
* HANGOUTS_MEET: the 10-letter meeting code, for example "aaa-bbbb-ccc"
* ADD_ON: defined by 3P conference provider
:param signature:
The signature of the conference data.
Generated on server side. Must be preserved while copying the conference data between events,
otherwise the conference data will not be copied.
None for a conference with a failed create request.
Optional for a conference with a pending create request.
:param notes:
String of additional notes (such as instructions from the domain administrator, legal notices)
to display to the user. Can contain HTML. The maximum length is 2048 characters
"""
super().__init__(conference_id=conference_id, signature=signature, notes=notes, _status=_status)
self.request_id = request_id or uuid4().hex
self.solution_type = solution_type
def __eq__(self, other):
if not isinstance(other, ConferenceSolutionCreateRequest):
return NotImplemented
elif self is other:
return True
else:
return (
super().__eq__(other)
and self.request_id == other.request_id
and self.solution_type == other.solution_type
and self.status == other.status
)
def __str__(self):
return "{} - status:'{}'".format(self.solution_type, self.status)
def __repr__(self):
return '<ConferenceSolutionCreateRequest {}>'.format(self.__str__())
|