|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""Webex Teams Messages API wrapper. |
| 3 | +
|
| 4 | +Copyright (c) 2016-2019 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 | +from requests_toolbelt import MultipartEncoder |
| 37 | + |
| 38 | +from ..generator_containers import generator_container |
| 39 | +from ..restsession import RestSession |
| 40 | +from ..utils import ( |
| 41 | + check_type, dict_from_items_with_values, is_local_file, is_web_url, |
| 42 | + open_local_file, |
| 43 | +) |
| 44 | + |
| 45 | + |
| 46 | +API_ENDPOINT = 'attachment/actions' |
| 47 | +OBJECT_TYPE = 'attachment_action' |
| 48 | + |
| 49 | + |
| 50 | +class AttachmentActionsAPI(object): |
| 51 | + """Webex Teams Attachment Actions API. |
| 52 | +
|
| 53 | + Wraps the Webex Teams Attachment Actions API and exposes the API as |
| 54 | + native Python methods that return native Python objects. |
| 55 | +
|
| 56 | + """ |
| 57 | + |
| 58 | + def __init__(self, session, object_factory): |
| 59 | + """Init a new AttachmentActionsAPI object with the provided RestSession. |
| 60 | +
|
| 61 | + Args: |
| 62 | + session(RestSession): The RESTful session object to be used for |
| 63 | + API calls to the Webex Teams service. |
| 64 | +
|
| 65 | + Raises: |
| 66 | + TypeError: If the parameter types are incorrect. |
| 67 | +
|
| 68 | + """ |
| 69 | + check_type(session, RestSession, may_be_none=False) |
| 70 | + super(AttachmentActionsAPI, self).__init__() |
| 71 | + self._session = session |
| 72 | + self._object_factory = object_factory |
| 73 | + |
| 74 | + def create(self, type=None, messageId=None, inputs=None, |
| 75 | + **request_parameters): |
| 76 | + """Create an attachment action. |
| 77 | +
|
| 78 | + Args: |
| 79 | + type(attachment action enum): The type of attachment action. |
| 80 | + messageId(basestring): The ID of parent message the attachment |
| 81 | + action is to be performed on. |
| 82 | + inputs(dict): inputs to attachment fields |
| 83 | + **request_parameters: Additional request parameters (provides |
| 84 | + support for parameters that may be added in the future). |
| 85 | +
|
| 86 | + Returns: |
| 87 | + Attachment action: A attachment action object with the details |
| 88 | + of the created attachment action. |
| 89 | +
|
| 90 | + Raises: |
| 91 | + TypeError: If the parameter types are incorrect. |
| 92 | + ApiError: If the Webex Teams cloud returns an error. |
| 93 | + ValueError: If the files parameter is a list of length > 1, or if |
| 94 | + the string in the list (the only element in the list) does not |
| 95 | + contain a valid URL or path to a local file. |
| 96 | +
|
| 97 | + """ |
| 98 | + |
| 99 | + check_type(type, basestring, may_be_none=False) |
| 100 | + check_type(messageId, basestring, may_be_none=False) |
| 101 | + check_type(inputs, dict, may_be_none=False) |
| 102 | + |
| 103 | + post_data = dict_from_items_with_values( |
| 104 | + request_parameters, |
| 105 | + type=type, |
| 106 | + messageId=messageId, |
| 107 | + inputs=inputs |
| 108 | + ) |
| 109 | + |
| 110 | + json_data = self._session.post(API_ENDPOINT, json=post_data) |
| 111 | + |
| 112 | + # Return a attachment action object created from the response JSON data |
| 113 | + return self._object_factory(OBJECT_TYPE, json_data) |
| 114 | + |
| 115 | + def get(self, attachmentId): |
| 116 | + """Get the details of a attachment action, by ID. |
| 117 | +
|
| 118 | + Args: |
| 119 | + attachmentId(basestring): The ID of the attachment action to be |
| 120 | + retrieved. |
| 121 | +
|
| 122 | + Returns: |
| 123 | + AttachmentAction: A Attachment Action object with the details of |
| 124 | + the requested attachment action. |
| 125 | +
|
| 126 | + Raises: |
| 127 | + TypeError: If the parameter types are incorrect. |
| 128 | + ApiError: If the Webex Teams cloud returns an error. |
| 129 | +
|
| 130 | + """ |
| 131 | + check_type(attachmentId, basestring, may_be_none=False) |
| 132 | + |
| 133 | + # API request |
| 134 | + json_data = self._session.get(API_ENDPOINT + '/' + attachmentId) |
| 135 | + |
| 136 | + # Return a message object created from the response JSON data |
| 137 | + return self._object_factory(OBJECT_TYPE, json_data) |
0 commit comments