diff options
Diffstat (limited to 'ricky/api.py')
| -rw-r--r-- | ricky/api.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ricky/api.py b/ricky/api.py new file mode 100644 index 0000000..93fa301 --- /dev/null +++ b/ricky/api.py @@ -0,0 +1,29 @@ +import urllib +import urllib2 +import sys +import random +import simplejson as json +import urllib2 + +class Api: + def __init__(self): + self._required_keys = [] + self.url = "" + def post_request(self, url, params): + params = urllib.urlencode(params) + headers = { + "Content-type": "application/x-www-form-urlencoded", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36", + "Accept": "text/plain" + } + try: + req = urllib2.Request(url, params, headers) + response = urllib2.urlopen(req) + return response.read() + except Exception as e: + sys.stderr.write(str(e)) + raise + def call(self, params): + if not(params.is_ready()): + raise Exception("Api Params Not Ready") + return json.loads(self.post_request(self.url, params.as_hash())) |
