requests!

This commit is contained in:
Kenneth Reitz
2011-02-14 02:54:16 -05:00
parent 8ba063d607
commit b44c2ad79f
2 changed files with 6 additions and 23 deletions
+5 -22
View File
@@ -10,45 +10,26 @@
"""
import sys
import httplib
try:
import simplejson as json
except ImportError:
import json
from urlparse import urlparse, urlunparse
try:
from urlparse import parse_qs
except ImportError:
from cgi import parse_qs
from urllib import urlencode
import requests
CONVORE_URL = "https://convore.com"
URL_PREFIX = "https://convore.com/api/"
class ConvoreError(Exception):
"""An error occured while making a request to the Convore API."""
class ConvoreRequest(object):
convore_url = CONVORE_URL
url_format = "%(convore_url)s/api/%(api_format)s"
api_format = "json"
ConvoreError = ConvoreError
def __init__(self, username, password, url_prefix=None):
def __init__(self, username, password):
self.username = username
self.password = password
if not self.url_prefix:
self.url_prefix = self.url_format % {
'convore_url': self.convore_url,
'api_format': self.api_format
}
def get(self, *path_components):
path_components = filter(None, path_components)
@@ -61,3 +42,5 @@ class ConvoreRequest(object):
url = "/".join([self.url_prefix, path])
return self.raw_request(url, extra_post_data, method=method)
class ConvoreError(Exception):
"""An error occured while making a request to the Convore API."""
+1 -1
View File
@@ -15,7 +15,7 @@ if sys.argv[-1] == "publish":
publish()
sys.exit()
required = []
required = ['requests']
# if python > 2.6, require simplejson