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

add pkg details to user agent #82

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions closeio_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import time
import requests
import time

from closeio_api._version import __version__ # noqa
from closeio_api.utils import local_tz_offset


Expand All @@ -14,6 +15,7 @@ def __init__(self, response):
super(APIError, self).__init__(response.text)
self.response = response


class ValidationError(APIError):
def __init__(self, response):
super(ValidationError, self).__init__(response)
Expand All @@ -23,6 +25,7 @@ def __init__(self, response):
self.errors = data.get('errors', [])
self.field_errors = data.get('field-errors', {})


class API(object):
def __init__(self, base_url, api_key=None, tz_offset=None,
async=False, max_retries=5, verify=True):
Expand All @@ -42,7 +45,15 @@ def __init__(self, base_url, api_key=None, tz_offset=None,
self.session = self.requests.Session()
if api_key:
self.session.auth = (api_key, '')
self.session.headers.update({'Content-Type': 'application/json', 'X-TZ-Offset': self.tz_offset})

self.session.headers.update({
'Content-Type': 'application/json',
'User-Agent': 'python closeio v{} {}'.format(
__version__,
requests.utils.default_user_agent()
),
'X-TZ-Offset': self.tz_offset
})

def _print_request(self, request):
print('{}\n{}\n{}\n\n{}\n{}'.format(
Expand Down
1 change: 1 addition & 0 deletions closeio_api/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.5'
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from setuptools import setup

# Version comes directly from source w/o importing
exec(open('closeio_api/_version.py').read())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't use exec, and the current directory may not necessarily be the one that contains closeio_api. Is there any convention on how to do this best?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason we can't do something like from _version import __version__?


requires = ['requests >= 2.11.1', 'grequests >= 0.3.0']

setup(
name="closeio",
packages=['closeio_api'],
version="0.5",
version=__version__, # noqa
description="Close.io Python Library",
long_description="Closeio Python library",
author="Close.io Team",
Expand Down