blob: 2e60813e28c0ab95dfac8838b42b7ccb95736608 (
plain) (
blame)
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
|
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
from google.appengine.api.urlfetch import fetch
from django.utils.simplejson import loads, dumps
import re
class AnyClipBackoffice():
def __init__(self, key):
self.key = key
self.errorMatch = re.compile("<code>(.*)</code><description>(.*)</description>")
def request(self, *arguments, **keywords):
keywords["token"] = self.key
url = "http://api.anyclip.com/ac_backoffice/v1/json/"
for call in arguments:
url += call + "/"
response = fetch(url, payload=dumps(keywords), method="POST", headers={"Content-Type": "application/json; charset=utf-8"})
if response.status_code == 200:
error = self.errorMatch.search(response.content)
if error != None:
return None
else:
return loads(response.content)
else:
return None
|