Permalink
Browse files

Merge branch 'add_requests'

  • Loading branch information...
Owen Jacobson
Owen Jacobson committed Apr 5, 2012
2 parents 2942dff + ec9e66f commit a2d257c873dda8e0da97823d695b06ff937c28b0
Showing with 30 additions and 6 deletions.
  1. +10 −5 refreshbooks/transport.py
  2. +18 −0 refreshbooks/transports/use_requests.py
  3. +2 −1 setup.py
View
@@ -12,11 +12,16 @@ def OAuthAuthorization(consumer, token, sig_method=None):
raise NotImplementedError('oauth support requires the "oauth" module.')
try:
- from refreshbooks.transports import use_httplib2 as transport
+ from refreshbooks.transports import use_requests as transport
except ImportError:
- import warnings
- warnings.warn("Unable to load httplib2 transport, falling back to urllib2. SSL cert verification disabled.")
- from refreshbooks.transports import use_urllib2 as transport
+ try:
+ from refreshbooks.transports import use_httplib2 as transport
+ except ImportError:
+ import warnings
+ warnings.warn(
+ "Unable to load requests or httplib2 transports, falling back to urllib2. SSL cert verification disabled."
+ )
+ from refreshbooks.transports import use_urllib2 as transport
class TokenAuthorization(object):
"""Generates HTTP BASIC authentication headers obeying FreshBooks'
@@ -60,4 +65,4 @@ def __call__(self):
return headers
HttpTransport = transport.Transport
-TransportException = exceptions.TransportException
+TransportException = exceptions.TransportException
@@ -0,0 +1,18 @@
+import requests
+
+class Transport(object):
+ def __init__(self, url, headers_factory):
+ self.url = url
+ self.headers_factory = headers_factory
+
+ def __call__(self, entity):
+
+ resp = requests.post(
+ self.url,
+ headers=self.headers_factory(),
+ data=entity
+ )
+ if resp.status_code >= 400:
+ raise TransportException(resp.status, content)
+
+ return resp.content
View
@@ -40,7 +40,8 @@
],
extras_require={
'oauth': ['oauth'],
- 'httplib2': ['httplib2 >= 0.7.2']
+ 'httplib2': ['httplib2 >= 0.7.2'],
+ 'requests': ['requests >= 0.11.1']
},
test_suite = 'nose.collector'

0 comments on commit a2d257c

Please sign in to comment.