-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Add claims API service (#342)
- Add claims API service - Update fixture data
- Loading branch information
Showing
16 changed files
with
2,620 additions
and
11 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
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,5 @@ | ||
from easypost.easypost_object import EasyPostObject | ||
|
||
|
||
class Claim(EasyPostObject): | ||
pass |
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,70 @@ | ||
from typing import ( | ||
Any, | ||
Dict, | ||
Optional, | ||
) | ||
|
||
from easypost.easypost_object import convert_to_easypost_object | ||
from easypost.models import Claim | ||
from easypost.requestor import ( | ||
RequestMethod, | ||
Requestor, | ||
) | ||
from easypost.services.base_service import BaseService | ||
|
||
|
||
class ClaimService(BaseService): | ||
def __init__(self, client): | ||
self._client = client | ||
self._model_class = Claim.__name__ | ||
|
||
def create(self, **params) -> Claim: | ||
"""Create a Claim.""" | ||
url = "/claims" | ||
|
||
response = Requestor(self._client).request(method=RequestMethod.POST, url=url, params=params, beta=False) | ||
|
||
return convert_to_easypost_object(response=response) | ||
|
||
def all(self, **params) -> Dict[str, Any]: | ||
"""Retrieve a list of Claims.""" | ||
filters = { | ||
"key": "claims", | ||
} | ||
|
||
return self._all_resources(class_name=self._model_class, filters=filters, beta=False, **params) | ||
|
||
def retrieve(self, id: str) -> Claim: | ||
"""Retrieve a Claim.""" | ||
return self._retrieve_resource(class_name=self._model_class, id=id, beta=False) | ||
|
||
def get_next_page( | ||
self, | ||
claims: Dict[str, Any], | ||
page_size: int, | ||
optional_params: Optional[Dict[str, Any]] = None, | ||
) -> Dict[str, Any]: | ||
"""Retrieve the next page of the list Claim response.""" | ||
self._check_has_next_page(collection=claims) | ||
|
||
params = { | ||
"before_id": claims["claims"][-1].id, | ||
"page_size": page_size, | ||
} | ||
|
||
if optional_params: | ||
params.update(optional_params) | ||
|
||
return self.all(**params) | ||
|
||
def cancel(self, id: str) -> Claim: | ||
"""Cancel a Claim.""" | ||
url = f"/claims/{id}/cancel" | ||
|
||
response = Requestor(self._client).request( | ||
method=RequestMethod.POST, | ||
url=url, | ||
beta=False, | ||
) | ||
|
||
return convert_to_easypost_object(response=response) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.