Skip to content

Commit

Permalink
Added User-Agent header with detailed version info
Browse files Browse the repository at this point in the history
Also version bump. This will be a new release.
  • Loading branch information
Liz4v committed Sep 30, 2015
1 parent cb4bc01 commit c776bac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyoneall/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from .connection import OneAll
from .connection import OneAll, __version__
8 changes: 7 additions & 1 deletion pyoneall/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

from base64 import standard_b64encode
from json import dumps, loads
from sys import version

from .base import OADict
from .classes import Users, Connections, Connection, User, BadOneAllCredentials

__version__ = '0.2.2'


class OneAll(object):
"""
Expand All @@ -28,7 +31,7 @@ class OneAll(object):

bindings = {}

def __init__(self, site_name, public_key, private_key, base_url=None):
def __init__(self, site_name, public_key, private_key, base_url=None, ua_prefix=None):
"""
:param str site_name: The name of the OneAll site
:param str public_key: API public key for the site
Expand All @@ -38,6 +41,8 @@ def __init__(self, site_name, public_key, private_key, base_url=None):
self.base_url = base_url if base_url else OneAll.DEFAULT_API_DOMAIN.format(site_name=site_name)
self.public_key = public_key
self.private_key = private_key
ua = str(ua_prefix or '').split() + ['pyoneall-' + __version__] + ('python-' + version).split()
self.user_agent_string = ' '.join(w for w in ua if w)

def _exec(self, action, params=None, post_params=None):
"""
Expand All @@ -56,6 +61,7 @@ def _exec(self, action, params=None, post_params=None):
token = '%s:%s' % (self.public_key, self.private_key)
auth = standard_b64encode(token.encode())
req.add_header('Authorization', 'Basic %s' % auth.decode())
req.add_header('User-Agent', self.user_agent_string)
try:
request = urlopen(req)
except HTTPError as e:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
README = open(join(dirname(__file__), 'README.rst')).read()
setup(
name='pyoneall',
version='0.2.1',
version='0.2.2',
packages=['pyoneall'],
install_requires=['future'],
license='MIT License, see LICENSE file',
Expand Down

0 comments on commit c776bac

Please sign in to comment.