Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Commit 638581f

Browse files
authored
Merge pull request #28 from shawnCaza/master
Added support for some theme and image endpoints.
2 parents ccfe1ec + 82471a6 commit 638581f

4 files changed

Lines changed: 124 additions & 0 deletions

File tree

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Python Client wrapper for [Typeform API](https://developer.typeform.com/)
1313
- [Create Client](#typeformapi_key)
1414
- [Forms](#forms)
1515
- [Responses](#responses)
16+
- [Themes](#themes)
17+
- [Images](#images)
1618
- [Tests](#tests)
1719

1820
## Installation
@@ -151,6 +153,53 @@ result: str = responses.delete('abc123' 'token1')
151153
result: str = responses.delete('abc123' ['token2', 'token3'])
152154
```
153155

156+
### Themes
157+
158+
#### `themes.get(uid: str)`
159+
160+
Retrieves a theme by the given theme_id. [See docs](https://developer.typeform.com/create/reference/retrieve-theme/).
161+
162+
```python
163+
themes = Typeform('<api_key>').themes
164+
result: dict = themes.get('abc123')
165+
```
166+
167+
#### `themes.list(page: int = None, pageSize: int = None)`
168+
169+
Retrieves a list of JSON descriptions for all themes in your Typeform account (public and private). Themes are listed in reverse-chronological order based on the date you added them to your account.
170+
171+
```python
172+
themes = Typeform('<api_key>').themes
173+
result: dict = themes.get('abc123')
174+
```
175+
176+
### Images
177+
178+
#### `images.get(uid: str)`
179+
180+
Retrieves an image by the given id. [See docs](https://developer.typeform.com/create/reference/retrieve-image).
181+
182+
```python
183+
images = Typeform('<api_key>').images
184+
result: dict = images.get('abc123')
185+
```
186+
187+
#### `images.list()`
188+
189+
Retrieves a list of JSON descriptions for all images in your Typeform account. Images are listed in reverse-chronological order based on the date you added them to your account.
190+
191+
```python
192+
images = Typeform('<api_key>').images
193+
result: dict = images.list()
194+
```
195+
196+
#### `images.upload(file_name : str, image : str = None, url : str = None)`
197+
198+
Adds an image in your Typeform account.
199+
200+
Specify the URL of your image or send your image in base64 format, which encodes the image data as ASCII text. You can use a tool like Base64 Image Encoder to get the base64 code for the image you want to add.
201+
202+
154203
## Tests
155204

156205
Check typeform/test/fixtures.py to configure test run.

typeform/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from .forms import Forms
2+
from .themes import Themes
3+
from .images import Images
24
from .responses import Responses
35
from .client import Client
46

@@ -12,12 +14,22 @@ def __init__(self, token: str, headers: dict = {}):
1214
"""Constructor for Typeform API client"""
1315
client = Client(token, headers=headers)
1416
self.__forms = Forms(client)
17+
self.__themes = Themes(client)
18+
self.__images = Images(client)
1519
self.__responses = Responses(client)
1620

1721
@property
1822
def forms(self) -> Forms:
1923
return self.__forms
2024

25+
@property
26+
def themes(self) -> Themes:
27+
return self.__themes
28+
29+
@property
30+
def images(self) -> Images:
31+
return self.__images
32+
2133
@property
2234
def responses(self) -> Responses:
2335
return self.__responses

typeform/images.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import typing
2+
from .client import Client
3+
4+
5+
class Images:
6+
"""Typeform Forms API client"""
7+
def __init__(self, client: Client):
8+
"""Constructor for Typeform Images class"""
9+
self.__client = client
10+
11+
@property
12+
def messages(self):
13+
return self.__messages
14+
15+
def get(self, uid: str) -> dict:
16+
"""Retrieves an image by the given id."""
17+
18+
return self.__client.request('get', '/images/%s' % uid)
19+
20+
def list(self) -> dict:
21+
"""
22+
Retrieves a list of JSON descriptions for all images in your Typeform account. Images are listed in reverse-chronological order based on the date you added them to your account.
23+
"""
24+
return self.__client.request('get', '/images')
25+
26+
def upload(self, file_name : str, image : str = None, url : str = None) -> dict:
27+
"""
28+
Adds an image in your Typeform account.
29+
30+
Specify the URL of your image or send your image in base64 format, which encodes the image data as ASCII text. You can use a tool like Base64 Image Encoder to get the base64 code for the image you want to add.
31+
"""
32+
return self.__client.request('post', '/images', data={
33+
'file_name': file_name,
34+
'image': image,
35+
})

typeform/themes.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import typing
2+
from .client import Client
3+
4+
5+
class Themes:
6+
"""Typeform Forms API client"""
7+
def __init__(self, client: Client):
8+
"""Constructor for Typeform Theme class"""
9+
self.__client = client
10+
11+
@property
12+
def messages(self):
13+
return self.__messages
14+
15+
def get(self, uid: str) -> dict:
16+
"""Retrieves a form by the given form_id. Includes any theme and images attached to the form as references."""
17+
return self.__client.request('get', '/themes/%s' % uid)
18+
19+
def list(self, page: int = None, pageSize: int = None) -> dict:
20+
"""
21+
Retrieves a list of JSON descriptions for all themes in your Typeform account (public and private). Themes are listed in reverse-chronological order based on the date you added them to your account.
22+
"""
23+
return self.__client.request('get', '/themes', params={
24+
'page': page,
25+
'page_size': pageSize,
26+
})
27+
28+

0 commit comments

Comments
 (0)