-
Notifications
You must be signed in to change notification settings - Fork 18
Fixed ListEventQueryParams to use a more specific type for orderBy parameter and correct JSON name. #276
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
Merged
AaronDDM
merged 4 commits into
main
from
CUST-4375-v-3-java-sdk-does-not-support-order-by-like-the-api-does
May 27, 2025
Merged
Fixed ListEventQueryParams to use a more specific type for orderBy parameter and correct JSON name. #276
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
136 changes: 136 additions & 0 deletions
136
examples/src/main/java/com/nylas/examples/EventsExample.java
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,136 @@ | ||
| package com.nylas.examples; | ||
|
|
||
| import com.nylas.NylasClient; | ||
| import com.nylas.models.NylasApiError; | ||
| import com.nylas.models.NylasSdkTimeoutError; | ||
| import com.nylas.models.Calendar; | ||
| import com.nylas.models.Event; | ||
| import com.nylas.models.ListEventQueryParams; | ||
| import com.nylas.models.Response; | ||
| import com.nylas.models.ListResponse; | ||
| import com.nylas.models.EventQueryOrderBy; | ||
| import okhttp3.OkHttpClient; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class EventsExample { | ||
| public static void main(String[] args) { | ||
| try { | ||
| // Load configuration from environment variables or .env file | ||
| Map<String, String> config = loadConfig(); | ||
|
|
||
| // Initialize the Nylas client with your API key | ||
| NylasClient nylas = new NylasClient( | ||
| config.get("NYLAS_API_KEY"), | ||
| new OkHttpClient.Builder(), | ||
| config.getOrDefault("NYLAS_API_URI", "https://api.us.nylas.com") | ||
| ); | ||
|
|
||
| // Run the example workflow | ||
| runEventsExample(nylas, config); | ||
|
|
||
| // Exit successfully | ||
| System.exit(0); | ||
|
|
||
| } catch (NylasApiError e) { | ||
| System.out.println("\n❌ Nylas API Error: " + e.getMessage()); | ||
| System.out.println(" Status code: " + e.getStatusCode()); | ||
| System.out.println(" Request ID: " + e.getRequestId()); | ||
| System.exit(1); | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println("\n❌ Configuration Error: " + e.getMessage()); | ||
| System.exit(1); | ||
| } catch (Exception e) { | ||
| System.out.println("\n❌ Unexpected Error: " + e.getMessage()); | ||
| e.printStackTrace(); | ||
| System.exit(1); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Loads configuration from environment variables and .env file | ||
| * @throws IllegalArgumentException if required configuration is missing | ||
| */ | ||
| private static Map<String, String> loadConfig() { | ||
| Map<String, String> config = new HashMap<>(); | ||
|
|
||
| // Try loading from environment variables first | ||
| System.getenv().entrySet().stream() | ||
| .filter(entry -> entry.getKey().startsWith("NYLAS_") || entry.getKey().equals("MEETING_LINK")) | ||
| .forEach(entry -> config.put(entry.getKey(), entry.getValue())); | ||
|
|
||
| // Then try loading from .env file if needed | ||
| List<String> envPaths = Arrays.asList("examples/.env", ".env"); | ||
| for (String path : envPaths) { | ||
| File envFile = new File(path); | ||
| if (envFile.exists()) { | ||
| System.out.println("📝 Loading configuration from " + envFile.getAbsolutePath()); | ||
| try { | ||
| Files.lines(envFile.toPath()) | ||
| .filter(line -> !line.trim().isEmpty() && !line.startsWith("#")) | ||
| .forEach(line -> { | ||
| String[] parts = line.split("=", 2); | ||
| if (parts.length == 2) { | ||
| String key = parts[0].trim(); | ||
| String value = parts[1].trim(); | ||
| if (!config.containsKey(key)) { | ||
| config.put(key, value); | ||
| } | ||
| } | ||
| }); | ||
| } catch (IOException e) { | ||
| System.out.println("Warning: Failed to load .env file: " + e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Validate required configuration | ||
| List<String> requiredKeys = Arrays.asList("NYLAS_API_KEY", "MEETING_LINK"); | ||
| List<String> missingKeys = requiredKeys.stream() | ||
| .filter(key -> !config.containsKey(key)) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| if (!missingKeys.isEmpty()) { | ||
| throw new IllegalArgumentException( | ||
| "Missing required configuration: " + String.join(", ", missingKeys) + "\n" + | ||
| "Please set these in examples/.env or as environment variables." | ||
| ); | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| private static void runEventsExample(NylasClient nylas, Map<String, String> config) throws NylasApiError, NylasSdkTimeoutError { | ||
| // Get the primary calendar | ||
| Response<Calendar> primaryCalendar = nylas.calendars().find(config.get("NYLAS_GRANT_ID"), "primary"); | ||
|
|
||
| // Get the start and end times for the query | ||
| long start = (System.currentTimeMillis() / 1000L) - (60 * 60 * 24 * 30); // 30 days ago in Unix timestamp | ||
| long end = (System.currentTimeMillis() / 1000L) + (60 * 60 * 24 * 30); // 30 days from now in Unix timestamp | ||
|
|
||
| // List events | ||
| ListEventQueryParams.Builder eventQueryBuilder = new ListEventQueryParams.Builder(primaryCalendar.getData().getId()) | ||
| .start(String.valueOf(start)) | ||
| .end(String.valueOf(end)) | ||
| .expandRecurring(false) | ||
| .showCancelled(true) | ||
| .orderBy(EventQueryOrderBy.START) | ||
| .limit(200); | ||
|
|
||
| // Get the events | ||
| ListResponse<Event> events = nylas.events().list(config.get("NYLAS_GRANT_ID"), eventQueryBuilder.build()); | ||
|
|
||
| // Print the events | ||
| System.out.println("Found " + events.getData().size() + " events"); | ||
| for (Event event : events.getData()) { | ||
| System.out.println(event); | ||
| } | ||
| } | ||
| } |
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,8 @@ | ||
| package com.nylas.models | ||
|
|
||
| import com.squareup.moshi.Json | ||
|
|
||
| enum class EventQueryOrderBy { | ||
| @Json(name = "start") | ||
| START, | ||
| } |
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.
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.