-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for get of invoices profiles (#95)
- Loading branch information
1 parent
4b3d43b
commit 9d1c3cd
Showing
13 changed files
with
116 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from travelperk.core.client import Travelperk | ||
|
||
__all__ = [ | ||
'Travelperk' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .invoice_profiles import InvoiceProfiles | ||
|
||
__all__ = [ | ||
'InvoiceProfiles' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from typing import List, Dict | ||
import requests | ||
import json | ||
|
||
from travelperk.exceptions import * | ||
|
||
class ApiBase: | ||
"""The base class for all API classes.""" | ||
|
||
def __init__(self): | ||
self.__access_token = None | ||
self.__server_url = None | ||
|
||
def change_access_token(self, access_token): | ||
"""Change the old access token with the new one. | ||
Parameters: | ||
access_token (str): The new access token. | ||
""" | ||
self.__access_token = access_token | ||
|
||
def set_server_url(self, server_url): | ||
"""Set the server URL dynamically upon creating a connection | ||
Parameters: | ||
server_url(str): The current server URL | ||
""" | ||
self.__server_url = server_url | ||
|
||
def _get_request(self, object_type: str, api_url: str) -> List[Dict] or Dict: | ||
"""Create a HTTP GET request. | ||
Parameters: | ||
api_url (str): Url for the wanted API. | ||
Returns: | ||
A response from the request (dict). | ||
""" | ||
|
||
api_headers = { | ||
'Authorization': 'Bearer {0}'.format(self.__access_token), | ||
'Accept': 'application/json', | ||
'Api-Version': '1' | ||
} | ||
|
||
response = requests.get( | ||
'{0}{1}'.format(self.__server_url, api_url), | ||
headers=api_headers | ||
) | ||
if response.status_code == 200: | ||
result = json.loads(response.text) | ||
return result[object_type] | ||
|
||
elif response.status_code == 400: | ||
raise BadRequestError('Something wrong with the request body', response.text) | ||
|
||
elif response.status_code == 401: | ||
raise UnauthorizedClientError('Wrong client secret or/and refresh token', response.text) | ||
|
||
elif response.status_code == 404: | ||
raise NotFoundError('Client ID doesn\'t exist', response.text) | ||
|
||
elif response.status_code == 500: | ||
raise InternalServerError('Internal server error', response.text) | ||
|
||
else: | ||
raise TravelperkError('Error: {0}'.format(response.status_code), response.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" | ||
Travelperk Invoices | ||
""" | ||
from .api_base import ApiBase | ||
|
||
|
||
class InvoiceProfiles(ApiBase): | ||
"""Class for Invoice Profiles APIs.""" | ||
|
||
GET_INVOICE_PROFILES = '/profiles' | ||
|
||
def get_all(self): | ||
"""Get a list of the existing Invoice Profiles in the Organization. | ||
Returns: | ||
List with dicts in Invoice Profile schema. | ||
""" | ||
return self._get_request('profiles', InvoiceProfiles.GET_INVOICE_PROFILES) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.