Skip to content

Commit 593ea1c

Browse files
Ihor BilousIhor Bilous
authored andcommitted
Fix issue #53: Add full usage in all examples
1 parent 8322164 commit 593ea1c

19 files changed

+188
-8
lines changed

examples/contacts/contact_fields.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,22 @@ def delete_contact_field(contact_field_id: int) -> DeletedObject:
4646

4747

4848
if __name__ == "__main__":
49-
print(list_contact_fields())
49+
created = create_contact_field(
50+
name="example_field", data_type="string", merge_tag="EXAMPLE"
51+
)
52+
print(created)
53+
54+
fields = list_contact_fields()
55+
print(fields)
56+
57+
field_id = fields[0].id
58+
field = get_contact_field(contact_field_id=field_id)
59+
print(field)
60+
61+
updated = update_contact_field(
62+
contact_field_id=field_id, name=f"{field.name}-updated"
63+
)
64+
print(updated)
65+
66+
deleted = delete_contact_field(contact_field_id=field_id)
67+
print(deleted)

examples/contacts/contact_lists.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,21 @@ def delete_contact_list(contact_list_id: int) -> DeletedObject:
3232

3333

3434
if __name__ == "__main__":
35-
print(list_contact_lists())
35+
created = create_contact_list(name="example-list")
36+
print(created)
37+
38+
lists = list_contact_lists()
39+
print(lists)
40+
41+
list_id = lists[0].id
42+
contact_list = get_contact_list(contact_list_id=list_id)
43+
print(contact_list)
44+
45+
updated = update_contact_list(
46+
contact_list_id=list_id,
47+
name=f"{contact_list.name}-updated",
48+
)
49+
print(updated)
50+
51+
deleted = delete_contact_list(contact_list_id=list_id)
52+
print(deleted)

examples/contacts/contacts.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def delete_contact(contact_id_or_email: str) -> DeletedObject:
6060
},
6161
)
6262
print(created_contact)
63+
6364
updated_contact = update_contact(
6465
created_contact.id,
6566
fields={
@@ -68,5 +69,9 @@ def delete_contact(contact_id_or_email: str) -> DeletedObject:
6869
},
6970
)
7071
print(updated_contact)
72+
73+
contact = get_contact(updated_contact.id)
74+
print(contact)
75+
7176
deleted_contact = delete_contact(updated_contact.id)
7277
print(deleted_contact)

examples/email_templates/templates.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,28 @@ def delete_template(template_id: str) -> DeletedObject:
5959

6060

6161
if __name__ == "__main__":
62-
print(list_templates())
62+
created = create_template(
63+
name="Example Template",
64+
subject="Hello",
65+
category="transactional",
66+
body_text="Hello world",
67+
)
68+
print(created)
69+
70+
templates = list_templates()
71+
print(templates)
72+
73+
template_id = templates[0].id
74+
template = get_template(template_id=template_id)
75+
print(template)
76+
77+
updated = update_template(
78+
template_id=template_id,
79+
name=f"{template.name}-updated",
80+
subject=f"{template.subject}-updated",
81+
body_text=f"{template.body_text}\nUpdated content.",
82+
)
83+
print(updated)
84+
85+
deleted = delete_template(template_id=template_id)
86+
print(deleted)

examples/general/account_accesses.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ def delete_account_access(account_id: int, account_access_id: int) -> DeletedObj
2020

2121

2222
if __name__ == "__main__":
23-
print(get_account_accesses(ACCOUNT_ID))
23+
accesses = get_account_accesses(ACCOUNT_ID)
24+
print(accesses)
25+
if accesses:
26+
access_id = accesses[0].id
27+
deleted = delete_account_access(
28+
account_id=ACCOUNT_ID, account_access_id=access_id
29+
)
30+
print(deleted)

examples/general/accounts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ def get_accounts() -> list[Account]:
1212

1313

1414
if __name__ == "__main__":
15-
print(get_accounts())
15+
accounts = get_accounts()
16+
print(accounts)

examples/general/billing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ def get_current_billing_usage(account_id: int) -> BillingCycleUsage:
1313

1414

1515
if __name__ == "__main__":
16-
print(get_current_billing_usage(ACCOUNT_ID))
16+
usage = get_current_billing_usage(ACCOUNT_ID)
17+
print(usage)

examples/general/permissions.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ def bulk_permissions_update(
2626

2727

2828
if __name__ == "__main__":
29-
print(get_permission_resources(ACCOUNT_ID))
29+
resources = get_permission_resources(ACCOUNT_ID)
30+
print(resources)
31+
if resources:
32+
account_access_id = resources[0].id
33+
payload = [
34+
mt.PermissionResourceParams(resource_name=resources[0].name, permissions=[])
35+
]
36+
updated = bulk_permissions_update(
37+
ACCOUNT_ID,
38+
account_access_id,
39+
payload,
40+
)
41+
print(updated)

examples/sending/advanced_sending.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
2323
sandbox=True,
2424
inbox_id="<YOUR_INBOX_ID>",
2525
)
26+
raise ValueError(f"Invalid sending type: {type_}")
2627

2728

2829
# Image should be in the same level in directory like this python file.

examples/sending/batch_advanced_sending.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def get_client(type_: SendingType) -> mt.MailtrapClient:
2323
sandbox=True,
2424
inbox_id="<YOUR_INBOX_ID>",
2525
)
26+
raise ValueError(f"Invalid sending type: {type_}")
2627

2728

2829
# Image should be in the same level in directory like this python file.

0 commit comments

Comments
 (0)