This repository was archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathforms.py
More file actions
72 lines (60 loc) · 2.93 KB
/
Copy pathforms.py
File metadata and controls
72 lines (60 loc) · 2.93 KB
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
import typing
from .client import Client
class Forms:
"""Typeform Forms API client"""
def __init__(self, client: Client):
"""Constructor for Typeform Forms class"""
self.__client = client
self.__messages = FormMessages(client)
@property
def messages(self):
return self.__messages
def create(self, data: dict = {}) -> dict:
"""Creates a form"""
return self.__client.request('post', '/forms', data=data)
def delete(self, uid: str) -> str:
"""
Deletes the form with the given form_id and all of the form's responses.
Return a `str` based on success of deletion, `OK` on success, otherwise an error message.
"""
return self.__client.request('delete', '/forms/%s' % uid)
def get(self, uid: str) -> dict:
"""Retrieves a form by the given form_id. Includes any theme and images attached to the form as references."""
return self.__client.request('get', '/forms/%s' % uid)
def list(self, page: int = None, pageSize: int = None, search: str = None, workspaceId: str = None) -> dict:
"""
Retrieves a list of JSON descriptions for all forms in your Typeform account (public and private).
Forms are listed in reverse-chronological order based on the last date they were modified.
"""
return self.__client.request('get', '/forms', params={
'page': page,
'page_size': pageSize,
'search': search,
'workspace_id': workspaceId
})
def update(self, uid: str, data: dict = {}, patch: bool = False) -> typing.Union[str, dict]:
"""
Updates an existing form.
Defaults to `put`.
`put` will return the modified form as a `dict` object.
`patch` will return a `str` based on success of change, `OK` on success, otherwise an error message.
"""
methodType = 'put' if patch is False else 'patch'
return self.__client.request(methodType, '/forms/%s' % uid, data=data)
class FormMessages:
def __init__(self, client: Client):
"""Constructor for TypeForm FormMessages class"""
self.__client = client
def get(self, uid: str) -> dict:
"""
Retrieves the customizable messages for a form (specified by form_id) using the form's specified language.
You can format messages with bold (*bold*) and italic (_italic_) text. HTML tags are forbidden.
"""
return self.__client.request('get', '/forms/%s/messages' % uid)
def update(self, uid: str, data={}) -> str:
"""
Specifies new values for the customizable messages in a form (specified by form_id).
You can format messages with bold (*bold*) and italic (_italic_) text. HTML tags are forbidden.
Return a `str` based on success of change, `OK` on success, otherwise an error message.
"""
return self.__client.request('put', '/forms/%s/messages' % uid, data=data)