Skip to content

Commit

Permalink
Group Attributes of Class and Object elements of Google Wallet, to ma…
Browse files Browse the repository at this point in the history
…ke it more maintainable.
  • Loading branch information
loechel committed Apr 22, 2024
1 parent d5003b1 commit 5c23cd4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 18 deletions.
70 changes: 67 additions & 3 deletions src/edutap/wallet_google/modelbase.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
from .models.primitives import CallbackOptions
from .models.primitives import GroupingInfo
from .models.primitives import Image
from .models.primitives import PassConstraints
from .models.primitives import SecurityAnimation
from .models.primitives.barcode import Barcode
from .models.primitives.barcode import RotatingBarcode
from .models.primitives.class_template_info import ClassTemplateInfo
from .models.primitives.data import ImageModuleData
from .models.primitives.data import InfoModuleData
from .models.primitives.data import LinksModuleData
from .models.primitives.data import TextModuleData
from .models.primitives.enums import ViewUnlockRequirement
from .models.primitives.notification import Message
from pydantic import BaseModel
from pydantic import ConfigDict
from pydantic import Field


class GoogleWalletModel(BaseModel):
Expand All @@ -9,6 +24,7 @@ class GoogleWalletModel(BaseModel):

model_config = ConfigDict(
extra="forbid",
# extra="ignore",
use_enum_values=True,
)

Expand All @@ -18,6 +34,7 @@ class GoogleWalletWithIdModel(GoogleWalletModel):
Base model for Google Wallet models with an identifier.
"""

kind: str | None = Field(description="deprecated", exclude=True, default=None)
id: str


Expand All @@ -26,6 +43,36 @@ class GoogleWalletClassModel(GoogleWalletWithIdModel):
Base model for all Google Wallet Class models.
"""

classTemplateInfo: ClassTemplateInfo | None = None
imageModulesData: list[ImageModuleData] | None = None
textModulesData: list[TextModuleData] | None = None
linksModuleData: LinksModuleData | None = None
infoModuleData: InfoModuleData | None = Field(
description="deprecated", exclude=True, default=None
)

# Callback Options
callbackOptions: CallbackOptions | None = None

# Smarttap Options
enableSmartTap: bool | None = None
redemptionIssuers: list[str] | None = None # string (int64 format)

# Barcode Options
securityAnimation: SecurityAnimation | None = None

# Security Options
viewUnlockRequirement: ViewUnlockRequirement = (
ViewUnlockRequirement.VIEW_UNLOCK_REQUIREMENT_UNSPECIFIED
)

# Design Options
hexBackgroundColor: str | None = None
logo: Image | None = None
wideLogo: Image | None = None
heroImage: Image | None = None
wordMark: Image | None = Field(description="deprecated", exclude=True, default=None)


class GoogleWalletObjectModel(GoogleWalletWithIdModel):
"""
Expand All @@ -34,10 +81,27 @@ class GoogleWalletObjectModel(GoogleWalletWithIdModel):

classId: str

groupingInfo: GroupingInfo | None = None

# Security Options
passConstraints: PassConstraints | None = None

# Barcode Options
barcode: Barcode | None = None
rotatingBarcode: RotatingBarcode | None = None


class GoogleWalletObjectReference(GoogleWalletObjectModel):
"""
Model for all Google Wallet Object with a Class references.
"""

classReference: GoogleWalletClassModel | None = None


class GoogleWalletObjectReference(GoogleWalletWithIdModel):
class GoogleWalletMessageble(GoogleWalletWithIdModel):
"""
Model for all Google Wallet Object references.
Model for Google Wallet Classes or Objects that can retrieve Messages
"""

classId: str | None = None
messages: list[Message] | None = None
35 changes: 20 additions & 15 deletions src/edutap/wallet_google/models/retail.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ..modelbase import GoogleWalletClassModel
from ..modelbase import GoogleWalletMessageble
from ..modelbase import GoogleWalletObjectModel
from ..registry import register_model
from .primitives import CallbackOptions
Expand Down Expand Up @@ -72,17 +73,17 @@ class GiftCardClass(GoogleWalletClassModel):
imageModulesData: list[ImageModuleData] | None = None
textModulesData: list[TextModuleData] | None = None
linksModuleData: LinksModuleData | None = None
redemptionIssuers: list[str] | None = None
# redemptionIssuers: list[str] | None = None
countryCode: str | None = None
heroImage: Image | None = None
# heroImage: Image | None = None
wordMark: Image | None = Field(description="deprecated", exclude=True, default=None)
enableSmartTap: bool | None = None
# enableSmartTap: bool | None = None
hexBackgroundColor: str | None = None
localizedIssuerName: LocalizedString | None = None
multipleDevicesAndHoldersAllowedStatus: MultipleDevicesAndHoldersAllowedStatus = (
MultipleDevicesAndHoldersAllowedStatus.STATUS_UNSPECIFIED
)
callbackOptions: CallbackOptions | None = None
# callbackOptions: CallbackOptions | None = None
securityAnimation: SecurityAnimation | None = None
viewUnlockRequirement: ViewUnlockRequirement = (
ViewUnlockRequirement.VIEW_UNLOCK_REQUIREMENT_UNSPECIFIED
Expand All @@ -109,6 +110,7 @@ class GiftCardObject(GoogleWalletObjectModel):
locations: list[LatLongPoint] | None = None
hasUsers: bool = False
smartTapRedemptionValue: str | None = None
smartTapRedemptionLevel: str | None = None
hasLinkedDevice: bool = False
disableExpirationNotification: bool | None = False
infoModuleData: InfoModuleData | None = None
Expand All @@ -118,21 +120,24 @@ class GiftCardObject(GoogleWalletObjectModel):
appLinkData: AppLinkData | None = None
rotatingBarcode: RotatingBarcode | None = None
heroImage: Image | None = None
groupingInfo: GroupingInfo | None = None
passConstraints: PassConstraints | None = None
# groupingInfo: GroupingInfo | None = None
# passConstraints: PassConstraints | None = None


@register_model(
"LoyaltyClass", url_part="loyaltyClass", plural="loyaltyClasses", can_disable=False
)
class LoyaltyClass(GoogleWalletClassModel):
class LoyaltyClass(GoogleWalletClassModel, GoogleWalletMessageble):
"""
see: https://developers.google.com/wallet/retail/loyalty-cards/rest/v1/loyaltyclass
"""

issuerName: str | None = None
programName: str | None = None
programLogo: Image | None = None
logo: Image | None = Field(
alias="programLogo", serialization_alias="programLogo", default=None
)
wideProgramLogo: Image | None = None
reviewStatus: ReviewStatus = ReviewStatus.REVIEW_STATUS_UNSPECIFIED
accountNameLabel: str | None = None
Expand All @@ -150,23 +155,23 @@ class LoyaltyClass(GoogleWalletClassModel):
localizedSecondaryRewardsTierLabel: LocalizedString | None = None
localizedSecondaryRewardsTier: LocalizedString | None = None
discoverableProgram: DiscoverableProgram | None = None
classTemplateInfo: ClassTemplateInfo | None = None
# classTemplateInfo: ClassTemplateInfo | None = None
messages: list[Message] | None = None
homepageUri: Uri | None = None
locations: list[LatLongPoint] | None = None
review: Review | None = None
imageModulesData: list[ImageModuleData] | None = None
textModulesData: list[TextModuleData] | None = None
linksModuleData: LinksModuleData | None = None
redemptionIssuers: list[str] | None = None # string (int64 format)
# imageModulesData: list[ImageModuleData] | None = None
# textModulesData: list[TextModuleData] | None = None
# linksModuleData: LinksModuleData | None = None
# redemptionIssuers: list[str] | None = None # string (int64 format)
countryCode: str | None = None
heroImage: Image | None = None
enableSmartTap: bool | None = False
hexBackgroundColor: str | None = None
# enableSmartTap: bool | None = False
# hexBackgroundColor: str | None = None
multipleDevicesAndHoldersAllowedStatus: MultipleDevicesAndHoldersAllowedStatus = (
MultipleDevicesAndHoldersAllowedStatus.STATUS_UNSPECIFIED
)
callbackOptions: CallbackOptions | None
# callbackOptions: CallbackOptions | None
securityAnimation: SecurityAnimation | None = None
viewUnlockRequirement: ViewUnlockRequirement = (
ViewUnlockRequirement.VIEW_UNLOCK_REQUIREMENT_UNSPECIFIED
Expand Down

0 comments on commit 5c23cd4

Please sign in to comment.