Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Account for new UPS endpoint in carrier account create/update functions #336

Merged
merged 7 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion easypost/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
"FedexAccount",
"FedexSmartpostAccount",
]
_UPS_OATH_CARRIER_ACCOUNT_TYPES = [
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES = [
"UpsAccount",
"UpsMailInnovationsAccount",
"UpsSurepostAccount",
]
_FILTERS_KEY = "filters"
_EXCLUDED_CLASS_NAMES = ["ups_oauth_registrations"]
5 changes: 4 additions & 1 deletion easypost/services/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)

from easypost.constant import (
_EXCLUDED_CLASS_NAMES,
_FILTERS_KEY,
NO_MORE_PAGES_ERROR,
)
Expand All @@ -30,7 +31,9 @@ def _snakecase_name(self, class_name: str) -> str:
def _class_url(self, class_name: str) -> str:
"""Generate a URL based on class name."""
transformed_class_name = self._snakecase_name(class_name)
if transformed_class_name[-1:] in ("s", "h"):
if transformed_class_name in _EXCLUDED_CLASS_NAMES:
return f"/{transformed_class_name}"
Justintime50 marked this conversation as resolved.
Show resolved Hide resolved
elif transformed_class_name[-1:] in ("s", "h"):
return f"/{transformed_class_name}es"
else:
return f"/{transformed_class_name}s"
Expand Down
8 changes: 4 additions & 4 deletions easypost/services/carrier_account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from easypost.constant import (
_CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS,
_UPS_OATH_CARRIER_ACCOUNT_TYPES,
_UPS_OAUTH_CARRIER_ACCOUNT_TYPES,
MISSING_PARAMETER_ERROR,
)
from easypost.easypost_object import convert_to_easypost_object
Expand All @@ -33,7 +33,7 @@ def create(self, **params) -> CarrierAccount:
raise MissingParameterError(MISSING_PARAMETER_ERROR.format("type"))

url = self._select_carrier_account_creation_endpoint(carrier_account_type=carrier_account_type)
if carrier_account_type in _UPS_OATH_CARRIER_ACCOUNT_TYPES:
if carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
wrapped_params = {"ups_oauth_registrations": params}
else:
wrapped_params = {self._snakecase_name(self._model_class): params}
Expand All @@ -54,7 +54,7 @@ def update(self, id: str, **params) -> CarrierAccount:
"""Update a CarrierAccount."""
carrier_account = self.retrieve(id)

if carrier_account.get("type") in _UPS_OATH_CARRIER_ACCOUNT_TYPES:
if carrier_account.get("type") in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
class_name = "UpsOauthRegistrations"
else:
class_name = self._model_class
Expand All @@ -75,7 +75,7 @@ def _select_carrier_account_creation_endpoint(self, carrier_account_type: Option
"""Determines which API endpoint to use for the creation call."""
if carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS:
return "/carrier_accounts/register"
elif carrier_account_type in _UPS_OATH_CARRIER_ACCOUNT_TYPES:
elif carrier_account_type in _UPS_OAUTH_CARRIER_ACCOUNT_TYPES:
return "/ups_oauth_registrations"

return "/carrier_accounts"
93 changes: 80 additions & 13 deletions tests/cassettes/test_carrier_account_create_ups.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading