Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
319 changes: 318 additions & 1 deletion appstoreserverlibrary/api_client.py

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions appstoreserverlibrary/models/AlternateProduct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional
from attr import define
import attr

@define
class AlternateProduct:
"""
A switch-plan message and product ID you provide in a real-time response to your Get Retention Message endpoint.

https://developer.apple.com/documentation/retentionmessaging/alternateproduct
"""

messageIdentifier: Optional[str] = attr.ib(default=None)
"""
The message identifier of the text to display in the switch-plan retention message.

The message identifier needs to refer to a message that doesn't include an image and that
has a messageState of APPROVED; otherwise, the retention message fails.

https://developer.apple.com/documentation/retentionmessaging/messageidentifier
"""

productId: Optional[str] = attr.ib(default=None)
"""
The product identifier of the subscription the retention message suggests for your customer to switch to.

Use the product identifier in DecodedRealtimeRequestBody to determine the customer's current subscription.
Choose an alternative subscription from the same subscription group.

https://developer.apple.com/documentation/retentionmessaging/productid
"""
69 changes: 69 additions & 0 deletions appstoreserverlibrary/models/DecodedRealtimeRequestBody.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional
from attr import define
import attr
from .Environment import Environment
from .LibraryUtility import AttrsRawValueAware

@define
class DecodedRealtimeRequestBody(AttrsRawValueAware):
"""
The decoded request body the App Store sends to your server to request a real-time retention message.

https://developer.apple.com/documentation/retentionmessaging/decodedrealtimerequestbody
"""

originalTransactionId: Optional[str] = attr.ib(default=None)
"""
The original transaction identifier of the customer's subscription.

https://developer.apple.com/documentation/retentionmessaging/originaltransactionid
"""

appAppleId: Optional[int] = attr.ib(default=None)
"""
The unique identifier of the app in the App Store.

https://developer.apple.com/documentation/retentionmessaging/appappleid
"""

productId: Optional[str] = attr.ib(default=None)
"""
The unique identifier of the auto-renewable subscription.

https://developer.apple.com/documentation/retentionmessaging/productid
"""

userLocale: Optional[str] = attr.ib(default=None)
"""
The device's locale.

https://developer.apple.com/documentation/retentionmessaging/locale
"""

requestIdentifier: Optional[str] = attr.ib(default=None)
"""
A UUID the App Store server creates to uniquely identify each request.

https://developer.apple.com/documentation/retentionmessaging/requestidentifier
"""

environment: Optional[Environment] = Environment.create_main_attr('rawEnvironment')
"""
The server environment, either sandbox or production.

https://developer.apple.com/documentation/retentionmessaging/environment
"""

rawEnvironment: Optional[str] = Environment.create_raw_attr('environment')
"""
See environment
"""

signedDate: Optional[int] = attr.ib(default=None)
"""
The UNIX time, in milliseconds, that the App Store signed the JSON Web Signature (JWS) data.

https://developer.apple.com/documentation/retentionmessaging/signeddate
"""
20 changes: 20 additions & 0 deletions appstoreserverlibrary/models/DefaultConfigurationRequest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional
from attr import define
import attr

@define
class DefaultConfigurationRequest:
"""
The request body that contains the default configuration information.

https://developer.apple.com/documentation/retentionmessaging/defaultconfigurationrequest
"""

messageIdentifier: Optional[str] = attr.ib(default=None)
"""
The message identifier of the message to configure as a default message.

https://developer.apple.com/documentation/retentionmessaging/messageidentifier
"""
21 changes: 21 additions & 0 deletions appstoreserverlibrary/models/GetImageListResponse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional, List
from attr import define
import attr
from .GetImageListResponseItem import GetImageListResponseItem

@define
class GetImageListResponse:
"""
A response that contains status information for all images.

https://developer.apple.com/documentation/retentionmessaging/getimagelistresponse
"""

imageIdentifiers: Optional[List[GetImageListResponseItem]] = attr.ib(default=None)
"""
An array of all image identifiers and their image state.

https://developer.apple.com/documentation/retentionmessaging/getimagelistresponseitem
"""
34 changes: 34 additions & 0 deletions appstoreserverlibrary/models/GetImageListResponseItem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional
from attr import define
import attr
from .ImageState import ImageState
from .LibraryUtility import AttrsRawValueAware

@define
class GetImageListResponseItem(AttrsRawValueAware):
"""
An image identifier and state information for an image.

https://developer.apple.com/documentation/retentionmessaging/getimagelistresponseitem
"""

imageIdentifier: Optional[str] = attr.ib(default=None)
"""
The identifier of the image.

https://developer.apple.com/documentation/retentionmessaging/imageidentifier
"""

imageState: Optional[ImageState] = ImageState.create_main_attr('rawImageState')
"""
The current state of the image.

https://developer.apple.com/documentation/retentionmessaging/imagestate
"""

rawImageState: Optional[str] = ImageState.create_raw_attr('imageState')
"""
See imageState
"""
21 changes: 21 additions & 0 deletions appstoreserverlibrary/models/GetMessageListResponse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional, List
from attr import define
import attr
from .GetMessageListResponseItem import GetMessageListResponseItem

@define
class GetMessageListResponse:
"""
A response that contains status information for all messages.

https://developer.apple.com/documentation/retentionmessaging/getmessagelistresponse
"""

messageIdentifiers: Optional[List[GetMessageListResponseItem]] = attr.ib(default=None)
"""
An array of all message identifiers and their message states.

https://developer.apple.com/documentation/retentionmessaging/getmessagelistresponseitem
"""
34 changes: 34 additions & 0 deletions appstoreserverlibrary/models/GetMessageListResponseItem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional
from attr import define
import attr
from .RetentionMessageState import RetentionMessageState
from .LibraryUtility import AttrsRawValueAware

@define
class GetMessageListResponseItem(AttrsRawValueAware):
"""
A message identifier and status information for a message.

https://developer.apple.com/documentation/retentionmessaging/getmessagelistresponseitem
"""

messageIdentifier: Optional[str] = attr.ib(default=None)
"""
The identifier of the message.

https://developer.apple.com/documentation/retentionmessaging/messageidentifier
"""

messageState: Optional[RetentionMessageState] = RetentionMessageState.create_main_attr('rawMessageState')
"""
The current state of the message.

https://developer.apple.com/documentation/retentionmessaging/messagestate
"""

rawMessageState: Optional[str] = RetentionMessageState.create_raw_attr('messageState')
"""
See messageState
"""
26 changes: 26 additions & 0 deletions appstoreserverlibrary/models/ImageState.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from enum import Enum
from .LibraryUtility import AppStoreServerLibraryEnumMeta

class ImageState(Enum, metaclass=AppStoreServerLibraryEnumMeta):
"""
The approval state of an image.

https://developer.apple.com/documentation/retentionmessaging/imagestate
"""

PENDING = "PENDING"
"""
The image is awaiting approval.
"""

APPROVED = "APPROVED"
"""
The image is approved.
"""

REJECTED = "REJECTED"
"""
The image is rejected.
"""
20 changes: 20 additions & 0 deletions appstoreserverlibrary/models/LibraryUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from functools import lru_cache
from typing import Any, List, Type, TypeVar

import attr
from attr import Attribute, has, ib, fields
from cattr import override
from cattrs.gen import make_dict_structure_fn, make_dict_unstructure_fn, override
Expand Down Expand Up @@ -68,4 +69,23 @@ def _get_cattrs_converter(destination_class: Type[T]) -> cattrs.Converter:
cattrs_overrides[raw_field] = override(rename=matching_name)
c.register_structure_hook_factory(has, lambda cl: make_dict_structure_fn(cl, c, **cattrs_overrides))
c.register_unstructure_hook_factory(has, lambda cl: make_dict_unstructure_fn(cl, c, **cattrs_overrides))
return c


@lru_cache(maxsize=None)
def _get_retention_response_converter() -> cattrs.Converter:
"""
Special converter for retention messaging responses that omits None/default values.
This is needed for RealtimeResponseBody where fields are mutually exclusive.
"""
c = cattrs.Converter()

# For any attrs class, configure to omit fields with default values
c.register_unstructure_hook_factory(
has,
lambda cls: make_dict_unstructure_fn(
cls, c, _cattrs_omit_if_default=True
)
)

return c
26 changes: 26 additions & 0 deletions appstoreserverlibrary/models/Message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional
from attr import define
import attr

@define
class Message:
"""
A message identifier you provide in a real-time response to your Get Retention Message endpoint.

https://developer.apple.com/documentation/retentionmessaging/message
"""

messageIdentifier: Optional[str] = attr.ib(default=None)
"""
The identifier of the message to display to the customer.

The message identifier needs to refer to a message that has a messageState of APPROVED;
otherwise, the retention message fails. If the message includes an image, the image also
needs to have an imageState of APPROVED.

For more information about setting up messages, see Upload Message.

https://developer.apple.com/documentation/retentionmessaging/messageidentifier
"""
56 changes: 56 additions & 0 deletions appstoreserverlibrary/models/PromotionalOffer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional
from attr import define
import attr
from .PromotionalOfferSignatureV1 import PromotionalOfferSignatureV1

@define
class PromotionalOffer:
"""
A promotional offer and message you provide in a real-time response to your Get Retention Message endpoint.

https://developer.apple.com/documentation/retentionmessaging/promotionaloffer
"""

messageIdentifier: Optional[str] = attr.ib(default=None)
"""
The identifier of the message to display to the customer, along with the promotional offer.

The message identifier needs to refer to a message that doesn't have an image, and that has
a messageState of APPROVED; otherwise, the retention message fails.

https://developer.apple.com/documentation/retentionmessaging/messageidentifier
"""

promotionalOfferSignatureV2: Optional[str] = attr.ib(default=None)
"""
The promotional offer signature in V2 format. This field is mutually exclusive with
promotionalOfferSignatureV1 field.

For new implementations, consider using this V2 signature, which is easier to generate.
To generate this signature, use the PromotionalOfferV2SignatureCreator class:

Example:
from appstoreserverlibrary.jws_signature_creator import PromotionalOfferV2SignatureCreator

creator = PromotionalOfferV2SignatureCreator(signing_key, key_id, issuer_id, bundle_id)
signature = creator.create_signature(
product_id="com.example.subscription",
offer_identifier="intro_offer",
transaction_id="optional_transaction_id"
)

https://developer.apple.com/documentation/retentionmessaging/promotionaloffersignaturev2
"""

promotionalOfferSignatureV1: Optional[PromotionalOfferSignatureV1] = attr.ib(default=None)
"""
The promotional offer signature in V1 format. This field is mutually exclusive with the
promotionalOfferSignatureV2 field.

To generate this signature, use the PromotionalOfferSignatureCreator class.
See PromotionalOfferSignatureV1 for implementation details.

https://developer.apple.com/documentation/retentionmessaging/promotionaloffersignaturev1
"""
Loading