This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 310
/
tips.json.spt
52 lines (44 loc) · 1.59 KB
/
tips.json.spt
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
import re
from aspen import json, Response
from gratipay.utils import get_participant
callback_pattern = re.compile(r'^[_A-Za-z0-9.]+$')
class BadPlatform(Exception): pass
[-----------------------]
participant = get_participant(state, restrict=True)
if user.participant != participant:
raise Response(403) # disallow admins
if request.method == 'POST':
out = []
new_tips = request.body
seen = set()
for tip in new_tips:
seen.add(tip['username'])
one = {"username": tip['username'], "platform": tip['platform']}
try:
if tip['platform'] not in ('gittip', 'gratipay'):
raise BadPlatform
amount = participant.set_tip_to( tip['username']
, parse_decimal(tip['amount'])
)['amount']
except Exception, exc:
amount = "error"
one['error'] = exc.__class__.__name__
one['amount'] = str(amount)
out.append(one)
if request.qs.get('also_prune', 'false').lower() in ('true', '1', 'yes'):
old_tips = participant.get_current_tips()
for tip in old_tips:
if tip['tippee'] not in seen:
participant.set_tip_to(tip['tippee'], '0.00')
else:
tips, total = participant.get_giving_for_profile()
out = []
for tip in tips:
if tip.amount == 0:
continue
out.append({ "username": tip.tippee
, "platform": "gratipay"
, "amount": str(tip.amount)
})
[---] application/json via json_dump
out