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 all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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,18 @@ 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)
import ipdb; ipdb.set_trace()
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, params=params, data=body, verify=True)
response.raise_for_status()
return response.json()

@property
def inputs(self):
@@ -1,5 +1,5 @@
from functools import wraps
from httplib2 import Http
import requests


def async(func):
@@ -23,14 +23,13 @@ def newfunc(*args, **kwargs):


def post_to_endpoint(endpoint, message, encoding='utf-8'):
h = Http()
# If unicode, try to encode
if isinstance(message, unicode):
try:
message = message.encode(encoding)
except UnicodeEncodeError:
pass
h.request(endpoint, 'POST', message)
requests.post(endpoint, message, verify=True)
async_post_to_endpoint = async(post_to_endpoint)


@@ -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.