Skip to content

Commit 2a4a665

Browse files
committed
feat: add user agent to header
fix: user-agent client version insert fix: fetch api version from one location to setup.py and base.py fix(client_info): import upcloud api error in setup phase fix: client_info as separate module fix: back to basics
1 parent abcc5f9 commit 2a4a665

File tree

5 files changed

+30
-8
lines changed

5 files changed

+30
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dist/
1111
docs/html/
1212
.tox
1313
.cache
14+
.vscode/
1415

1516
# pyenv
1617
.python-version

setup.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
#!/usr/bin/env python
22

33
from setuptools import setup
4+
import codecs
5+
import os.path
6+
7+
8+
def read(rel_path):
9+
here = os.path.abspath(os.path.dirname(__file__))
10+
with codecs.open(os.path.join(here, rel_path), 'r') as fp:
11+
return fp.read()
12+
13+
14+
def get_version(rel_path):
15+
for line in read(rel_path).splitlines():
16+
if line.startswith('__version__'):
17+
delim = '"' if '"' in line else "'"
18+
return line.split(delim)[1]
19+
else:
20+
raise RuntimeError("Unable to find version string.")
421

522

6-
version = '0.4.6'
723
with open('README.md') as f:
824
long_description = f.read()
925

26+
version = get_version('upcloud_api/__init__.py')
1027
setup(
1128
name='upcloud-api',
1229
version=version,

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Tox (http://tox.testrun.org/) is a tool for running tests
1+
# Tox (https://tox.readthedocs.io/) is a tool for running tests
22
# in multiple virtualenvs. This configuration file will run the
33
# test suite on all supported python versions. To use it, "pip install tox"
44
# and then run "tox" from this directory.

upcloud_api/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
from __future__ import unicode_literals
88
from __future__ import absolute_import
99

10-
__version__ = '0.3.9'
10+
11+
__version__ = '0.4.6'
1112
__author__ = 'Elias Nygren'
12-
__author_email__ = 'elias.nygren@upcloud.com'
13-
__license__ = 'MIT'
14-
__copyright__ = 'Copyright (c) 2015 Elias Nygren'
13+
__author_email__ = 'elias.nygren@upcloud.com'
14+
__maintainer__ = 'UpCloud'
15+
__maintainer_email__ = 'hello@upcloud.com'
16+
__license__ = 'MIT'
17+
__copyright__ = 'Copyright (c) 2015 UpCloud'
1518

1619
from upcloud_api.upcloud_resource import UpCloudResource
1720
from upcloud_api.errors import UpCloudClientError, UpCloudAPIError

upcloud_api/cloud_manager/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import requests
55

6-
from upcloud_api import UpCloudAPIError
6+
from upcloud_api import UpCloudAPIError, __version__
77

88

99
class BaseAPI(object):
@@ -29,7 +29,8 @@ def request(self, method, endpoint, body=None, timeout=-1, request_to_api=True):
2929

3030
url = 'https://api.upcloud.com/' + self.api_v + endpoint if request_to_api else endpoint
3131
headers = {
32-
'Authorization': self.token
32+
'Authorization': self.token,
33+
'User-Agent': 'upcloud-python-api/{}'.format(__version__)
3334
}
3435

3536
headers['Content-Type'] = 'application/json' if request_to_api else 'application/octet-stream'

0 commit comments

Comments
 (0)