Skip to content

Commit a4e9e2a

Browse files
author
zorynbas
committed
attachments actions initial commit
1 parent b9ac306 commit a4e9e2a

File tree

10 files changed

+357
-3
lines changed

10 files changed

+357
-3
lines changed

.DS_Store

8 KB
Binary file not shown.

tests/api/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import webexteamssdk
3030
from tests.environment import WEBEX_TEAMS_ACCESS_TOKEN
3131
from webexteamssdk.api.access_tokens import AccessTokensAPI
32+
from webexteamssdk.api.attachment_actions import AttachmentActionsAPI
3233
from webexteamssdk.api.events import EventsAPI
3334
from webexteamssdk.api.licenses import LicensesAPI
3435
from webexteamssdk.api.memberships import MembershipsAPI
@@ -133,6 +134,10 @@ def test_access_tokens_api_object_creation(api):
133134
assert isinstance(api.access_tokens, AccessTokensAPI)
134135

135136

137+
def test_attachment_actions_api_object_creation(api):
138+
assert isinstance(api.attachment_actions, AttachmentActionsAPI)
139+
140+
136141
def test_events_api_object_creation(api):
137142
assert isinstance(api.events, EventsAPI)
138143

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# -*- coding: utf-8 -*-
2+
"""WebexTeamsAPI Messages API fixtures and tests.
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+
import itertools
26+
27+
import pytest
28+
29+
import webexteamssdk
30+
from tests.environment import WEBEX_TEAMS_TEST_FILE_URL
31+
from tests.utils import create_string
32+
33+
34+
# Helper Functions
35+
36+
def is_valid_attachment_action(obj):
37+
return isinstance(obj, webexteamssdk.AttachmentAction) \
38+
and obj.id is not None
39+
40+
41+
# Fixtures
42+
43+
@pytest.fixture(scope="session")
44+
def attachment_action_create(api, test_people):
45+
person = test_people["member_added_by_email"]
46+
message = api.messages.create(
47+
toPersonEmail=person.emails[0],
48+
text=create_string("Message"),
49+
attachments=[{
50+
"contentType": "application/vnd.microsoft.card.adaptive",
51+
"content": {
52+
"$schema": ("http://adaptivecards.io/schemas/"
53+
"adaptive-card.json"),
54+
"type": "AdaptiveCard",
55+
"version": "1.0",
56+
"body": [{
57+
"type": "ColumnSet",
58+
"columns": [{
59+
"type": "Column",
60+
"width": 2,
61+
"items": [
62+
{
63+
"type": "TextBlock",
64+
"text": "Tell us about your problem",
65+
"weight": "bolder",
66+
"size": "medium"
67+
},
68+
{
69+
"type": "TextBlock",
70+
"text": "Your name",
71+
"wrap": True
72+
},
73+
{
74+
"type": "Input.Text",
75+
"id": "Name",
76+
"placeholder": "John Andersen"
77+
},
78+
{
79+
"type": "TextBlock",
80+
"text": "Your email",
81+
"wrap": True
82+
},
83+
{
84+
"type": "Input.Text",
85+
"id": "Email",
86+
"placeholder": "john.andersen@example.com",
87+
"style": "email"
88+
},
89+
]
90+
}]
91+
}],
92+
"actions": [
93+
{
94+
"type": "Action.Submit",
95+
"title": "Submit"
96+
}
97+
]
98+
}
99+
}]
100+
)
101+
attachment_action = api.attachment_actions.create(
102+
type="submit", messageId=message.id,
103+
inputs={"Name": "test_name", "Email": "test_email"}
104+
)
105+
yield attachment_action
106+
107+
api.messages.delete(message.id)
108+
109+
# Tests
110+
111+
112+
def test_attachment_actions_create(attachment_action_create):
113+
assert is_valid_attachment_action(attachment_action_create)
114+
115+
116+
def test_attachment_actions_get(api, attachment_action_create):
117+
attachment_action = api.attachment_actions.get(attachment_action_create.id)
118+
assert is_valid_attachment_action(attachment_action)

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
pytest_plugins = [
4040
'tests.test_webexteamssdk',
4141
'tests.api',
42+
'tests.api.test_attachment_actions',
4243
'tests.api.test_licenses',
4344
'tests.api.test_memberships',
4445
'tests.api.test_messages',

tests/test_webexteamssdk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def test_package_contents(self):
4343
# Data Models
4444
assert hasattr(webexteamssdk, "dict_data_factory")
4545
assert hasattr(webexteamssdk, "AccessToken")
46+
assert hasattr(webexteamssdk, "AttachmentAction")
4647
assert hasattr(webexteamssdk, "Event")
4748
assert hasattr(webexteamssdk, "License")
4849
assert hasattr(webexteamssdk, "Membership")

webexteamssdk/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
)
4242
from .models.dictionary import dict_data_factory
4343
from .models.immutable import (
44-
AccessToken, Event, License, Membership, Message, Organization, Person,
45-
Role, Room, Team, TeamMembership, Webhook, WebhookEvent,
46-
immutable_data_factory,
44+
AccessToken, AttachmentAction, Event, License, Membership, Message,
45+
Organization, Person, Role, Room, Team, TeamMembership, Webhook,
46+
WebhookEvent, immutable_data_factory,
4747
)
4848
from .models.simple import SimpleDataModel, simple_data_factory
4949
from .utils import WebexTeamsDateTime

webexteamssdk/api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from webexteamssdk.restsession import RestSession
3535
from webexteamssdk.utils import check_type
3636
from .access_tokens import AccessTokensAPI
37+
from .attachment_actions import AttachmentActionsAPI
3738
from .events import EventsAPI
3839
from .guest_issuer import GuestIssuerAPI
3940
from .licenses import LicensesAPI
@@ -179,6 +180,9 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
179180
self.team_memberships = TeamMembershipsAPI(
180181
self._session, object_factory
181182
)
183+
self.attachment_actions = AttachmentActionsAPI(
184+
self._session, object_factory
185+
)
182186
self.webhooks = WebhooksAPI(self._session, object_factory)
183187
self.organizations = OrganizationsAPI(self._session, object_factory)
184188
self.licenses = LicensesAPI(self._session, object_factory)
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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)

webexteamssdk/models/immutable.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
from webexteamssdk.utils import json_dict
4444
from .mixins.access_token import AccessTokenBasicPropertiesMixin
45+
from .mixins.attachment_action import AttachmentActionBasicPropertiesMixin
4546
from .mixins.event import EventBasicPropertiesMixin
4647
from .mixins.license import LicenseBasicPropertiesMixin
4748
from .mixins.membership import MembershipBasicPropertiesMixin
@@ -230,6 +231,10 @@ class Webhook(ImmutableData, WebhookBasicPropertiesMixin):
230231
"""Webex Teams Webhook data model."""
231232

232233

234+
class AttachmentAction(ImmutableData, AttachmentActionBasicPropertiesMixin):
235+
"""Webex Attachment Actions data model"""
236+
237+
233238
class WebhookEvent(ImmutableData, WebhookEventBasicPropertiesMixin):
234239
"""Webex Teams Webhook-Events data model."""
235240

@@ -246,6 +251,7 @@ class GuestIssuerToken(ImmutableData, GuestIssuerTokenBasicPropertiesMixin):
246251
immutable_data_models = defaultdict(
247252
lambda: ImmutableData,
248253
access_token=AccessToken,
254+
attachment_action=AttachmentAction,
249255
event=Event,
250256
license=License,
251257
membership=Membership,

0 commit comments

Comments
 (0)