Skip to content
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

Sample code to use JMAP library #13

Merged
merged 1 commit into from
Aug 18, 2021
Merged
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
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,64 @@ Please report any problem, any feature request, or discuss how you plan to use t

## Code samples

(TODO)
#### GetSession:
```dart
// create instance of httpClient with Dio
// using BasicAuth to config Dio
final httpClient = HttpClient(Dio());

final getSessionBuilder = GetSessionBuilder(httpClient);
final session = await getSessionBuilder.build().execute();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where/how do you set up authentication?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested on the comment above

```

#### Fetching mailboxes
```dart
final processingInvocation = ProcessingInvocation();
final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation);

final getMailboxMethod = GetMailboxMethod(accountId)
..addProperties(Properties({'role', 'name'}));

final queryInvocation = jmapRequestBuilder.invocation(getMailboxMethod);

final responseObject = await (jmapRequestBuilder
..usings(getMailboxCreated.requiredCapabilities))
.build()
.execute();

final getMailboxResponse = responseObject.parse<GetMailboxResponse>(
queryInvocation.methodCallId,
GetMailboxResponse.deserialize);
```

#### Get emails in Mailbox
```dart
final processingInvocation = ProcessingInvocation();

final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation);

final queryEmailMethod = QueryEmailMethod(accountId)
..addPosition(0)
..addLimit(UnsignedInt(20))
..addSorts({EmailComparator(EmailComparatorProperty.sentAt)..setIsAscending(false)})
..addFilters(EmailFilterCondition(inMailbox: inBoxId));

final queryEmailInvocation = jmapRequestBuilder.invocation(queryEmailMethod);

final getEmailMethod = GetEmailMethod(accountId)
..addProperties(Properties({'id', 'subject','from', 'keywords', 'sentAt', 'preview', 'hasAttachment'}))
..addReferenceIds(processingInvocation.createResultReference(
queryEmailInvocation.methodCallId,
ReferencePath.idsPath));

final getEmailInvocation = jmapRequestBuilder.invocation(getEmailMethod);

final responseObject = await (jmapRequestBuilder
..usings(getEmailMethod.requiredCapabilities))
.build()
.execute();

final getEmailResponse = responseObject.parse<GetEmailResponse>(
getEmailInvocation.methodCallId,
GetEmailResponse.deserialize);
```