Skip to content
Merged
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
109 changes: 108 additions & 1 deletion appstoreserverlibrary/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from .models.TransactionHistoryRequest import TransactionHistoryRequest
from .models.TransactionInfoResponse import TransactionInfoResponse
from .models.UpdateAppAccountTokenRequest import UpdateAppAccountTokenRequest
from .models.UploadMessageRequestBody import UploadMessageRequestBody
from .models.GetMessageListResponse import GetMessageListResponse

T = TypeVar('T')

Expand Down Expand Up @@ -457,10 +459,53 @@ class APIError(IntEnum):
GENERAL_INTERNAL_RETRYABLE = 5000001
"""
An error response that indicates an unknown error occurred, but you can try again.

https://developer.apple.com/documentation/appstoreserverapi/generalinternalretryableerror
"""

# Retention Messaging specific errors
HEADER_TOO_LONG_ERROR = 4000101
"""
An error that indicates the message header exceeds 66 characters.

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

BODY_TOO_LONG_ERROR = 4000102
"""
An error that indicates the message body exceeds 144 characters.

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

ALT_TEXT_TOO_LONG_ERROR = 4000103
"""
An error that indicates the alt text exceeds 150 characters.

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

MAXIMUM_NUMBER_OF_MESSAGES_REACHED_ERROR = 4030001
"""
An error that indicates the maximum number of retention messages (2000) has been reached.

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

MESSAGE_NOT_FOUND_ERROR = 4040001
"""
An error that indicates the specified message was not found.

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

MESSAGE_ALREADY_EXISTS_ERROR = 4090001
"""
An error that indicates the message identifier already exists.

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


@define
class APIException(Exception):
Expand Down Expand Up @@ -758,6 +803,37 @@ def set_app_account_token(self, original_transaction_id: str, update_app_account
"""
self._make_request("/inApps/v1/transactions/" + original_transaction_id + "/appAccountToken", "PUT", {}, update_app_account_token_request, None)

def upload_retention_message(self, message_identifier: str, retention_message_request: UploadMessageRequestBody) -> None:
"""
Upload a message to use for retention messaging.
https://developer.apple.com/documentation/retentionmessaging/upload-message

:param message_identifier: A UUID you provide to uniquely identify the message you upload.
:param retention_message_request: The request body containing the message text and optional image reference.
:raises APIException: If a response was returned indicating the request could not be processed
"""
self._make_request("/inApps/v1/messaging/message/" + message_identifier, "PUT", {}, retention_message_request, None)

def get_retention_message_list(self) -> GetMessageListResponse:
"""
Get the message identifier and state of all uploaded messages.
https://developer.apple.com/documentation/retentionmessaging/get-message-list

:return: A response that contains status information for all messages.
:raises APIException: If a response was returned indicating the request could not be processed
"""
return self._make_request("/inApps/v1/messaging/message/list", "GET", {}, None, GetMessageListResponse)

def delete_retention_message(self, message_identifier: str) -> None:
"""
Delete a previously uploaded message.
https://developer.apple.com/documentation/retentionmessaging/delete-message

:param message_identifier: The identifier of the message to delete.
:raises APIException: If a response was returned indicating the request could not be processed
"""
self._make_request("/inApps/v1/messaging/message/" + message_identifier, "DELETE", {}, None, None)

class AsyncAppStoreServerAPIClient(BaseAppStoreServerAPIClient):
def __init__(self, signing_key: bytes, key_id: str, issuer_id: str, bundle_id: str, environment: Environment):
super().__init__(signing_key=signing_key, key_id=key_id, issuer_id=issuer_id, bundle_id=bundle_id, environment=environment)
Expand Down Expand Up @@ -970,3 +1046,34 @@ async def set_app_account_token(self, original_transaction_id: str, update_app_a
:raises APIException: If a response was returned indicating the request could not be processed
"""
await self._make_request("/inApps/v1/transactions/" + original_transaction_id + "/appAccountToken", "PUT", {}, update_app_account_token_request, None)

async def upload_retention_message(self, message_identifier: str, retention_message_request: UploadMessageRequestBody) -> None:
"""
Upload a message to use for retention messaging.
https://developer.apple.com/documentation/retentionmessaging/upload-message

:param message_identifier: A UUID you provide to uniquely identify the message you upload.
:param retention_message_request: The request body containing the message text and optional image reference.
:raises APIException: If a response was returned indicating the request could not be processed
"""
await self._make_request("/inApps/v1/messaging/message/" + message_identifier, "PUT", {}, retention_message_request, None)

async def get_retention_message_list(self) -> GetMessageListResponse:
"""
Get the message identifier and state of all uploaded messages.
https://developer.apple.com/documentation/retentionmessaging/get-message-list

:return: A response that contains status information for all messages.
:raises APIException: If a response was returned indicating the request could not be processed
"""
return await self._make_request("/inApps/v1/messaging/message/list", "GET", {}, None, GetMessageListResponse)

async def delete_retention_message(self, message_identifier: str) -> None:
"""
Delete a previously uploaded message.
https://developer.apple.com/documentation/retentionmessaging/delete-message

:param message_identifier: The identifier of the message to delete.
:raises APIException: If a response was returned indicating the request could not be processed
"""
await self._make_request("/inApps/v1/messaging/message/" + message_identifier, "DELETE", {}, None, None)
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/RetentionMessageState.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 RetentionMessageState(Enum, metaclass=AppStoreServerLibraryEnumMeta):
"""
The approval state of the message.

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

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

APPROVED = "APPROVED"
"""
The message is approved.
"""

REJECTED = "REJECTED"
"""
The message is rejected.
"""
28 changes: 28 additions & 0 deletions appstoreserverlibrary/models/UploadMessageImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2023 Apple Inc. Licensed under MIT License.

from typing import Optional
from attr import define
import attr

@define
class UploadMessageImage:
"""
The definition of an image with its alternative text.

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

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

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

altText: Optional[str] = attr.ib(default=None)
"""
The alternative text you provide for the corresponding image.
Maximum length: 150

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

from typing import Optional
from attr import define
import attr
from .UploadMessageImage import UploadMessageImage

@define
class UploadMessageRequestBody:
"""
The request body for uploading a message, which includes the message text and an optional image reference.

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

header: Optional[str] = attr.ib(default=None)
"""
The header text of the retention message that the system displays to customers.
Maximum length: 66

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

body: Optional[str] = attr.ib(default=None)
"""
The body text of the retention message that the system displays to customers.
Maximum length: 144

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

image: Optional[UploadMessageImage] = attr.ib(default=None)
"""
The optional image identifier and its alternative text to appear as part of a text-based message with an image.

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