Skip to content

Commit e104766

Browse files
authored
Merge pull request #21 from Prevedere/dev
0.4.0 Release
2 parents 3b341a9 + 8589f30 commit e104766

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## 0.4.0 - 2019-09-06
5+
### Added
6+
- Can now use a difference base url instead of 'api' using a new argument 'base'
7+
### Changed
8+
- Authentication of api key context is improved and should be faster
9+
410
## 0.3.2 - 2019-07-11
511
### Added
612
- Authenticates by calling to `/company`

prevedere/prevedere.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class Api:
99

10-
def __init__(self, api_key: str = None):
10+
def __init__(self, api_key: str = None, base: str = None):
1111
"""
1212
API can be initialized directly by passing string, if not it looks for prevedere_api.ini in current working directory.
1313
Copy the prevedere_api.ini.example file and remove `.example` from the end.
@@ -38,12 +38,16 @@ def __init__(self, api_key: str = None):
3838
raise FileNotFoundError('prevedere_api.ini config file not found in directory: ' + str(filepath.parent))
3939
logging.exception()
4040

41+
if base:
42+
self.base = base
43+
logging.debug(f'Using "{self.base}" instead of "api."')
44+
else:
45+
self.base = 'api'
46+
4147
try:
4248
self.api_key = str(UUID(api_key))
43-
company = self.fetch('/company')
44-
if len(company) == 1:
45-
self.company = company[0]
46-
logging.info('Successfully validated as ' + self.company['Name'])
49+
self.context = self.fetch('/context')
50+
logging.debug(f"Hello {self.context['User']['FirstName']}, you're now connected to the {self.context['Company']['Prefix']} instance.")
4751
except (TypeError, ValueError, requests.exceptions.HTTPError) as e:
4852
raise ApiKeyError(f"'{api_key}' is not a valid API Key. " +\
4953
"Please check the config file or string that was passed to the constructor and try again.") from e
@@ -53,7 +57,7 @@ def fetch(self, path: str, payload: dict = None) -> dict:
5357
if payload is None:
5458
payload = {}
5559
payload['ApiKey'] = self.api_key
56-
url = f'https://api.prevedere.com{path}'
60+
url = f'https://{self.base}.prevedere.com{path}'
5761
try:
5862
r = requests.get(url, params=payload)
5963
r.raise_for_status()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='prevedere-api',
8-
version='0.3.2',
8+
version='0.4.0',
99
author="Prevedere, Inc.",
1010
author_email="[email protected]",
1111
description="API interface for Prevedere Inc. in Python 3.6+",

0 commit comments

Comments
 (0)