-
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.
* added notes endpoint * added shares endpoint --------- Co-authored-by: Moser Marco Julian <marco.moser@smaxtec.com>
- Loading branch information
1 parent
3883487
commit 21a3ff9
Showing
5 changed files
with
340 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
class Notes: | ||
""" | ||
Class for interacting with the notes endpoint of the public V2 API | ||
https://api.smaxtec.com/api/v2/ | ||
""" | ||
|
||
def __init__(self, api=None): | ||
self.api = api | ||
self.path_suffix = "/notes" | ||
|
||
def post(self, source, reference_type, reference_id, category, note_event, **kwargs): | ||
"""Create a new note. | ||
Args: | ||
source (str): Source of the note | ||
reference_type (str): Type of the reference | ||
reference_id (str): ID of the reference | ||
category (str): Category of the note | ||
note_event (str): Event of the note | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/api/v2/ | ||
Returns: | ||
dict: Response of API call. Note on success, | ||
error message else. | ||
""" | ||
params = { | ||
"source": source, | ||
"reference_type": reference_type, | ||
"reference_id": reference_id, | ||
"category": category, | ||
"note_event": note_event, | ||
} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
return self.api.post(self.path_suffix, json=params) | ||
|
||
def get(self, note_id, **kwargs): | ||
"""Get one note. | ||
Args: | ||
note_id (str): ID of the desired note | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/api/v2/ | ||
Returns: | ||
dict: Response of API call. Note on success, | ||
error message else. | ||
""" | ||
params = {} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
url_suffix = self.path_suffix + f"/{note_id}" | ||
return self.api.get(url_suffix, json=kwargs) | ||
|
||
def put(self, note_id, source, reference_type, reference_id, category, note_event, **kwargs): | ||
"""Update an existing note. | ||
Args: | ||
note_id (str): ID of the note to be updated | ||
source (str): Source of the note | ||
reference_type (str): Type of the reference | ||
reference_id (str): ID of the reference | ||
category (str): Category of the note | ||
note_event (str): Event of the note | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/api/v2/ | ||
Returns: | ||
dict: Response of API call. Note on success, | ||
error message else. | ||
""" | ||
params = { | ||
"source": source, | ||
"reference_type": reference_type, | ||
"reference_id": reference_id, | ||
"category": category, | ||
"note_event": note_event, | ||
} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
url_suffix = self.path_suffix + f"/{note_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,103 @@ | ||
class Shares: | ||
""" | ||
Class for interacting with the notes endpoint of the public V2 API | ||
https://api.smaxtec.com/api/v2/ | ||
""" | ||
|
||
def __init__(self, api=None): | ||
self.api = api | ||
self.path_suffix = "/shares" | ||
|
||
def post(self, email, organisation_id, **kwargs): | ||
"""Create a new share. | ||
Args: | ||
email (str): Email of the user to share | ||
organisation_id (str): ID of the organisation to share | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/api/v2/ | ||
Returns: | ||
dict: Response of API call. Share on success, | ||
error message else. | ||
""" | ||
params = { | ||
"email": email, | ||
"organisation_id": organisation_id, | ||
} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
return self.api.post(self.path_suffix, json=params) | ||
|
||
def get(self, share_id, **kwargs): | ||
"""Get one share. | ||
Args: | ||
share_id (str): ID of the desired share | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/api/v2/ | ||
Returns: | ||
dict: Response of API call. Share on success, | ||
error message else. | ||
""" | ||
params = {} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
url_suffix = self.path_suffix + f"/{share_id}" | ||
return self.api.get(url_suffix, json=params) | ||
|
||
def put(self, share_id, role, **kwargs): | ||
"""Update one share. | ||
Args: | ||
share_id (str): ID of the desired share | ||
role (str): Role of the share | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/api/v2/ | ||
Returns: | ||
dict: Response of API call. Share on success, | ||
error message else. | ||
""" | ||
params = { | ||
"role": role, | ||
} | ||
|
||
for k, v in kwargs.items(): | ||
params[k] = v | ||
|
||
url_suffix = self.path_suffix + f"/{share_id}" | ||
return self.api.put(url_suffix, json=params) | ||
|
||
def delete(self, share_id, **kwargs): | ||
"""Delete one share. | ||
Args: | ||
share_id (str): ID of the desired share | ||
**kwargs: Optional parameters of the API call. | ||
Find supported parameters under | ||
https://api.smaxtec.com/api/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"/{share_id}" | ||
return self.api.delete(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,69 @@ | ||
import mock | ||
|
||
from sxapi.publicV2 import PublicAPIV2 | ||
|
||
@mock.patch("sxapi.publicV2.PublicAPIV2.post") | ||
def test_post(post_mock): | ||
test_api = PublicAPIV2() | ||
test_api.notes.post( | ||
"test_source", | ||
"test_reference_type", | ||
"test_reference_id", | ||
"test_category", | ||
"test_note_event", | ||
kwarg1="kwarg1" | ||
) | ||
|
||
call_args = post_mock.call_args_list[0] | ||
|
||
assert post_mock.call_count == 1 | ||
assert call_args.args[0] == "/notes" | ||
assert call_args.kwargs["json"] == { | ||
"source": "test_source", | ||
"reference_type": "test_reference_type", | ||
"reference_id": "test_reference_id", | ||
"category": "test_category", | ||
"note_event": "test_note_event", | ||
"kwarg1": "kwarg1", | ||
} | ||
|
||
|
||
@mock.patch("sxapi.publicV2.PublicAPIV2.get") | ||
def test_get(get_mock): | ||
test_api = PublicAPIV2() | ||
test_api.notes.get("test_note_id", kwarg1="kwarg1") | ||
|
||
call_args = get_mock.call_args_list[0] | ||
|
||
assert get_mock.call_count == 1 | ||
assert call_args.args[0] == "/notes/test_note_id" | ||
assert call_args.kwargs["json"] == { | ||
"kwarg1": "kwarg1", | ||
} | ||
|
||
|
||
@mock.patch("sxapi.publicV2.PublicAPIV2.put") | ||
def test_put(put_mock): | ||
test_api = PublicAPIV2() | ||
test_api.notes.put( | ||
"test_note_id", | ||
"test_source", | ||
"test_reference_type", | ||
"test_reference_id", | ||
"test_category", | ||
"test_note_event", | ||
kwarg1="kwarg1" | ||
) | ||
|
||
call_args = put_mock.call_args_list[0] | ||
|
||
assert put_mock.call_count == 1 | ||
assert call_args.args[0] == "/notes/test_note_id" | ||
assert call_args.kwargs["json"] == { | ||
"source": "test_source", | ||
"reference_type": "test_reference_type", | ||
"reference_id": "test_reference_id", | ||
"category": "test_category", | ||
"note_event": "test_note_event", | ||
"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,69 @@ | ||
import mock | ||
|
||
from sxapi.publicV2 import PublicAPIV2 | ||
|
||
|
||
@mock.patch("sxapi.publicV2.PublicAPIV2.post") | ||
def test_post(post_mock): | ||
test_api = PublicAPIV2() | ||
test_api.shares.post( | ||
"test_email", | ||
"test_organisation_id", | ||
kwarg1="1", | ||
) | ||
|
||
call_args = post_mock.call_args_list[0] | ||
|
||
assert post_mock.call_count == 1 | ||
assert call_args.args[0] == "/shares" | ||
assert call_args.kwargs["json"] == { | ||
"email": "test_email", | ||
"organisation_id": "test_organisation_id", | ||
"kwarg1": "1", | ||
} | ||
|
||
|
||
@mock.patch("sxapi.publicV2.PublicAPIV2.get") | ||
def test_get(get_mock): | ||
test_api = PublicAPIV2() | ||
test_api.shares.get("test_share_id", kwarg1="1", kwarg2="2") | ||
|
||
call_args = get_mock.call_args_list[0] | ||
|
||
assert get_mock.call_count == 1 | ||
assert call_args.args[0] == "/shares/test_share_id" | ||
assert call_args.kwargs["json"] == { | ||
"kwarg1": "1", | ||
"kwarg2": "2", | ||
} | ||
|
||
|
||
@mock.patch("sxapi.publicV2.PublicAPIV2.put") | ||
def test_put(put_mock): | ||
test_api = PublicAPIV2() | ||
test_api.shares.put("test_share_id", "test_role", kwarg1="1", kwarg2="2") | ||
|
||
call_args = put_mock.call_args_list[0] | ||
|
||
assert put_mock.call_count == 1 | ||
assert call_args.args[0] == "/shares/test_share_id" | ||
assert call_args.kwargs["json"] == { | ||
"role": "test_role", | ||
"kwarg1": "1", | ||
"kwarg2": "2", | ||
} | ||
|
||
|
||
@mock.patch("sxapi.publicV2.PublicAPIV2.delete") | ||
def test_delete(delete_mock): | ||
test_api = PublicAPIV2() | ||
test_api.shares.delete("test_share_id", kwarg1="1", kwarg2="2") | ||
|
||
call_args = delete_mock.call_args_list[0] | ||
|
||
assert delete_mock.call_count == 1 | ||
assert call_args.args[0] == "/shares/test_share_id" | ||
assert call_args.kwargs["json"] == { | ||
"kwarg1": "1", | ||
"kwarg2": "2", | ||
} |