Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated hoover to use python requests instead of httplib2 #7

Merged
merged 4 commits into from Feb 23, 2013
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

modifying hoover to use requests instead of httplib2

  • Loading branch information
gingerlime committed Feb 22, 2013
commit 413af76ce50c3bacbb624636ebbc8432151f2c3b
@@ -6,7 +6,7 @@
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode
from httplib2 import Http
import requests
try:
from simplejson import loads
except ImportError:
@@ -33,27 +33,17 @@ def __init__(self, subdomain, username, password, domain=None, proxy=None,
self.protocol = secure and 'https' or 'http'

def _api_help(self, endpoint, params=None, method='GET'):
h = Http()
h.add_credentials(self.username, self.password)
s = requests.Session()
s.auth = (self.username, self.password)
url = '%s://%s.%s/%s' % (self.protocol, self.subdomain, self.domain,
endpoint)
if method == 'GET':
body = ''
if params:
url += '?' + urlencode(params)
elif params:
body = ''
if params and method != 'GET':
body = urlencode(params)
else:
body = ''
headers, results = h.request(url, method, body)
status = headers['status']
if int(status) == 401:
raise AuthFail('Sorry, your authentication was not accepted.')
# TODO check status, raise appropriate errors or something
try:
return loads(results.decode('utf-8'))
except ValueError:
return results
params = None
response = s.request(method, url, data=body, verify=True)
response.raise_for_status()
return response.json()

@property
def inputs(self):
@@ -4,11 +4,11 @@
from distutils.core import setup

setup(name='Hoover',
version='0.5.3',
version='0.5.4',
description="Library for logging to Loggly from within Python webapps",
author="Mike Blume",
author_email="mike@loggly.com",
url="http://www.github.com/loggly/hoover",
packages=['hoover'],
install_requires=['httplib2'],
install_requires=['requests'],
)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.