-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/integration api/users translations accounts (#45)
* moved IntegrationAPIV2 client to separate folder * added accounts endpoint * added users endpoint * added translations endpoint
- Loading branch information
1 parent
920c9a3
commit d8d6b49
Showing
11 changed files
with
360 additions
and
19 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
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 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,28 @@ | ||
from sxapi.base import ( | ||
ApiTypes, | ||
BaseAPI, | ||
) | ||
from sxapi.integrationV2.accounts import Accounts | ||
from sxapi.integrationV2.tranlations import Translations | ||
from sxapi.integrationV2.users import Users | ||
|
||
INTEGRATION_API_V2_BASE_URL = "https://api.smaxtec.com/integration/v2" | ||
|
||
|
||
class IntegrationAPIV2(BaseAPI): | ||
def __init__(self, base_url=None, email=None, password=None, api_token=None): | ||
"""Initialize a new integration api client instance.""" | ||
base_url = base_url or INTEGRATION_API_V2_BASE_URL | ||
api_type = ApiTypes.INTEGRATION | ||
|
||
self.users = Users(api=self) | ||
self.translations = Translations(api=self) | ||
self.accounts = Accounts(api=self) | ||
|
||
super().__init__( | ||
base_url, | ||
email=email, | ||
password=password, | ||
api_token=api_token, | ||
api_type=api_type, | ||
) |
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,95 @@ | ||
class Accounts: | ||
""" | ||
This Class represents the /accounts endpoint fo the IntegrationAPIV2 | ||
https://api.smaxtec.com/integration/v2/ | ||
""" | ||
|
||
def __init__(self, api=None): | ||
self.api = api | ||
self.path_suffix = "/accounts" | ||
|
||
def get_usages(self, **kwargs): | ||
"""Get usages of provided account numbers. | ||
Args: | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/integration/v2/ | ||
Returns: | ||
dict: Response of API call. List of usages on success, | ||
error message else. | ||
""" | ||
params = {} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
url_suffix = self.path_suffix + "/usages" | ||
return self.api.get(url_suffix, json=params) | ||
|
||
def put( | ||
self, | ||
account_nr, | ||
account_name, | ||
partner_id, | ||
address_name, | ||
street, | ||
county_code, | ||
**kwargs, | ||
): | ||
"""Update an account. | ||
Args: | ||
account_nr (str): Account number of the account | ||
account_name (str): Name of the account | ||
partner_id (str): Partner ID of the account | ||
address_name (str): Name of the address of the account | ||
street (str): Street of the address of the account | ||
county_code (str): Country code of the address of the account | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/integration/v2/ | ||
Returns: | ||
dict: Response of API call. Updated account on success, | ||
error message else. | ||
""" | ||
params = { | ||
"account_name": account_name, | ||
"partner_id": partner_id, | ||
"address_name": address_name, | ||
"street": street, | ||
"county_code": county_code, | ||
} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
url_suffix = self.path_suffix + f"/{account_nr}" | ||
return self.api.put(url_suffix, json=params) | ||
|
||
def put_organisation(self, account_nr, organisation_id, **kwargs): | ||
"""Add an account to an organisation. | ||
Args: | ||
account_nr (str): Account number of the account | ||
organisation_id (str): Organisation ID of the organisation | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/integration/v2/ | ||
Returns: | ||
dict: Response of API call. Result on success, | ||
error message else. | ||
""" | ||
params = {} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
url_suffix = self.path_suffix + f"/{account_nr}/organisation/{organisation_id}" | ||
return self.api.put(url_suffix, json=params) |
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,54 @@ | ||
class Translations: | ||
""" | ||
This Class represents the /translations endpoint fo the IntegrationAPIV2 | ||
https://api.smaxtec.com/integration/v2/ | ||
""" | ||
|
||
def __init__(self, api=None): | ||
self.api = api | ||
self.path_suffix = "/translations" | ||
|
||
def get_events(self, language, **kwargs): | ||
"""Get translations for events. | ||
Args: | ||
language (str): Language of the events to be returned | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/integration/v2/ | ||
Returns: | ||
dict: Response of API call. List of events on success, | ||
error message else. | ||
""" | ||
params = {} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
url_suffix = self.path_suffix + f"/{language}/events" | ||
return self.api.get(url_suffix, json=params) | ||
|
||
def get_event_types(self, language, event_type, **kwargs): | ||
"""Get translations for event types. | ||
Args: | ||
language (str): Language of the event types to be returned | ||
event_type (str): Type of the event types to be returned | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/integration/v2/ | ||
Returns: | ||
dict: Response of API call. List of event types on success, | ||
error message else. | ||
""" | ||
params = {} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
url_suffix = self.path_suffix + f"/{language}/events/{event_type}" | ||
return self.api.get(url_suffix, json=params) |
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,51 @@ | ||
class Users: | ||
""" | ||
This Class represents the /users endpoint fo the IntegrationAPIV2 | ||
https://api.smaxtec.com/integration/v2/ | ||
""" | ||
|
||
def __init__(self, api=None): | ||
self.api = api | ||
self.path_suffix = "/users" | ||
|
||
def get(self, **kwargs): | ||
"""Grant access to demo farm | ||
Args: | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/integration/v2/ | ||
Returns: | ||
dict: Response of API call. Demo farm User on success, | ||
error message else. | ||
""" | ||
params = {} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
return self.api.get(self.path_suffix, json=params) | ||
|
||
def post_session_token(self, user, password, **kwargs): | ||
"""Creates a new session token. | ||
Args: | ||
user (str): Email of the user to be logged in | ||
password (str): Password of the user to be logged in | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/integration/v2/ | ||
Returns: | ||
dict: Response of API call. Created session token on success, | ||
error message else. | ||
""" | ||
params = {"user": user, "password": password} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
return self.api.post(self.path_suffix + "/session_token", json=params) |
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 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,65 @@ | ||
import mock | ||
|
||
from sxapi.integrationV2 import IntegrationAPIV2 | ||
|
||
|
||
@mock.patch("sxapi.integrationV2.IntegrationAPIV2.get") | ||
def test_get_usages(get_mock): | ||
test_api = IntegrationAPIV2() | ||
test_api.accounts.get_usages(kwarg1="kwarg1") | ||
|
||
call_args = get_mock.call_args_list[0] | ||
|
||
assert get_mock.call_count == 1 | ||
assert call_args.args[0] == "/accounts/usages" | ||
assert call_args.kwargs["json"] == { | ||
"kwarg1": "kwarg1", | ||
} | ||
|
||
|
||
@mock.patch("sxapi.integrationV2.IntegrationAPIV2.put") | ||
def test_put(put_mock): | ||
test_api = IntegrationAPIV2() | ||
test_api.accounts.put( | ||
"test_account_nr", | ||
"test_account_name", | ||
"test_partner_id", | ||
"test_address_name", | ||
"test_street", | ||
"test_county_code", | ||
kwarg1="kwarg1", | ||
) | ||
|
||
call_args = put_mock.call_args_list[0] | ||
|
||
assert put_mock.call_count == 1 | ||
assert call_args.args[0] == "/accounts/test_account_nr" | ||
assert call_args.kwargs["json"] == { | ||
"account_name": "test_account_name", | ||
"partner_id": "test_partner_id", | ||
"address_name": "test_address_name", | ||
"street": "test_street", | ||
"county_code": "test_county_code", | ||
"kwarg1": "kwarg1", | ||
} | ||
|
||
|
||
@mock.patch("sxapi.integrationV2.IntegrationAPIV2.put") | ||
def test_put_organisation(put_mock): | ||
test_api = IntegrationAPIV2() | ||
test_api.accounts.put_organisation( | ||
"test_account_nr", | ||
"test_organisation_id", | ||
kwarg1="kwarg1", | ||
) | ||
|
||
call_args = put_mock.call_args_list[0] | ||
|
||
assert put_mock.call_count == 1 | ||
assert ( | ||
call_args.args[0] | ||
== "/accounts/test_account_nr/organisation/test_organisation_id" | ||
) | ||
assert call_args.kwargs["json"] == { | ||
"kwarg1": "kwarg1", | ||
} |
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,31 @@ | ||
import mock | ||
|
||
from sxapi.integrationV2 import IntegrationAPIV2 | ||
|
||
|
||
@mock.patch("sxapi.integrationV2.IntegrationAPIV2.get") | ||
def test_get_events(get_mock): | ||
test_api = IntegrationAPIV2() | ||
test_api.translations.get_events("en", kwarg1="kwarg1") | ||
|
||
call_args = get_mock.call_args_list[0] | ||
|
||
assert get_mock.call_count == 1 | ||
assert call_args.args[0] == "/translations/en/events" | ||
assert call_args.kwargs["json"] == { | ||
"kwarg1": "kwarg1", | ||
} | ||
|
||
|
||
@mock.patch("sxapi.integrationV2.IntegrationAPIV2.get") | ||
def test_get_event_types(get_mock): | ||
test_api = IntegrationAPIV2() | ||
test_api.translations.get_event_types("en", "test_event_type", kwarg1="kwarg1") | ||
|
||
call_args = get_mock.call_args_list[0] | ||
|
||
assert get_mock.call_count == 1 | ||
assert call_args.args[0] == "/translations/en/events/test_event_type" | ||
assert call_args.kwargs["json"] == { | ||
"kwarg1": "kwarg1", | ||
} |
Oops, something went wrong.