|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""Webex Teams Room Tabs API wrapper. |
| 3 | +
|
| 4 | +Copyright (c) 2016-2020 Cisco and/or its affiliates. |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all |
| 14 | +copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +SOFTWARE. |
| 23 | +""" |
| 24 | + |
| 25 | + |
| 26 | +from __future__ import ( |
| 27 | + absolute_import, |
| 28 | + division, |
| 29 | + print_function, |
| 30 | + unicode_literals, |
| 31 | +) |
| 32 | + |
| 33 | +from builtins import * |
| 34 | + |
| 35 | +from past.builtins import basestring |
| 36 | + |
| 37 | +from ..generator_containers import generator_container |
| 38 | +from ..restsession import RestSession |
| 39 | +from ..utils import ( |
| 40 | + check_type, |
| 41 | + dict_from_items_with_values, |
| 42 | +) |
| 43 | + |
| 44 | + |
| 45 | +API_ENDPOINT = 'room/tabs' |
| 46 | +OBJECT_TYPE = 'room_tab' |
| 47 | + |
| 48 | + |
| 49 | +class RoomTabsAPI(object): |
| 50 | + """Webex Teams Room Tabs API. |
| 51 | +
|
| 52 | + Wraps the Webex Teams Room Tabs API and exposes the API as native Python |
| 53 | + methods that return native Python objects. |
| 54 | +
|
| 55 | + """ |
| 56 | + |
| 57 | + def __init__(self, session, object_factory): |
| 58 | + """Initialize a new RoomTabsAPI object with the provided RestSession. |
| 59 | +
|
| 60 | + Args: |
| 61 | + session(RestSession): The RESTful session object to be used for |
| 62 | + API calls to the Webex Teams service. |
| 63 | +
|
| 64 | + Raises: |
| 65 | + TypeError: If the parameter types are incorrect. |
| 66 | +
|
| 67 | + """ |
| 68 | + check_type(session, RestSession) |
| 69 | + |
| 70 | + super(RoomTabsAPI, self).__init__() |
| 71 | + |
| 72 | + self._session = session |
| 73 | + self._object_factory = object_factory |
| 74 | + |
| 75 | + @generator_container |
| 76 | + def list(self, roomId, **request_parameters): |
| 77 | + """Lists all Room Tabs of a room. roomId query parameter is required to retrieve the response. |
| 78 | +
|
| 79 | + This method supports Webex Teams's implementation of RFC5988 Web |
| 80 | + Linking to provide pagination support. It returns a generator |
| 81 | + container that incrementally yields all room tabs returned by the |
| 82 | + query. The generator will automatically request additional 'pages' of |
| 83 | + responses from Webex as needed until all responses have been returned. |
| 84 | + The container makes the generator safe for reuse. A new API call will |
| 85 | + be made, using the same parameters that were specified when the |
| 86 | + generator was created, every time a new iterator is requested from the |
| 87 | + container. |
| 88 | +
|
| 89 | + Args: |
| 90 | + roomId(basestring): List Room Tabs associated with a room, by ID. |
| 91 | + **request_parameters: Additional request parameters (provides |
| 92 | + support for parameters that may be added in the future). |
| 93 | +
|
| 94 | + Returns: |
| 95 | + GeneratorContainer: A GeneratorContainer which, when iterated, |
| 96 | + yields the room tabs returned by the Webex Teams query. |
| 97 | +
|
| 98 | + Raises: |
| 99 | + TypeError: If the parameter types are incorrect. |
| 100 | + ApiError: If the Webex Teams cloud returns an error. |
| 101 | +
|
| 102 | + """ |
| 103 | + check_type(roomId, basestring) |
| 104 | + |
| 105 | + params = dict_from_items_with_values( |
| 106 | + request_parameters, |
| 107 | + roomId=roomId, |
| 108 | + ) |
| 109 | + |
| 110 | + # API request - get items |
| 111 | + items = self._session.get_items(API_ENDPOINT, params=params) |
| 112 | + |
| 113 | + # Yield room objects created from the returned items JSON objects |
| 114 | + for item in items: |
| 115 | + yield self._object_factory(OBJECT_TYPE, item) |
| 116 | + |
| 117 | + def create(self, roomId, contentUrl, displayName, **request_parameters): |
| 118 | + """Create a room tab. |
| 119 | +
|
| 120 | + Add a tab with a content url to a room that can be accessed in the room |
| 121 | +
|
| 122 | + Args: |
| 123 | + roomId(basestring): A unique identifier for the room. |
| 124 | + contentUrl(basestring): Content Url of the Room Tab. Needs to use the https protocol. |
| 125 | + displayName(basestring): A user-friendly name for the room. |
| 126 | + **request_parameters: Additional request parameters (provides |
| 127 | + support for parameters that may be added in the future). |
| 128 | + Returns: |
| 129 | + RoomTab: A Room Tab with the details of the created room tab. |
| 130 | +
|
| 131 | + Raises: |
| 132 | + TypeError: If the parameter types are incorrect. |
| 133 | + ApiError: If the Webex Teams cloud returns an error. |
| 134 | +
|
| 135 | + """ |
| 136 | + check_type(roomId, basestring) |
| 137 | + check_type(contentUrl, basestring) |
| 138 | + check_type(displayName, basestring) |
| 139 | + |
| 140 | + post_data = dict_from_items_with_values( |
| 141 | + request_parameters, |
| 142 | + roomId=roomId, |
| 143 | + contentUrl=contentUrl, |
| 144 | + displayName=displayName, |
| 145 | + ) |
| 146 | + |
| 147 | + # API request |
| 148 | + json_data = self._session.post(API_ENDPOINT, json=post_data) |
| 149 | + |
| 150 | + # Return a room object created from the response JSON data |
| 151 | + return self._object_factory(OBJECT_TYPE, json_data) |
| 152 | + |
| 153 | + # def get(self, roomId): |
| 154 | + # """Get the details of a room tab, by ID. |
| 155 | + |
| 156 | + # Args: |
| 157 | + # roomId(basestring): The ID of the room to be retrieved. |
| 158 | + |
| 159 | + # Returns: |
| 160 | + # Room: A Room object with the details of the requested room. |
| 161 | + |
| 162 | + # Raises: |
| 163 | + # TypeError: If the parameter types are incorrect. |
| 164 | + # ApiError: If the Webex Teams cloud returns an error. |
| 165 | + |
| 166 | + # """ |
| 167 | + # check_type(roomId, basestring) |
| 168 | + |
| 169 | + # # API request |
| 170 | + # json_data = self._session.get(API_ENDPOINT + '/' + roomId) |
| 171 | + |
| 172 | + # # Return a room object created from the response JSON data |
| 173 | + # return self._object_factory(OBJECT_TYPE, json_data) |
| 174 | + |
| 175 | + def update(self, roomTabId, roomId, contentUrl, displayName, **request_parameters): |
| 176 | + """Updates the content url of a Room Tab by ID. |
| 177 | +
|
| 178 | + Args: |
| 179 | + roomTabId(basestring): The unique identifier for the Room Tab. |
| 180 | + roomId(basestring): The room ID. |
| 181 | + contentUrl(basestring): Content Url of the Room Tab. Needs to use the https protocol. |
| 182 | + displayName(basestring): A user-friendly name for the room. |
| 183 | + **request_parameters: Additional request parameters (provides |
| 184 | + support for parameters that may be added in the future). |
| 185 | +
|
| 186 | + Returns: |
| 187 | + Room: A Room object with the updated Webex Teams room details. |
| 188 | +
|
| 189 | + Raises: |
| 190 | + TypeError: If the parameter types are incorrect. |
| 191 | + ApiError: If the Webex Teams cloud returns an error. |
| 192 | +
|
| 193 | + """ |
| 194 | + check_type(roomTabId, basestring) |
| 195 | + check_type(roomId, basestring) |
| 196 | + check_type(contentUrl, basestring) |
| 197 | + check_type(displayName, basestring) |
| 198 | + |
| 199 | + put_data = dict_from_items_with_values( |
| 200 | + request_parameters, |
| 201 | + roomTabId=roomTabId, |
| 202 | + roomId=roomId, |
| 203 | + contentUrl=contentUrl, |
| 204 | + displayName=displayName, |
| 205 | + ) |
| 206 | + |
| 207 | + # API request |
| 208 | + json_data = self._session.put(API_ENDPOINT + '/' + roomTabId, |
| 209 | + json=put_data) |
| 210 | + |
| 211 | + # Return a room object created from the response JSON data |
| 212 | + return self._object_factory(OBJECT_TYPE, json_data) |
| 213 | + |
| 214 | + |
| 215 | + def delete(self, roomTabId): |
| 216 | + """Delete a room tab. |
| 217 | +
|
| 218 | + Args: |
| 219 | + roomTabId(basestring): The ID of the room tab to be deleted. |
| 220 | +
|
| 221 | + Raises: |
| 222 | + TypeError: If the parameter types are incorrect. |
| 223 | + ApiError: If the Webex Teams cloud returns an error. |
| 224 | +
|
| 225 | + """ |
| 226 | + check_type(roomTabId, basestring) |
| 227 | + |
| 228 | + # API request |
| 229 | + self._session.delete(API_ENDPOINT + '/' + roomTabId) |
0 commit comments