Repository navigation
Add Subscription Topics and topic fields on campaigns, contacts, imports, suppressions, email logs and webhooks #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Rabsztok
wants to merge
6
commits into
main
Choose a base branch
from
add-subscription-topics-to-the-sdks-and
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,096
−70
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bba8836
Add Subscription Topics and the topic fields
Rabsztok 36f93ec
Pick email-log event details by type on every construction path
Rabsztok 67ea283
Pick email-log details in a field validator
Rabsztok b1a01d6
Follow topic pagination in the campaign example
Rabsztok 28a8357
Pick email-log details from a lookup table and fold repeated tests
Rabsztok 45f2931
Read contact topic preferences that come without a domain ID
Rabsztok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
| import os | ||
| from typing import Optional | ||
|
|
||
| import mailtrap as mt | ||
| from mailtrap.models.subscription_topics import SubscriptionTopic | ||
| from mailtrap.models.subscription_topics import SubscriptionTopicListResponse | ||
|
|
||
| API_KEY = os.environ["MAILTRAP_API_KEY"] | ||
|
|
||
| client = mt.MailtrapClient(token=API_KEY) | ||
| subscription_topics_api = client.subscription_topics_api.subscription_topics | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| def list_subscription_topics( | ||
| token: Optional[int] = None, | ||
| ) -> SubscriptionTopicListResponse: | ||
| # `token` is the page number (page-token pagination); `per_page` caps at | ||
| # 100 (default 50). Deleted topics are left out. | ||
| return subscription_topics_api.get_list( | ||
| mt.SubscriptionTopicListParams(per_page=50, token=token) | ||
| ) | ||
|
|
||
|
|
||
| def get_subscription_topic(subscription_topic_id: int) -> SubscriptionTopic: | ||
| # A deleted topic is returned too, with `deleted_at` set. | ||
| return subscription_topics_api.get_by_id(subscription_topic_id) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| try: | ||
| page = list_subscription_topics() | ||
| except mt.APIError as error: | ||
| if error.status != 403: | ||
| raise | ||
| raise SystemExit("Subscription topics aren't available for this account.") | ||
|
|
||
| while True: | ||
| for topic in page.data: | ||
| # `domain_id` is None when the topic covers every sending domain. | ||
| print(f"{topic.id}: {topic.name} (domain: {topic.domain_id or 'all'})") | ||
| if page.pagination is None or page.pagination.next_token is None: | ||
| break | ||
| page = list_subscription_topics(token=page.pagination.next_token) | ||
|
|
||
| if page.data: | ||
| print(get_subscription_topic(page.data[0].id)) | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| from typing import Optional | ||
|
|
||
| from mailtrap.http import HttpClient | ||
| from mailtrap.models.subscription_topics import SubscriptionTopic | ||
| from mailtrap.models.subscription_topics import SubscriptionTopicListParams | ||
| from mailtrap.models.subscription_topics import SubscriptionTopicListResponse | ||
| from mailtrap.models.subscription_topics import SubscriptionTopicResponse | ||
|
|
||
|
|
||
| class SubscriptionTopicsApi: | ||
| """ | ||
| Subscription Topics API. On an account without subscription topics, both | ||
| calls raise ``APIError`` with status ``403``. | ||
| """ | ||
|
|
||
| def __init__(self, client: HttpClient) -> None: | ||
| self._client = client | ||
|
|
||
| def get_list( | ||
| self, params: Optional[SubscriptionTopicListParams] = None | ||
| ) -> SubscriptionTopicListResponse: | ||
| """ | ||
| List the account's subscription topics, one page at a time, leaving out | ||
| deleted ones. Pass ``pagination.next_token`` with the same ``per_page`` | ||
| to get the next page. Omit ``params`` for the first page with API | ||
| defaults. | ||
| """ | ||
| query_params = params.api_query_params if params else None | ||
| response = self._client.get(self._api_path(), params=query_params or None) | ||
| return SubscriptionTopicListResponse(**response) | ||
|
|
||
| def get_by_id(self, subscription_topic_id: int) -> SubscriptionTopic: | ||
| """ | ||
| Get a subscription topic by ID. A deleted topic is returned too, with | ||
| ``deleted_at`` set. | ||
| """ | ||
| response = self._client.get(self._api_path(subscription_topic_id)) | ||
| return SubscriptionTopicResponse(**response).data | ||
|
|
||
| def _api_path(self, subscription_topic_id: Optional[int] = None) -> str: | ||
| path = "/api/subscription_topics" | ||
| if subscription_topic_id is not None: | ||
| return f"{path}/{subscription_topic_id}" | ||
| return path |
This file contains hidden or 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 hidden or 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,11 @@ | ||
| from mailtrap.api.resources.subscription_topics import SubscriptionTopicsApi | ||
| from mailtrap.http import HttpClient | ||
|
|
||
|
|
||
| class SubscriptionTopicsBaseApi: | ||
| def __init__(self, client: HttpClient) -> None: | ||
| self._client = client | ||
|
|
||
| @property | ||
| def subscription_topics(self) -> SubscriptionTopicsApi: | ||
| return SubscriptionTopicsApi(client=self._client) |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.