Skip to content

Commit 7130ead

Browse files
Merge pull request #121 from CartoDB/kuviz
Kuvizs creation
2 parents c394a08 + 6ea50a8 commit 7130ead

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

carto/kuvizs.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
"""
2+
Module for working with custom map visualizations (aka Kuvizs)
3+
4+
.. module:: carto.Kuvizs
5+
:platform: Unix, Windows
6+
:synopsis: Module for working with custom map visualizations (aka Kuvizs)
7+
8+
.. moduleauthor:: Simon Martin <[email protected]>
9+
10+
"""
11+
12+
import base64
13+
14+
from pyrestcli.fields import CharField, DateTimeField
15+
16+
from .resources import Manager, WarnResource
17+
from .paginators import CartoPaginator
18+
19+
20+
API_VERSION = "v4"
21+
API_ENDPOINT = "api/{api_version}/kuviz/"
22+
23+
PRIVACY_PASSWORD = 'password'
24+
25+
26+
class Kuviz(WarnResource):
27+
"""
28+
Represents a custom map visualization in CARTO.
29+
30+
.. warning:: Non-public API. It may change with no previous notice
31+
"""
32+
created_at = DateTimeField()
33+
data = CharField()
34+
id = CharField()
35+
name = CharField()
36+
password = CharField()
37+
privacy = CharField()
38+
updated_at = DateTimeField()
39+
url = CharField()
40+
41+
class Meta:
42+
collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION)
43+
name_field = "id"
44+
45+
46+
class KuvizManager(Manager):
47+
"""
48+
Manager for the Kuviz class.
49+
50+
.. warning:: Non-public API. It may change with no previous notice
51+
"""
52+
resource_class = Kuviz
53+
paginator_class = CartoPaginator
54+
55+
def get(self, id):
56+
pass
57+
58+
def all(self):
59+
pass
60+
61+
def create(self, html, name, password=None):
62+
"""
63+
Creates a Kuviz.
64+
65+
:param html: The visualization HTML
66+
:param name: The visualization name
67+
:type html: str
68+
:type name: str
69+
70+
:return: A Kuviz instance with the `url` and `visualization` properties
71+
of the new Kuviz
72+
"""
73+
data = base64.b64encode(html.encode()).decode('ascii')
74+
if password:
75+
return super(KuvizManager, self).create(data=data, name=name,
76+
privacy=PRIVACY_PASSWORD, password=password)
77+
else:
78+
return super(KuvizManager, self).create(data=data, name=name)
79+
80+
def update(self, html, name, password=None):
81+
pass

doc/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Please, refer to the :ref:`apidoc` or the source code for further details about
3636
sql_api
3737
import_api
3838
maps_api
39+
kuviz
3940
non_public_apis
4041
examples
4142
modules

doc/source/kuviz.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Custom visualizations (aka Kuviz)
2+
=================================
3+
4+
Create
5+
^^^^^^
6+
::
7+
8+
from carto.kuvizs import KuvizManager
9+
10+
km = KuvizManager(auth_client)
11+
html = "<html><body><h1>Hi Kuviz</h1></body></html>"
12+
kuviz = km.create(html=html, name="public-kuviz")
13+
14+
print(kuviz.id)
15+
print(kuviz.url)
16+
17+
18+
Create with password
19+
^^^^^^^^^^^^^^^^^^^^
20+
::
21+
22+
from carto.kuvizs import KuvizManager
23+
24+
km = KuvizManager(auth_client)
25+
html = "<html><body><h1>Hi Kuviz</h1></body></html>"
26+
kuviz = km.create(html=html, name="password-protected-kuviz", password="your-password")
27+
28+
print(kuviz.id)
29+
print(kuviz.url)
30+
31+
32+
List all Kuviz
33+
^^^^^^^^^^^^^^
34+
35+
WIP
36+
37+
38+
Update
39+
^^^^^^
40+
41+
WIP
42+
43+
44+
Delete
45+
^^^^^^
46+
47+
WIP

0 commit comments

Comments
 (0)