-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from smkent/dev
Add usage examples and development status information
- Loading branch information
Showing
6 changed files
with
166 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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,26 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
|
||
from jmapc import Client | ||
from jmapc.methods import CoreEcho | ||
|
||
# Create and configure client | ||
client = Client( | ||
host=os.environ["JMAP_HOST"], | ||
user=os.environ["JMAP_USER"], | ||
password=os.environ["JMAP_PASSWORD"], | ||
) | ||
|
||
# Prepare a request for the JMAP Core/echo method with some sample data | ||
method = CoreEcho(data=dict(hello="world")) | ||
|
||
# Call JMAP API with the prepared request | ||
result = client.call_method(method) | ||
|
||
# Print result | ||
print(result) | ||
|
||
# Example output: | ||
# | ||
# CoreEchoResponse(data={'hello': 'world'}) |
This file contains 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,32 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
|
||
from jmapc import Client | ||
from jmapc.methods import IdentityGet | ||
|
||
# Create and configure client | ||
client = Client( | ||
host=os.environ["JMAP_HOST"], | ||
user=os.environ["JMAP_USER"], | ||
password=os.environ["JMAP_PASSWORD"], | ||
) | ||
|
||
# Prepare Identity/get request | ||
# To retrieve all of the user's identities, no arguments are required. | ||
method = IdentityGet() | ||
|
||
# Call JMAP API with the prepared request | ||
result = client.call_method(method) | ||
|
||
# Print some information about each retrieved identity | ||
for identity in result.data: | ||
print( | ||
f"Identity {identity.id} is for " | ||
f"{identity.name} at {identity.email}" | ||
) | ||
|
||
# Example output: | ||
# | ||
# Identity 12345 is for Ness at ness@onett.example.com | ||
# Identity 67890 is for Ness at ness-alternate@onett.example.com |
This file contains 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,57 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
|
||
from jmapc import Client, MailboxQueryFilterCondition, ResultReference | ||
from jmapc.methods import MailboxGet, MailboxQuery | ||
|
||
# Create and configure client | ||
client = Client( | ||
host=os.environ["JMAP_HOST"], | ||
user=os.environ["JMAP_USER"], | ||
password=os.environ["JMAP_PASSWORD"], | ||
) | ||
|
||
# Prepare two methods to be submitted in one request | ||
# The first method, Mailbox/query, will locate the ID of the Inbox folder | ||
# The second method, Mailbox/get, uses a result reference to retrieve the Inbox | ||
# mailbox details | ||
methods = [ | ||
MailboxQuery(filter=MailboxQueryFilterCondition(name="Inbox")), | ||
MailboxGet( | ||
ids=ResultReference( | ||
name=MailboxQuery.name(), | ||
path="/ids", | ||
result_of="0", | ||
), | ||
), | ||
] | ||
|
||
# Call JMAP API with the prepared request | ||
results = client.call_methods(methods) | ||
|
||
# Retrieve the result tuple for the second method. The result tuple contains | ||
# the client-provided method ID, and the result data model. | ||
method_2_result = results[1] | ||
|
||
# Retrieve the result data model from the result tuple | ||
method_2_result_data = method_2_result[1] | ||
|
||
# Retrieve the Mailbox data from the result data model | ||
mailboxes = method_2_result_data.data | ||
|
||
# Although multiple mailboxes may be present in the results, we only expect a | ||
# single match for our query. Retrieve the first Mailbox from the list. | ||
mailbox = mailboxes[0] | ||
|
||
# Print some information about the mailbox | ||
print(f"Found the mailbox named {mailbox.name} with ID {mailbox.id}") | ||
print( | ||
f"This mailbox has {mailbox.total_emails} emails, " | ||
f"{mailbox.unread_emails} of which are unread" | ||
) | ||
|
||
# Example output: | ||
# | ||
# Found the mailbox named Inbox with ID deadbeef-0000-0000-0000-000000000001 | ||
# This mailbox has 42 emails, 4 of which are unread |
This file contains 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 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