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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ build
.classpath
.project
.settings
bin
bin

# Ignore Intellij files
.idea
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This section contains changes that have been committed but not yet released.

### Added

- Add `metadata` field in the Event model to support new event metadata
- Add support for filtering `metadata` using `metadata_key`, `metadata_value`, and `metadata_pair`]

### Changed

### Deprecated
Expand Down
8 changes: 8 additions & 0 deletions src/examples/java/com/nylas/examples/other/DocExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.nylas.Contact;
import com.nylas.Draft;
Expand Down Expand Up @@ -221,6 +223,12 @@ public static void postEventExample() throws IOException, RequestFailedException
event.setDescription("Let's celebrate our calendar integration!!");
event.setBusy(true);

// Metadata can be added to an event to store extra information and
// add custom fields. You can also query on metadata by keys, values, and key-value pairs
Map<String, String> metadata = new HashMap<>();
metadata.put("event_category", "gathering");
event.setMetadata(metadata);

// Participants are added as a list of Participant objects, which require email
// and may contain name, status, or comment as well
event.setParticipants(Arrays.asList(new Participant("swag@nylas.com").name("My Nylas Friend")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.nylas.Calendar;
import com.nylas.Event;
Expand Down Expand Up @@ -53,7 +55,7 @@ public static void main(String[] args) throws Exception {
.startsAfter(Instant.now())
.startsBefore(Instant.now().plus(30, ChronoUnit.DAYS ))
.limit(50);

for (Event event : events.list(query)) {
System.out.println("event: " + event);
}
Expand Down Expand Up @@ -95,6 +97,11 @@ protected static void basicEventCrud(Events events, Calendar primary) throws IOE
created.setLocation("Lake Merritt");
created.setParticipants(Arrays.asList(partier, partier1, partier2, partier3));
created.setRecurrence(new Recurrence(startTz.getId(), Arrays.asList("RRULE:FREQ=WEEKLY;BYDAY=TH")));

Map<String, String> metadata = new HashMap<>();
metadata.put("event_category", "gathering");
created.setMetadata(metadata);

Event updated = events.update(created, true);
System.out.println("Updated: " + updated);

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/nylas/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Event extends AccountOwnedModel implements JsonObject {
private String status;
private Boolean read_only;
private Boolean busy;
private Map<String, String> metadata;

private Recurrence recurrence;

Expand Down Expand Up @@ -86,6 +87,10 @@ public Boolean getBusy() {
return busy;
}

public Map<String, String> getMetadata() {
return metadata;
}

public Recurrence getRecurrence() {
return recurrence;
}
Expand All @@ -106,7 +111,7 @@ public static JsonAdapter.Factory getWhenJsonFactory() {
public String toString() {
return "Event [id=" + getId() + ", calendar_id=" + calendar_id + ", ical_uid=" + ical_uid + ", title=" + title
+ ", when=" + when + ", location=" + location + ", owner=" + owner + ", participants=" + participants
+ ", status=" + status + ", read_only=" + read_only + ", busy=" + busy + ", recurrence=" + recurrence
+ ", status=" + status + ", read_only=" + read_only + ", busy=" + busy + ", metadata=" + metadata + ", recurrence=" + recurrence
+ ", master_event_id=" + master_event_id + ", original_start_time=" + getOriginalStartTime() + "]";
}

Expand Down Expand Up @@ -134,6 +139,10 @@ public void setBusy(Boolean busy) {
this.busy = busy;
}

public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
}

public void setRecurrence(Recurrence recurrence) {
this.recurrence = recurrence;
}
Expand All @@ -150,6 +159,7 @@ Map<String, Object> getWritableFields(boolean creation) {
Maps.putIfNotNull(params, "location", getLocation());
Maps.putIfNotNull(params, "participants", getParticipants());
Maps.putIfNotNull(params, "busy", getBusy());
Maps.putIfNotNull(params, "metadata", getMetadata());
Maps.putIfNotNull(params, "recurrence", getRecurrence());
return params;
}
Expand Down
67 changes: 66 additions & 1 deletion src/main/java/com/nylas/EventQuery.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.nylas;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import okhttp3.HttpUrl;

Expand All @@ -17,6 +20,9 @@ public class EventQuery extends RestfulQuery<EventQuery> {
private Instant startsAfter;
private Instant endsBefore;
private Instant endsAfter;
private List<String> metadataKeys;
private List<String> metadataValues;
private List<String> metadataPairs;

@Override
public void addParameters(HttpUrl.Builder url) {
Expand Down Expand Up @@ -55,6 +61,21 @@ public void addParameters(HttpUrl.Builder url) {
if (endsAfter != null) {
url.addQueryParameter("ends_after", Instants.formatEpochSecond(endsAfter));
}
if (metadataKeys != null) {
for(String key : metadataKeys) {
url.addQueryParameter("metadata_key", key);
}
}
if (metadataValues != null) {
for(String value : metadataValues) {
url.addQueryParameter("metadata_value", value);
}
}
if (metadataPairs != null) {
for(String value : metadataPairs) {
url.addQueryParameter("metadata_pair", value);
}
}
}

public EventQuery expandRecurring(Boolean expandRecurring) {
Expand Down Expand Up @@ -111,5 +132,49 @@ public EventQuery endsAfter(Instant endsAfter) {
this.endsAfter = endsAfter;
return this;
}


/**
* Return events with metadata containing a property having the given key.
*
* If multiple instances of metadata methods are invoked
* (any combination of calls to metadataKey, metadataValue, or metadataPair),
* then this query will return events which match ANY one of them.
*/
public EventQuery metadataKey(String... metadataKey) {
if (this.metadataKeys == null) {
this.metadataKeys = new ArrayList<>();
}
this.metadataKeys.addAll(Arrays.asList(metadataKey));
return this;
}

/**
* Return events with metadata containing a property having the given value.
*
* If multiple instances of metadata methods are invoked
* (any combination of calls to metadataKey, metadataValue, or metadataPair),
* then this query will return events which match ANY one of them.
*/
public EventQuery metadataValue(String... metadataValue) {
if (this.metadataValues == null) {
this.metadataValues = new ArrayList<>();
}
this.metadataValues.addAll(Arrays.asList(metadataValue));
return this;
}

/**
* Return events with metadata containing a property having the given key-value pair.
*
* If multiple instances of metadata methods are invoked
* (any combination of calls to metadataKey, metadataValue, or metadataPair),
* then this query will return events which match ANY one of them.
*/
public EventQuery metadataPair(String key, String value) {
if (this.metadataPairs == null) {
this.metadataPairs = new ArrayList<>();
}
this.metadataPairs.add(key + ":" + value);
return this;
}
}