-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
76 lines (60 loc) · 1.35 KB
/
app.py
File metadata and controls
76 lines (60 loc) · 1.35 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
73
74
75
import dub
import os
from flask import Flask
from dub.models import operations
d = dub.Dub(
token=os.environ['DUB_API_KEY'],
)
app = Flask(__name__)
# Create a short link
@app.route('/create-link', methods=['POST'])
def hello():
res = None
try:
res = d.links.create(request={
"url": "https://google/com",
})
except Exception as e:
return str(e)
if res is not None:
return res.short_link
# Upsert a short link
@app.route('/upsert-link', methods=['POST'])
def upsert():
res = None
try:
res = d.links.upsert(request={
"url": "https://google.com",
})
except Exception as e:
return str(e)
if res is not None:
return res.short_link
# Update a short link
@app.route('/update-link', methods=['POST'])
def update():
res = None
try:
res = d.links.update(link_id="clx1gvi9o0005hf5momm6f7hj", request_body={
"url": "https://google.uk",
})
except Exception as e:
return str(e)
if res is not None:
return res.short_link
# Get analytics of a short link
@app.route('/analytics')
def analytics():
res = None
try:
res = d.analytics.retrieve(request={
"link_id": "clx1gvi9o0005hf5momm6f7hj",
"interval": "7d",
"group_by": "timeseries",
})
except Exception as e:
return str(e)
if res is not None:
return str(res)
if __name__ == "__main__":
app.run()