77
88from easypost .constant import (
99 _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS ,
10+ _UPS_OATH_CARRIER_ACCOUNT_TYPES ,
1011 MISSING_PARAMETER_ERROR ,
1112)
1213from easypost .easypost_object import convert_to_easypost_object
@@ -32,7 +33,10 @@ def create(self, **params) -> CarrierAccount:
3233 raise MissingParameterError (MISSING_PARAMETER_ERROR .format ("type" ))
3334
3435 url = self ._select_carrier_account_creation_endpoint (carrier_account_type = carrier_account_type )
35- wrapped_params = {self ._snakecase_name (self ._model_class ): params }
36+ if carrier_account_type in _UPS_OATH_CARRIER_ACCOUNT_TYPES :
37+ wrapped_params = {"ups_oauth_registrations" : params }
38+ else :
39+ wrapped_params = {self ._snakecase_name (self ._model_class ): params }
3640
3741 response = Requestor (self ._client ).request (method = RequestMethod .POST , url = url , params = wrapped_params )
3842
@@ -48,7 +52,11 @@ def retrieve(self, id: str) -> CarrierAccount:
4852
4953 def update (self , id : str , ** params ) -> CarrierAccount :
5054 """Update a CarrierAccount."""
51- return self ._update_resource (self ._model_class , id , ** params )
55+ if params .get ("type" ) in _UPS_OATH_CARRIER_ACCOUNT_TYPES :
56+ class_name = "UpsOauthRegistrations"
57+ else :
58+ class_name = self ._model_class
59+ return self ._update_resource (class_name , id , ** params )
5260
5361 def delete (self , id : str ) -> None :
5462 """Delete a CarrierAccount."""
@@ -60,26 +68,11 @@ def types(self) -> List[Dict[str, Any]]:
6068
6169 return convert_to_easypost_object (response = response )
6270
63- def create_ups (self , ** params ) -> CarrierAccount :
64- """Create a UPS CarrierAccount which has its own custom workflow."""
65- url = "/ups_oauth_registrations"
66- wrapped_params = {"ups_oauth_registrations" : params }
67-
68- response = Requestor (self ._client ).request (
69- method = RequestMethod .POST ,
70- url = url ,
71- params = wrapped_params ,
72- )
73-
74- return convert_to_easypost_object (response = response )
75-
76- def update_ups (self , id : str , ** params ) -> CarrierAccount :
77- """Update a UPS CarrierAccount which has its own custom workflow."""
78- return self ._update_resource ("UpsOauthRegistrations" , id , ** params )
79-
8071 def _select_carrier_account_creation_endpoint (self , carrier_account_type : Optional [Any ]) -> str :
8172 """Determines which API endpoint to use for the creation call."""
8273 if carrier_account_type in _CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOWS :
8374 return "/carrier_accounts/register"
75+ elif carrier_account_type in _UPS_OATH_CARRIER_ACCOUNT_TYPES :
76+ return "/ups_oauth_registrations"
8477
8578 return "/carrier_accounts"
0 commit comments