Skip to content

Commit

Permalink
Add custom User Agent to every request, and expose the version in a r…
Browse files Browse the repository at this point in the history
…eadable way (#104)

* Add User Agent to requests, add the ability for setup.py to take the version number from __init__.py, and update the version number to 1.2

* Update User Agent format to RFC 7231 standard
  • Loading branch information
eengoron committed Dec 13, 2019
1 parent bf6011f commit 139f1a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion closeio_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

from closeio_api.utils import local_tz_offset


DEFAULT_RATE_LIMIT_DELAY = 2 # Seconds

# To update the package version, change this variable. This variable is also
# read by setup.py when installing the package.
__version__ = '1.2'

class APIError(Exception):
"""Raised when sending a request to the API failed."""
Expand Down Expand Up @@ -47,6 +49,10 @@ def __init__(self, base_url, api_key=None, tz_offset=None, max_retries=5,
self.session.auth = (api_key, '')

self.session.headers.update({
'User-Agent': 'Close/{} python ({})'.format(
__version__,
requests.utils.default_user_agent()
),
'X-TZ-Offset': self.tz_offset
})

Expand Down
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import io
import re
from setuptools import setup

VERSION_FILE = "closeio_api/__init__.py"
with io.open(VERSION_FILE, "rt", encoding="utf8") as f:
version = re.search(r'__version__ = ([\'"])(.*?)\1', f.read()).group(2)

setup(
name="closeio",
packages=['closeio_api'],
version="1.1",
version=version,
description="Close API Python Client",
long_description="Close API Python Client",
author="Close Team",
Expand Down

0 comments on commit 139f1a7

Please sign in to comment.