-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor api to split create in new and create, refactor/simplify sav…
…e_link
- Loading branch information
Showing
8 changed files
with
169 additions
and
94 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# import to register models | ||
from . import misc # noqa: F401 | ||
from . import passes # noqa: F401 |
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,71 @@ | ||
""" | ||
Models to be used to assemble the JWT for the save link (add to wallet link). | ||
""" | ||
|
||
from ..bases import Model | ||
from ..bases import WithIdModel | ||
from ..passes import generic | ||
from ..passes import retail | ||
from ..passes import tickets_and_transit | ||
from pydantic import Field | ||
from pydantic import model_validator | ||
|
||
|
||
class Reference(WithIdModel): | ||
""" | ||
References an existing wallet object. | ||
It is used to create the JWT for the add to wallet link. | ||
The id must be an existing wallet object id. | ||
Either model_name or mode_type must be set. | ||
""" | ||
|
||
# inherits id | ||
|
||
# mode_name and model_type are implementation specific for this package | ||
model_name: str | None = Field(exclude=True, default=None) | ||
model_type: type[Model] | None = Field(exclude=True, default=None) | ||
|
||
@model_validator(mode="after") | ||
def check_one_of(self) -> "Reference": | ||
if self.model_name is None and self.model_type is None: | ||
raise ValueError("One of [model_name, model_type] must be set") | ||
if self.model_name is not None and self.model_type is not None: | ||
raise ValueError("Only one of [model_name, model_type] must be set") | ||
return self | ||
|
||
|
||
class JWTPayload(Model): | ||
|
||
eventTicketClasses: ( | ||
list[tickets_and_transit.EventTicketClass | Reference] | None | ||
) = None | ||
eventTicketObjects: ( | ||
list[tickets_and_transit.EventTicketObject | Reference] | None | ||
) = None | ||
flightClasses: list[tickets_and_transit.FlightClass | Reference] | None = None | ||
flightObjects: list[tickets_and_transit.FlightObject | Reference] | None = None | ||
giftCardClasses: list[retail.GiftCardClass | Reference] | None = None | ||
giftCardObjects: list[retail.GiftCardObject | Reference] | None = None | ||
loyaltyClasses: list[retail.LoyaltyClass | Reference] | None = None | ||
loyaltyObjects: list[retail.LoyaltyObject | Reference] | None = None | ||
offerClasses: list[retail.OfferClass | Reference] | None = None | ||
offerObjects: list[retail.OfferObject | Reference] | None = None | ||
transitClasses: list[tickets_and_transit.TransitClass | Reference] | None = None | ||
transitObjects: list[tickets_and_transit.TransitObject | Reference] | None = None | ||
genericClasses: list[generic.GenericClass | Reference] | None = None | ||
genericObjects: list[generic.GenericObject | Reference] | None = None | ||
|
||
|
||
class JWTClaims(Model): | ||
""" | ||
see: https://developers.google.com/wallet/reference/rest/v1/Jwt | ||
""" | ||
|
||
iss: str | ||
aud: str = "google" | ||
typ: str = "savettowallet" | ||
iat: str = "" | ||
payload: JWTPayload | ||
origins: list[str] |
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
Oops, something went wrong.