From 3790bdd4fd6230f30221c42d3e168afa6f3877fd Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 24 Sep 2011 14:41:25 -0400 Subject: [PATCH] http client --- localtunnel/http.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 localtunnel/http.py diff --git a/localtunnel/http.py b/localtunnel/http.py new file mode 100644 index 0000000..1f807b9 --- /dev/null +++ b/localtunnel/http.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +""" +localtunnel.http +~~~~~~~~~~~~~~~~ + +This module provides +""" + +import requests + +from .packages.omnijson import loads as from_json +from .packages.omnijson import JSONError + + +LOCALTUNNEL_API = 'http://open.localtunnel.com/' + + +def register_key(pub_key): + """Publishes a public key to the localtunnel service.""" + + r = requests.post(LOCALTUNNEL_API, data={'key': pub_key}) + r.raise_for_status() + + +def register_tunnel(): + """Requests a new connection to the localtunnel service.""" + r = requests.get(LOCALTUNNEL_API) + + try: + return from_json(r.content) + except JSONError, why: + raise why +