From 031ca69f1d2e18b240c04dafa08daab6110389de Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Thu, 6 Jul 2023 18:21:47 -0400 Subject: [PATCH 01/20] Replace Java with Kotlin + Add Auth, Calendar & Event support (#154) # Description This PR shifts the Java SDK into a Kotlin SDK. This is done to enable friendlier support for Kotlin-powered applications while still keeping the SDK feeling native to Java, as we're designing this SDK with Java interoperability in mind. This PR also brings support for: - Nylas API v3 - Auth methods - Calendars API CRUD - Events API CRUD - Application CRUD # License I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner. --- .editorconfig | 6 + build.gradle | 211 ---- build.gradle.kts | 51 + gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.jar | Bin 58702 -> 58694 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew.bat | 3 + settings.gradle => settings.gradle.kts | 2 +- .../java/com/nylas/examples/ExampleConf.java | 113 -- .../java/com/nylas/examples/Readme.md | 25 - .../HostedAuthFetchTokenExample.java | 24 - .../hostedAuth/HostedAuthUrlExample.java | 35 - .../nativeAuth/HtmlTemplateResponder.java | 36 - .../nativeAuth/NativeAuthGoogleExample.java | 299 ------ .../nativeAuth/NativeAuthPasswordExample.java | 126 --- .../examples/other/AccountDetailExample.java | 22 - .../nylas/examples/other/AccountsExample.java | 60 -- .../other/ApplicationDetailExample.java | 32 - .../examples/other/AuthenticationExample.java | 90 -- .../examples/other/CalendarsExample.java | 114 --- .../examples/other/ComponentsExample.java | 35 - .../nylas/examples/other/ContactsExample.java | 101 -- .../nylas/examples/other/DeltaExample.java | 56 - .../com/nylas/examples/other/DocExamples.java | 359 ------- .../nylas/examples/other/DraftsExample.java | 119 --- .../nylas/examples/other/EventsExample.java | 202 ---- .../nylas/examples/other/FilesExample.java | 42 - .../nylas/examples/other/FoldersExample.java | 73 -- .../other/IpAddressWhitelistExample.java | 23 - .../examples/other/JobStatusExample.java | 41 - .../nylas/examples/other/LabelsExample.java | 68 -- .../examples/other/MessageSearchExample.java | 30 - .../nylas/examples/other/MessagesExample.java | 93 -- .../nylas/examples/other/NeuralExample.java | 74 -- .../nylas/examples/other/OutboxExample.java | 48 - .../examples/other/RoomResourceExample.java | 28 - .../examples/other/SchedulerExample.java | 67 -- .../examples/other/SendDirectExample.java | 42 - .../examples/other/SendDraftExample.java | 48 - .../examples/other/SendRawMimeExample.java | 27 - .../examples/other/ThreadSearchExample.java | 29 - .../nylas/examples/other/ThreadsExample.java | 41 - .../examples/webhooks/WebhookServer.java | 88 -- .../examples/webhooks/WebhooksExample.java | 63 -- src/examples/resources/.gitignore | 1 - .../resources/example.properties.template | 111 -- .../native-auth-google/base.ftlh | 16 - .../native-auth-google/step1.ftlh | 12 - .../native-auth-google/step2.ftlh | 18 - .../native-auth-google/step3.ftlh | 18 - src/examples/resources/log4j2.xml | 19 - src/main/java/com/nylas/AccessToken.java | 44 - src/main/java/com/nylas/Account.java | 59 -- src/main/java/com/nylas/AccountDetail.java | 53 - .../java/com/nylas/AccountOwnedModel.java | 30 - src/main/java/com/nylas/AccountQuery.java | 27 - src/main/java/com/nylas/Accounts.java | 110 -- .../nylas/AddVersionHeadersInterceptor.java | 26 - .../java/com/nylas/ApplicationDetail.java | 31 - src/main/java/com/nylas/Authentication.java | 95 -- .../java/com/nylas/AuthenticationDAO.java | 18 - .../java/com/nylas/AuthorizationCode.java | 11 - src/main/java/com/nylas/Availability.java | 21 - .../java/com/nylas/AvailabilityQuery.java | 187 ---- src/main/java/com/nylas/BuildInfo.java | 54 - src/main/java/com/nylas/Calendar.java | 96 -- src/main/java/com/nylas/CalendarQuery.java | 27 - src/main/java/com/nylas/Calendars.java | 123 --- src/main/java/com/nylas/Component.java | 160 --- src/main/java/com/nylas/ComponentQuery.java | 4 - src/main/java/com/nylas/Components.java | 48 - .../com/nylas/ConsecutiveAvailability.java | 27 - src/main/java/com/nylas/Contact.java | 390 ------- src/main/java/com/nylas/ContactGroup.java | 22 - src/main/java/com/nylas/ContactGroups.java | 19 - src/main/java/com/nylas/ContactQuery.java | 94 -- src/main/java/com/nylas/Contacts.java | 64 -- .../com/nylas/ContentHeadersInterceptor.java | 38 - src/main/java/com/nylas/Count.java | 11 - src/main/java/com/nylas/Deltas.java | 249 ----- src/main/java/com/nylas/Draft.java | 182 ---- src/main/java/com/nylas/DraftQuery.java | 5 - src/main/java/com/nylas/Drafts.java | 143 --- src/main/java/com/nylas/Event.java | 964 ------------------ src/main/java/com/nylas/EventQuery.java | 277 ----- src/main/java/com/nylas/Events.java | 205 ---- src/main/java/com/nylas/File.java | 52 - src/main/java/com/nylas/FileQuery.java | 42 - src/main/java/com/nylas/Files.java | 86 -- src/main/java/com/nylas/Folder.java | 45 - src/main/java/com/nylas/FolderQuery.java | 5 - src/main/java/com/nylas/Folders.java | 61 -- src/main/java/com/nylas/FreeBusy.java | 35 - .../java/com/nylas/FreeBusyCalendars.java | 35 - src/main/java/com/nylas/FreeBusyQuery.java | 106 -- .../com/nylas/GoogleProviderSettings.java | 82 -- src/main/java/com/nylas/Grant.java | 205 ---- src/main/java/com/nylas/GrantQuery.java | 5 - src/main/java/com/nylas/Grants.java | 108 -- .../java/com/nylas/HostedAuthentication.java | 203 ---- .../com/nylas/HttpLoggingInterceptor.java | 190 ---- .../java/com/nylas/IPAddressWhitelist.java | 24 - .../java/com/nylas/ImapProviderSettings.java | 71 -- src/main/java/com/nylas/Integration.java | 231 ----- .../IntegrationHostedAuthentication.java | 144 --- src/main/java/com/nylas/IntegrationQuery.java | 5 - src/main/java/com/nylas/Integrations.java | 102 -- src/main/java/com/nylas/JobStatus.java | 151 --- src/main/java/com/nylas/JobStatusQuery.java | 5 - src/main/java/com/nylas/JobStatuses.java | 27 - src/main/java/com/nylas/JsonHelper.java | 108 -- src/main/java/com/nylas/JsonObject.java | 5 - .../com/nylas/KnownImapProviderSettings.java | 31 - src/main/java/com/nylas/Label.java | 31 - src/main/java/com/nylas/LabelQuery.java | 5 - src/main/java/com/nylas/Labels.java | 48 - src/main/java/com/nylas/LoginInfo.java | 120 --- src/main/java/com/nylas/Message.java | 118 --- .../java/com/nylas/MessageObjectQuery.java | 126 --- src/main/java/com/nylas/MessageQuery.java | 42 - src/main/java/com/nylas/Messages.java | 201 ---- src/main/java/com/nylas/MetadataQuery.java | 96 -- .../MicrosoftExchangeProviderSettings.java | 45 - .../MicrosoftOffice365ProviderSettings.java | 45 - .../com/nylas/MultipleAvailabilityQuery.java | 43 - src/main/java/com/nylas/NameEmail.java | 26 - .../java/com/nylas/NativeAuthentication.java | 236 ----- src/main/java/com/nylas/Neural.java | 184 ---- .../java/com/nylas/NeuralCategorizer.java | 111 -- .../com/nylas/NeuralCleanConversation.java | 23 - .../java/com/nylas/NeuralMessageOptions.java | 67 -- src/main/java/com/nylas/NeuralOcr.java | 24 - .../com/nylas/NeuralSentimentAnalysis.java | 35 - .../com/nylas/NeuralSignatureContacts.java | 118 --- .../com/nylas/NeuralSignatureExtraction.java | 28 - src/main/java/com/nylas/Notification.java | 546 ---------- src/main/java/com/nylas/NylasAccount.java | 101 -- src/main/java/com/nylas/NylasApplication.java | 131 --- src/main/java/com/nylas/NylasClient.java | 320 ------ src/main/java/com/nylas/OpenHours.java | 64 -- src/main/java/com/nylas/Outbox.java | 117 --- src/main/java/com/nylas/OutboxJobStatus.java | 21 - src/main/java/com/nylas/OutboxMessage.java | 113 -- src/main/java/com/nylas/Participant.java | 124 --- src/main/java/com/nylas/ProviderSettings.java | 149 --- .../java/com/nylas/RateLimitException.java | 75 -- src/main/java/com/nylas/RemoteCollection.java | 123 --- .../com/nylas/RequestFailedException.java | 111 -- src/main/java/com/nylas/RestfulDAO.java | 182 ---- src/main/java/com/nylas/RestfulModel.java | 49 - src/main/java/com/nylas/RestfulQuery.java | 77 -- src/main/java/com/nylas/RoomResource.java | 70 -- src/main/java/com/nylas/RoomResources.java | 28 - src/main/java/com/nylas/Schedulers.java | 164 --- src/main/java/com/nylas/Scope.java | 89 -- src/main/java/com/nylas/SearchQuery.java | 36 - .../com/nylas/SendGridVerifiedStatus.java | 21 - .../com/nylas/SingleAvailabilityQuery.java | 87 -- src/main/java/com/nylas/Thread.java | 144 --- src/main/java/com/nylas/ThreadQuery.java | 151 --- src/main/java/com/nylas/Threads.java | 151 --- src/main/java/com/nylas/TimeSlot.java | 87 -- src/main/java/com/nylas/TokenInfo.java | 34 - src/main/java/com/nylas/Tracking.java | 47 - src/main/java/com/nylas/Webhook.java | 118 --- src/main/java/com/nylas/WebhookQuery.java | 5 - src/main/java/com/nylas/Webhooks.java | 47 - src/main/java/com/nylas/delta/Delta.java | 55 - .../java/com/nylas/delta/DeltaCursor.java | 33 - .../nylas/delta/DeltaLongPollListener.java | 6 - .../com/nylas/delta/DeltaQueryOptions.java | 93 -- .../com/nylas/delta/DeltaStreamListener.java | 8 - .../nylas/scheduler/AvailableCalendars.java | 38 - .../nylas/scheduler/BookingConfirmation.java | 103 -- .../com/nylas/scheduler/BookingRequest.java | 130 --- .../nylas/scheduler/ProviderAvailability.java | 53 - .../java/com/nylas/scheduler/Scheduler.java | 925 ----------------- .../com/nylas/scheduler/SchedulerQuery.java | 7 - .../java/com/nylas/scheduler/TimeSlot.java | 89 -- .../nylas/scheduler/UploadImageResponse.java | 35 - src/main/java/com/nylas/services/Tunnel.java | 200 ---- src/main/kotlin/com/nylas/BuildInfo.kt | 34 + src/main/kotlin/com/nylas/NylasClient.kt | 254 +++++ .../AddVersionHeadersInterceptor.kt | 19 + .../interceptors/ContentHeadersInterceptor.kt | 31 + .../interceptors/HttpLoggingInterceptor.kt | 166 +++ .../kotlin/com/nylas/models/AccessType.kt | 11 + .../com/nylas/models/ApplicationDetails.kt | 50 + .../kotlin/com/nylas/models/AuthProvider.kt | 17 + src/main/kotlin/com/nylas/models/Calendar.kt | 34 + .../com/nylas/models/CodeExchangeRequest.kt | 35 + .../com/nylas/models/CodeExchangeResponse.kt | 20 + .../kotlin/com/nylas/models/Conferencing.kt | 32 + .../com/nylas/models/ConferencingProvider.kt | 20 + .../com/nylas/models/CreateCalendarRequest.kt | 33 + .../nylas/models/CreateEventQueryParams.kt | 23 + .../com/nylas/models/CreateEventRequest.kt | 236 +++++ .../com/nylas/models/CreateGrantRequest.kt | 27 + .../nylas/models/CreateRedirectUriRequest.kt | 23 + .../kotlin/com/nylas/models/DeleteResponse.kt | 8 + .../nylas/models/DestroyEventQueryParams.kt | 23 + src/main/kotlin/com/nylas/models/EmailName.kt | 6 + .../kotlin/com/nylas/models/Environment.kt | 11 + .../kotlin/com/nylas/models/EvenVisibility.kt | 11 + src/main/kotlin/com/nylas/models/Event.kt | 61 ++ .../com/nylas/models/FindEventQueryParams.kt | 16 + src/main/kotlin/com/nylas/models/Grant.kt | 30 + .../com/nylas/models/HostedAuthRequest.kt | 42 + .../com/nylas/models/HostedAuthResponse.kt | 31 + .../kotlin/com/nylas/models/IQueryParams.kt | 17 + .../nylas/models/ListCalendersQueryParams.kt | 28 + .../com/nylas/models/ListEventQueryParams.kt | 83 ++ .../com/nylas/models/ListGrantsQueryParams.kt | 51 + .../kotlin/com/nylas/models/ListResponse.kt | 15 + .../kotlin/com/nylas/models/NylasApiError.kt | 13 + .../com/nylas/models/NylasApiErrorResponse.kt | 10 + .../kotlin/com/nylas/models/OpenIDResponse.kt | 37 + .../kotlin/com/nylas/models/PKCEAuthURL.kt | 7 + .../kotlin/com/nylas/models/Participant.kt | 16 + .../com/nylas/models/ParticipantStatus.kt | 17 + src/main/kotlin/com/nylas/models/Platform.kt | 20 + src/main/kotlin/com/nylas/models/Provider.kt | 31 + .../com/nylas/models/ProviderDetectParams.kt | 28 + .../nylas/models/ProviderDetectResponse.kt | 14 + .../kotlin/com/nylas/models/Recurrence.kt | 10 + .../kotlin/com/nylas/models/RedirectUri.kt | 14 + .../com/nylas/models/RedirectUriSettings.kt | 14 + src/main/kotlin/com/nylas/models/Region.kt | 11 + .../kotlin/com/nylas/models/ReminderMethod.kt | 17 + src/main/kotlin/com/nylas/models/Reminders.kt | 10 + src/main/kotlin/com/nylas/models/Response.kt | 13 + .../com/nylas/models/TokenExchangeRequest.kt | 31 + .../com/nylas/models/UpdateCalendarRequest.kt | 40 + .../nylas/models/UpdateEventQueryParams.kt | 23 + .../com/nylas/models/UpdateEventRequest.kt | 270 +++++ .../com/nylas/models/UpdateGrantRequest.kt | 20 + .../nylas/models/UpdateRedirectUriRequest.kt | 24 + .../models/UrlForAuthenticationConfig.kt | 57 ++ src/main/kotlin/com/nylas/models/When.kt | 63 ++ src/main/kotlin/com/nylas/models/WhenType.kt | 17 + .../com/nylas/resources/Applications.kt | 21 + src/main/kotlin/com/nylas/resources/Auth.kt | 142 +++ .../kotlin/com/nylas/resources/Calendars.kt | 46 + src/main/kotlin/com/nylas/resources/Events.kt | 42 + src/main/kotlin/com/nylas/resources/Grants.kt | 47 + .../kotlin/com/nylas/resources/Providers.kt | 28 + .../com/nylas/resources/RedirectUris.kt | 46 + .../kotlin/com/nylas/resources/Resource.kt | 49 + .../com/nylas/util/ConferencingAdapter.kt | 28 + .../nylas/util/CreateConferencingAdapter.kt | 26 + .../com/nylas/util/CreateWhenAdapter.kt | 30 + .../com/nylas/util}/Instants.java | 2 +- src/main/kotlin/com/nylas/util/JsonHelper.kt | 114 +++ .../nylas => kotlin/com/nylas/util}/Maps.java | 2 +- .../nylas/util/UpdateConferencingAdapter.kt | 26 + .../com/nylas/util/UpdateWhenAdapter.kt | 30 + .../com/nylas/util}/Validations.java | 2 +- src/main/resources/build.properties | 1 + src/test/java/com/nylas/AccessTokenTest.java | 50 - .../java/com/nylas/AccountDetailTest.java | 37 - .../java/com/nylas/AccountOwnedModelTest.java | 24 - src/test/java/com/nylas/AccountQueryTest.java | 45 - src/test/java/com/nylas/AccountTest.java | 41 - src/test/java/com/nylas/AccountsTest.java | 197 ---- .../java/com/nylas/AuthenticationDAOTest.java | 42 - .../java/com/nylas/AuthenticationTest.java | 83 -- .../java/com/nylas/AuthorizationCodeTest.java | 35 - .../java/com/nylas/ByteChannelSource.java | 55 - .../java/com/nylas/CalendarQueryTest.java | 29 - src/test/java/com/nylas/CalendarTest.java | 62 -- src/test/java/com/nylas/CalendarsTest.java | 271 ----- src/test/java/com/nylas/ContactGroupTest.java | 24 - .../java/com/nylas/ContactGroupsTest.java | 66 -- src/test/java/com/nylas/ContactQueryTest.java | 131 --- src/test/java/com/nylas/ContactTest.java | 221 ---- src/test/java/com/nylas/ContactsTest.java | 197 ---- .../nylas/ContentHeadersInterceptorTest.java | 65 -- src/test/java/com/nylas/EventTest.java | 482 --------- .../java/com/nylas/FieldReflectionUtils.java | 52 - .../java/com/nylas/FreeBusyCalendarsTest.java | 55 - .../java/com/nylas/FreeBusyQueryTest.java | 79 -- src/test/java/com/nylas/FreeBusyTest.java | 43 - src/test/java/com/nylas/GrantQueryTest.java | 78 -- src/test/java/com/nylas/GrantTest.java | 286 ------ src/test/java/com/nylas/GrantsTest.java | 206 ---- .../com/nylas/HostedAuthenticationTest.java | 68 -- .../com/nylas/MessageObjectQueryTest.java | 59 -- src/test/java/com/nylas/MessageQueryTest.java | 28 - src/test/java/com/nylas/MessageTest.java | 98 -- src/test/java/com/nylas/MessagesTest.java | 502 --------- src/test/java/com/nylas/MockNylas.java | 23 - .../com/nylas/NativeAuthenticationTest.java | 149 --- src/test/java/com/nylas/NylasAccountTest.java | 73 -- .../java/com/nylas/NylasApplicationTest.java | 279 ----- src/test/java/com/nylas/NylasClientTest.java | 547 ---------- .../java/com/nylas/ProviderSettingsTest.java | 137 --- src/test/java/com/nylas/ScopeTest.java | 38 - src/test/java/com/nylas/TestAuthEntity.java | 10 - src/test/java/com/nylas/TestAuthRest.java | 4 - .../java/com/nylas/TestClientResponse.java | 9 - src/test/java/com/nylas/TestNotification.java | 13 - src/test/java/com/nylas/ThreadQueryTest.java | 58 -- src/test/java/com/nylas/ThreadTest.java | 101 -- src/test/java/com/nylas/ThreadsTest.java | 419 -------- src/test/java/com/nylas/TokenInfoTest.java | 25 - src/test/resources/log4j2.xml | 19 - 306 files changed, 3067 insertions(+), 22007 deletions(-) create mode 100644 .editorconfig delete mode 100644 build.gradle create mode 100644 build.gradle.kts rename settings.gradle => settings.gradle.kts (90%) delete mode 100644 src/examples/java/com/nylas/examples/ExampleConf.java delete mode 100644 src/examples/java/com/nylas/examples/Readme.md delete mode 100644 src/examples/java/com/nylas/examples/hostedAuth/HostedAuthFetchTokenExample.java delete mode 100644 src/examples/java/com/nylas/examples/hostedAuth/HostedAuthUrlExample.java delete mode 100644 src/examples/java/com/nylas/examples/nativeAuth/HtmlTemplateResponder.java delete mode 100644 src/examples/java/com/nylas/examples/nativeAuth/NativeAuthGoogleExample.java delete mode 100644 src/examples/java/com/nylas/examples/nativeAuth/NativeAuthPasswordExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/AccountDetailExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/AccountsExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/ApplicationDetailExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/AuthenticationExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/CalendarsExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/ComponentsExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/ContactsExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/DeltaExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/DocExamples.java delete mode 100644 src/examples/java/com/nylas/examples/other/DraftsExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/EventsExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/FilesExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/FoldersExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/IpAddressWhitelistExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/JobStatusExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/LabelsExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/MessageSearchExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/MessagesExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/NeuralExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/OutboxExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/RoomResourceExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/SchedulerExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/SendDirectExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/SendDraftExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/SendRawMimeExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/ThreadSearchExample.java delete mode 100644 src/examples/java/com/nylas/examples/other/ThreadsExample.java delete mode 100644 src/examples/java/com/nylas/examples/webhooks/WebhookServer.java delete mode 100644 src/examples/java/com/nylas/examples/webhooks/WebhooksExample.java delete mode 100644 src/examples/resources/.gitignore delete mode 100644 src/examples/resources/example.properties.template delete mode 100644 src/examples/resources/html-templates/native-auth-google/base.ftlh delete mode 100644 src/examples/resources/html-templates/native-auth-google/step1.ftlh delete mode 100644 src/examples/resources/html-templates/native-auth-google/step2.ftlh delete mode 100644 src/examples/resources/html-templates/native-auth-google/step3.ftlh delete mode 100644 src/examples/resources/log4j2.xml delete mode 100644 src/main/java/com/nylas/AccessToken.java delete mode 100644 src/main/java/com/nylas/Account.java delete mode 100644 src/main/java/com/nylas/AccountDetail.java delete mode 100644 src/main/java/com/nylas/AccountOwnedModel.java delete mode 100644 src/main/java/com/nylas/AccountQuery.java delete mode 100644 src/main/java/com/nylas/Accounts.java delete mode 100644 src/main/java/com/nylas/AddVersionHeadersInterceptor.java delete mode 100644 src/main/java/com/nylas/ApplicationDetail.java delete mode 100644 src/main/java/com/nylas/Authentication.java delete mode 100644 src/main/java/com/nylas/AuthenticationDAO.java delete mode 100644 src/main/java/com/nylas/AuthorizationCode.java delete mode 100644 src/main/java/com/nylas/Availability.java delete mode 100644 src/main/java/com/nylas/AvailabilityQuery.java delete mode 100644 src/main/java/com/nylas/BuildInfo.java delete mode 100644 src/main/java/com/nylas/Calendar.java delete mode 100644 src/main/java/com/nylas/CalendarQuery.java delete mode 100644 src/main/java/com/nylas/Calendars.java delete mode 100644 src/main/java/com/nylas/Component.java delete mode 100644 src/main/java/com/nylas/ComponentQuery.java delete mode 100644 src/main/java/com/nylas/Components.java delete mode 100644 src/main/java/com/nylas/ConsecutiveAvailability.java delete mode 100644 src/main/java/com/nylas/Contact.java delete mode 100644 src/main/java/com/nylas/ContactGroup.java delete mode 100644 src/main/java/com/nylas/ContactGroups.java delete mode 100644 src/main/java/com/nylas/ContactQuery.java delete mode 100644 src/main/java/com/nylas/Contacts.java delete mode 100644 src/main/java/com/nylas/ContentHeadersInterceptor.java delete mode 100644 src/main/java/com/nylas/Count.java delete mode 100644 src/main/java/com/nylas/Deltas.java delete mode 100644 src/main/java/com/nylas/Draft.java delete mode 100644 src/main/java/com/nylas/DraftQuery.java delete mode 100644 src/main/java/com/nylas/Drafts.java delete mode 100644 src/main/java/com/nylas/Event.java delete mode 100644 src/main/java/com/nylas/EventQuery.java delete mode 100644 src/main/java/com/nylas/Events.java delete mode 100644 src/main/java/com/nylas/File.java delete mode 100644 src/main/java/com/nylas/FileQuery.java delete mode 100644 src/main/java/com/nylas/Files.java delete mode 100644 src/main/java/com/nylas/Folder.java delete mode 100644 src/main/java/com/nylas/FolderQuery.java delete mode 100644 src/main/java/com/nylas/Folders.java delete mode 100644 src/main/java/com/nylas/FreeBusy.java delete mode 100644 src/main/java/com/nylas/FreeBusyCalendars.java delete mode 100644 src/main/java/com/nylas/FreeBusyQuery.java delete mode 100644 src/main/java/com/nylas/GoogleProviderSettings.java delete mode 100644 src/main/java/com/nylas/Grant.java delete mode 100644 src/main/java/com/nylas/GrantQuery.java delete mode 100644 src/main/java/com/nylas/Grants.java delete mode 100644 src/main/java/com/nylas/HostedAuthentication.java delete mode 100644 src/main/java/com/nylas/HttpLoggingInterceptor.java delete mode 100644 src/main/java/com/nylas/IPAddressWhitelist.java delete mode 100644 src/main/java/com/nylas/ImapProviderSettings.java delete mode 100644 src/main/java/com/nylas/Integration.java delete mode 100644 src/main/java/com/nylas/IntegrationHostedAuthentication.java delete mode 100644 src/main/java/com/nylas/IntegrationQuery.java delete mode 100644 src/main/java/com/nylas/Integrations.java delete mode 100644 src/main/java/com/nylas/JobStatus.java delete mode 100644 src/main/java/com/nylas/JobStatusQuery.java delete mode 100644 src/main/java/com/nylas/JobStatuses.java delete mode 100644 src/main/java/com/nylas/JsonHelper.java delete mode 100644 src/main/java/com/nylas/JsonObject.java delete mode 100644 src/main/java/com/nylas/KnownImapProviderSettings.java delete mode 100644 src/main/java/com/nylas/Label.java delete mode 100644 src/main/java/com/nylas/LabelQuery.java delete mode 100644 src/main/java/com/nylas/Labels.java delete mode 100644 src/main/java/com/nylas/LoginInfo.java delete mode 100644 src/main/java/com/nylas/Message.java delete mode 100644 src/main/java/com/nylas/MessageObjectQuery.java delete mode 100644 src/main/java/com/nylas/MessageQuery.java delete mode 100644 src/main/java/com/nylas/Messages.java delete mode 100644 src/main/java/com/nylas/MetadataQuery.java delete mode 100644 src/main/java/com/nylas/MicrosoftExchangeProviderSettings.java delete mode 100644 src/main/java/com/nylas/MicrosoftOffice365ProviderSettings.java delete mode 100644 src/main/java/com/nylas/MultipleAvailabilityQuery.java delete mode 100644 src/main/java/com/nylas/NameEmail.java delete mode 100644 src/main/java/com/nylas/NativeAuthentication.java delete mode 100644 src/main/java/com/nylas/Neural.java delete mode 100644 src/main/java/com/nylas/NeuralCategorizer.java delete mode 100644 src/main/java/com/nylas/NeuralCleanConversation.java delete mode 100644 src/main/java/com/nylas/NeuralMessageOptions.java delete mode 100644 src/main/java/com/nylas/NeuralOcr.java delete mode 100644 src/main/java/com/nylas/NeuralSentimentAnalysis.java delete mode 100644 src/main/java/com/nylas/NeuralSignatureContacts.java delete mode 100644 src/main/java/com/nylas/NeuralSignatureExtraction.java delete mode 100644 src/main/java/com/nylas/Notification.java delete mode 100644 src/main/java/com/nylas/NylasAccount.java delete mode 100644 src/main/java/com/nylas/NylasApplication.java delete mode 100644 src/main/java/com/nylas/NylasClient.java delete mode 100644 src/main/java/com/nylas/OpenHours.java delete mode 100644 src/main/java/com/nylas/Outbox.java delete mode 100644 src/main/java/com/nylas/OutboxJobStatus.java delete mode 100644 src/main/java/com/nylas/OutboxMessage.java delete mode 100644 src/main/java/com/nylas/Participant.java delete mode 100644 src/main/java/com/nylas/ProviderSettings.java delete mode 100644 src/main/java/com/nylas/RateLimitException.java delete mode 100644 src/main/java/com/nylas/RemoteCollection.java delete mode 100644 src/main/java/com/nylas/RequestFailedException.java delete mode 100644 src/main/java/com/nylas/RestfulDAO.java delete mode 100644 src/main/java/com/nylas/RestfulModel.java delete mode 100644 src/main/java/com/nylas/RestfulQuery.java delete mode 100644 src/main/java/com/nylas/RoomResource.java delete mode 100644 src/main/java/com/nylas/RoomResources.java delete mode 100644 src/main/java/com/nylas/Schedulers.java delete mode 100644 src/main/java/com/nylas/Scope.java delete mode 100644 src/main/java/com/nylas/SearchQuery.java delete mode 100644 src/main/java/com/nylas/SendGridVerifiedStatus.java delete mode 100644 src/main/java/com/nylas/SingleAvailabilityQuery.java delete mode 100644 src/main/java/com/nylas/Thread.java delete mode 100644 src/main/java/com/nylas/ThreadQuery.java delete mode 100644 src/main/java/com/nylas/Threads.java delete mode 100644 src/main/java/com/nylas/TimeSlot.java delete mode 100644 src/main/java/com/nylas/TokenInfo.java delete mode 100644 src/main/java/com/nylas/Tracking.java delete mode 100644 src/main/java/com/nylas/Webhook.java delete mode 100644 src/main/java/com/nylas/WebhookQuery.java delete mode 100644 src/main/java/com/nylas/Webhooks.java delete mode 100644 src/main/java/com/nylas/delta/Delta.java delete mode 100644 src/main/java/com/nylas/delta/DeltaCursor.java delete mode 100644 src/main/java/com/nylas/delta/DeltaLongPollListener.java delete mode 100644 src/main/java/com/nylas/delta/DeltaQueryOptions.java delete mode 100644 src/main/java/com/nylas/delta/DeltaStreamListener.java delete mode 100644 src/main/java/com/nylas/scheduler/AvailableCalendars.java delete mode 100644 src/main/java/com/nylas/scheduler/BookingConfirmation.java delete mode 100644 src/main/java/com/nylas/scheduler/BookingRequest.java delete mode 100644 src/main/java/com/nylas/scheduler/ProviderAvailability.java delete mode 100644 src/main/java/com/nylas/scheduler/Scheduler.java delete mode 100644 src/main/java/com/nylas/scheduler/SchedulerQuery.java delete mode 100644 src/main/java/com/nylas/scheduler/TimeSlot.java delete mode 100644 src/main/java/com/nylas/scheduler/UploadImageResponse.java delete mode 100644 src/main/java/com/nylas/services/Tunnel.java create mode 100644 src/main/kotlin/com/nylas/BuildInfo.kt create mode 100644 src/main/kotlin/com/nylas/NylasClient.kt create mode 100644 src/main/kotlin/com/nylas/interceptors/AddVersionHeadersInterceptor.kt create mode 100644 src/main/kotlin/com/nylas/interceptors/ContentHeadersInterceptor.kt create mode 100644 src/main/kotlin/com/nylas/interceptors/HttpLoggingInterceptor.kt create mode 100644 src/main/kotlin/com/nylas/models/AccessType.kt create mode 100644 src/main/kotlin/com/nylas/models/ApplicationDetails.kt create mode 100644 src/main/kotlin/com/nylas/models/AuthProvider.kt create mode 100644 src/main/kotlin/com/nylas/models/Calendar.kt create mode 100644 src/main/kotlin/com/nylas/models/CodeExchangeRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/CodeExchangeResponse.kt create mode 100644 src/main/kotlin/com/nylas/models/Conferencing.kt create mode 100644 src/main/kotlin/com/nylas/models/ConferencingProvider.kt create mode 100644 src/main/kotlin/com/nylas/models/CreateCalendarRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/CreateEventQueryParams.kt create mode 100644 src/main/kotlin/com/nylas/models/CreateEventRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/CreateGrantRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/CreateRedirectUriRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/DeleteResponse.kt create mode 100644 src/main/kotlin/com/nylas/models/DestroyEventQueryParams.kt create mode 100644 src/main/kotlin/com/nylas/models/EmailName.kt create mode 100644 src/main/kotlin/com/nylas/models/Environment.kt create mode 100644 src/main/kotlin/com/nylas/models/EvenVisibility.kt create mode 100644 src/main/kotlin/com/nylas/models/Event.kt create mode 100644 src/main/kotlin/com/nylas/models/FindEventQueryParams.kt create mode 100644 src/main/kotlin/com/nylas/models/Grant.kt create mode 100644 src/main/kotlin/com/nylas/models/HostedAuthRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/HostedAuthResponse.kt create mode 100644 src/main/kotlin/com/nylas/models/IQueryParams.kt create mode 100644 src/main/kotlin/com/nylas/models/ListCalendersQueryParams.kt create mode 100644 src/main/kotlin/com/nylas/models/ListEventQueryParams.kt create mode 100644 src/main/kotlin/com/nylas/models/ListGrantsQueryParams.kt create mode 100644 src/main/kotlin/com/nylas/models/ListResponse.kt create mode 100644 src/main/kotlin/com/nylas/models/NylasApiError.kt create mode 100644 src/main/kotlin/com/nylas/models/NylasApiErrorResponse.kt create mode 100644 src/main/kotlin/com/nylas/models/OpenIDResponse.kt create mode 100644 src/main/kotlin/com/nylas/models/PKCEAuthURL.kt create mode 100644 src/main/kotlin/com/nylas/models/Participant.kt create mode 100644 src/main/kotlin/com/nylas/models/ParticipantStatus.kt create mode 100644 src/main/kotlin/com/nylas/models/Platform.kt create mode 100644 src/main/kotlin/com/nylas/models/Provider.kt create mode 100644 src/main/kotlin/com/nylas/models/ProviderDetectParams.kt create mode 100644 src/main/kotlin/com/nylas/models/ProviderDetectResponse.kt create mode 100644 src/main/kotlin/com/nylas/models/Recurrence.kt create mode 100644 src/main/kotlin/com/nylas/models/RedirectUri.kt create mode 100644 src/main/kotlin/com/nylas/models/RedirectUriSettings.kt create mode 100644 src/main/kotlin/com/nylas/models/Region.kt create mode 100644 src/main/kotlin/com/nylas/models/ReminderMethod.kt create mode 100644 src/main/kotlin/com/nylas/models/Reminders.kt create mode 100644 src/main/kotlin/com/nylas/models/Response.kt create mode 100644 src/main/kotlin/com/nylas/models/TokenExchangeRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/UpdateCalendarRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/UpdateEventQueryParams.kt create mode 100644 src/main/kotlin/com/nylas/models/UpdateEventRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/UpdateGrantRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/UpdateRedirectUriRequest.kt create mode 100644 src/main/kotlin/com/nylas/models/UrlForAuthenticationConfig.kt create mode 100644 src/main/kotlin/com/nylas/models/When.kt create mode 100644 src/main/kotlin/com/nylas/models/WhenType.kt create mode 100644 src/main/kotlin/com/nylas/resources/Applications.kt create mode 100644 src/main/kotlin/com/nylas/resources/Auth.kt create mode 100644 src/main/kotlin/com/nylas/resources/Calendars.kt create mode 100644 src/main/kotlin/com/nylas/resources/Events.kt create mode 100644 src/main/kotlin/com/nylas/resources/Grants.kt create mode 100644 src/main/kotlin/com/nylas/resources/Providers.kt create mode 100644 src/main/kotlin/com/nylas/resources/RedirectUris.kt create mode 100644 src/main/kotlin/com/nylas/resources/Resource.kt create mode 100644 src/main/kotlin/com/nylas/util/ConferencingAdapter.kt create mode 100644 src/main/kotlin/com/nylas/util/CreateConferencingAdapter.kt create mode 100644 src/main/kotlin/com/nylas/util/CreateWhenAdapter.kt rename src/main/{java/com/nylas => kotlin/com/nylas/util}/Instants.java (93%) create mode 100644 src/main/kotlin/com/nylas/util/JsonHelper.kt rename src/main/{java/com/nylas => kotlin/com/nylas/util}/Maps.java (95%) create mode 100644 src/main/kotlin/com/nylas/util/UpdateConferencingAdapter.kt create mode 100644 src/main/kotlin/com/nylas/util/UpdateWhenAdapter.kt rename src/main/{java/com/nylas => kotlin/com/nylas/util}/Validations.java (97%) create mode 100644 src/main/resources/build.properties delete mode 100644 src/test/java/com/nylas/AccessTokenTest.java delete mode 100644 src/test/java/com/nylas/AccountDetailTest.java delete mode 100644 src/test/java/com/nylas/AccountOwnedModelTest.java delete mode 100644 src/test/java/com/nylas/AccountQueryTest.java delete mode 100644 src/test/java/com/nylas/AccountTest.java delete mode 100644 src/test/java/com/nylas/AccountsTest.java delete mode 100644 src/test/java/com/nylas/AuthenticationDAOTest.java delete mode 100644 src/test/java/com/nylas/AuthenticationTest.java delete mode 100644 src/test/java/com/nylas/AuthorizationCodeTest.java delete mode 100644 src/test/java/com/nylas/ByteChannelSource.java delete mode 100644 src/test/java/com/nylas/CalendarQueryTest.java delete mode 100644 src/test/java/com/nylas/CalendarTest.java delete mode 100644 src/test/java/com/nylas/CalendarsTest.java delete mode 100644 src/test/java/com/nylas/ContactGroupTest.java delete mode 100644 src/test/java/com/nylas/ContactGroupsTest.java delete mode 100644 src/test/java/com/nylas/ContactQueryTest.java delete mode 100644 src/test/java/com/nylas/ContactTest.java delete mode 100644 src/test/java/com/nylas/ContactsTest.java delete mode 100644 src/test/java/com/nylas/ContentHeadersInterceptorTest.java delete mode 100644 src/test/java/com/nylas/EventTest.java delete mode 100644 src/test/java/com/nylas/FieldReflectionUtils.java delete mode 100644 src/test/java/com/nylas/FreeBusyCalendarsTest.java delete mode 100644 src/test/java/com/nylas/FreeBusyQueryTest.java delete mode 100644 src/test/java/com/nylas/FreeBusyTest.java delete mode 100644 src/test/java/com/nylas/GrantQueryTest.java delete mode 100644 src/test/java/com/nylas/GrantTest.java delete mode 100644 src/test/java/com/nylas/GrantsTest.java delete mode 100644 src/test/java/com/nylas/HostedAuthenticationTest.java delete mode 100644 src/test/java/com/nylas/MessageObjectQueryTest.java delete mode 100644 src/test/java/com/nylas/MessageQueryTest.java delete mode 100644 src/test/java/com/nylas/MessageTest.java delete mode 100644 src/test/java/com/nylas/MessagesTest.java delete mode 100644 src/test/java/com/nylas/MockNylas.java delete mode 100644 src/test/java/com/nylas/NativeAuthenticationTest.java delete mode 100644 src/test/java/com/nylas/NylasAccountTest.java delete mode 100644 src/test/java/com/nylas/NylasApplicationTest.java delete mode 100644 src/test/java/com/nylas/NylasClientTest.java delete mode 100644 src/test/java/com/nylas/ProviderSettingsTest.java delete mode 100644 src/test/java/com/nylas/ScopeTest.java delete mode 100644 src/test/java/com/nylas/TestAuthEntity.java delete mode 100644 src/test/java/com/nylas/TestAuthRest.java delete mode 100644 src/test/java/com/nylas/TestClientResponse.java delete mode 100644 src/test/java/com/nylas/TestNotification.java delete mode 100644 src/test/java/com/nylas/ThreadQueryTest.java delete mode 100644 src/test/java/com/nylas/ThreadTest.java delete mode 100644 src/test/java/com/nylas/ThreadsTest.java delete mode 100644 src/test/java/com/nylas/TokenInfoTest.java delete mode 100644 src/test/resources/log4j2.xml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..28404d8b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*.{kt,kts}] +indent_size = 2 +indent_style = space +ktlint_standard_no-wildcard-imports = disabled diff --git a/build.gradle b/build.gradle deleted file mode 100644 index ef76220a..00000000 --- a/build.gradle +++ /dev/null @@ -1,211 +0,0 @@ -plugins { - id 'java-library' - id 'maven-publish' - id 'signing' - id 'eclipse' // necessary for workaround at bottom -} - -repositories { - jcenter() -} - -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -sourceSets { - examples { - compileClasspath += sourceSets.main.output - runtimeClasspath += sourceSets.main.output - } -} - -configurations { - examplesImplementation.extendsFrom implementation - examplesRuntimeOnly.extendsFrom runtimeOnly -} - -dependencies { - ////////////////////////////////// - // Public dependencies - - // OkHttp 3 - Http client (without Kotlin dependency of version 4) - api('com.squareup.okhttp3:okhttp:3.14.5') - - // Moshi JSON library - implementation('com.squareup.moshi:moshi:1.9.2') - implementation('com.squareup.moshi:moshi-adapters:1.9.2') - - // SLF4J for logging facade - implementation('org.slf4j:slf4j-api:1.7.30') - - // Websocket dependency - api('org.java-websocket:Java-WebSocket:1.5.3') - - /////////////////////////////////// - // Test dependencies - - // jUnit 5 for Testing - testImplementation('org.junit.jupiter:junit-jupiter-api:5.6.2') - testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.6.2') - - // use log4j logging for tests - testRuntimeOnly('org.apache.logging.log4j:log4j-slf4j-impl:2.17.0') - - // use wiremock for mocking the nylas server during tests - testImplementation('com.github.tomakehurst:wiremock-jre8:2.26.3') - - // mockito for dependency mocking - dependencies { - testImplementation "org.mockito:mockito-core:3.+" - testImplementation 'org.mockito:mockito-inline:2.13.0' - } - - - /////////////////////////////////// - // Examples dependencies - - // use log4j2 logging for examples - examplesImplementation('org.apache.logging.log4j:log4j-api:2.17.0') - examplesImplementation('org.apache.logging.log4j:log4j-core:2.17.0') - examplesImplementation('org.apache.logging.log4j:log4j-slf4j-impl:2.17.0') - - // Guava for examples since it makes all Java better and we don't need to worry about - // conflicting dependencies downstream for examples - examplesImplementation('com.google.guava:guava:28.2-jre') - - // jetty http server for examples that use callbacks - examplesImplementation('org.eclipse.jetty:jetty-server:9.4.28.v20200408') - examplesImplementation('org.eclipse.jetty:jetty-servlet:9.4.28.v20200408') - - // freemarker template library for serving basic html in some examples - examplesImplementation('org.freemarker:freemarker:2.3.29') - -} - -test { - useJUnitPlatform() - testLogging { - events "passed", "skipped", "failed", "standardError" - } - afterSuite { desc, result -> - if (!desc.parent) { // will match the outermost suite - def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)" - def startItem = '| ', endItem = ' |' - def repeatLength = startItem.length() + output.length() + endItem.length() - println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength)) - } - } -} - -task runExample(type: JavaExec) { - classpath = sourceSets.examples.runtimeClasspath - main = project.hasProperty("example") ? project.getProperty("example") : "com.nylas.examples.Examples" -} - -def getGitCommitHash = { -> - def buffer = new ByteArrayOutputStream() - exec { - commandLine 'git', 'rev-parse', 'HEAD' - standardOutput = buffer - } - return buffer.toString().trim() -} - -task createProperties(dependsOn: processResources) { - doLast { - mkdir "$buildDir/resources/main" - new File("$buildDir/resources/main/build.properties").withWriter { w -> - Properties p = new Properties() - p['version'] = project.version.toString() - p['commit.hash'] = getGitCommitHash() - p['build.timestamp'] = Instant.now().toString() - p.store w, null - } - } -} - -classes { - dependsOn createProperties -} - -task sourceJar(type: Jar) { - classifier "sources" - from sourceSets.main.allJava -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier "javadoc" - from javadoc.destinationDir -} - -javadoc.options.addStringOption('Xdoclint:none', '-quiet') - -artifacts { - archives jar - archives sourceJar - archives javadocJar -} - -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - artifact sourceJar - artifact javadocJar - pom { - name = "Nylas Java SDK" - description = "Java SDK for the Nylas Communication Platform" - url = "https://github.com/nylas/nylas-java" - licenses { - license { - name = "MIT" - url = "http://www.opensource.org/licenses/mit-license.php" - } - } - developers { - developer { - id = "ddlatham" - name = "David Latham" - organization = "Nylas" - organizationUrl = "https://www.nylas.com/" - } - developer { - id = "mrashed-dev" - name = "Mostafa Rashed" - organization = "Nylas" - organizationUrl = "https://www.nylas.com/" - } - } - scm { - url = "https://github.com/nylas/nylas-java" - connection = "scm:git:https://github.com/nylas/nylas-java.git" - developerConnection = "scm:git:https://github.com/nylas/nylas-java.git" - } - } - } - } - repositories { - maven { - def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2" - def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots" - url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl - credentials { - username = "$ossrhUser" - password = "$ossrhPassword" - } - } - } -} - -signing { - sign publishing.publications.mavenJava -} - -// workaround for https://github.com/eclipse/buildship/issues/476 -eclipse { - classpath { - plusConfigurations.add configurations.examplesCompileClasspath - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..245b4e29 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,51 @@ +plugins { + kotlin("jvm") version "1.8.21" + id("org.jmailen.kotlinter") version "3.15.0" + application +} + +repositories { + mavenCentral() +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +kotlin { + jvmToolchain(8) +} + +dependencies { + // //////////////////////////////// + // Public dependencies + + // OkHttp 3 - Http client (without Kotlin dependency of version 4) + api("com.squareup.okhttp3:okhttp:3.14.5") + + // Moshi JSON library + implementation("com.squareup.moshi:moshi:1.15.0") + implementation("com.squareup.moshi:moshi-kotlin:1.15.0") + implementation("com.squareup.moshi:moshi-adapters:1.15.0") + + // SLF4J for logging facade + implementation("org.slf4j:slf4j-api:2.0.7") +} + +tasks.processResources { + expand("artifact_version" to project.version) +} + +tasks.register("uberJar") { + archiveClassifier.set("uber") + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + + from(sourceSets.main.get().output) + + dependsOn(configurations.runtimeClasspath) + from({ + configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) } + }) +} diff --git a/gradle.properties b/gradle.properties index 2548e01a..022346cf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.nylas.sdk -version=1.22.0-SNAPSHOT +version=2.0.0-SNAPSHOT # Override and set these in ~/.gradle/gradle.properties ossrhUser= diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ffd05266c5e1ffaa4feb42a070f9e71f167c0d57..490fda8577df6c95960ba7077c43220e5bb2c0d9 100644 GIT binary patch delta 6577 zcmYkAbyQT*w}4>)kxq%Bq;V)oN$KwH&OxL>N(O`h=@=S@PU&u>rMpu?hY^qlLE`cJ zz4z9;=a2h+d+&43TKlg1&z>Ab8yZEc{UMINjGM#+LyC(+%rr=(NW-_lEoSW-(wspr z3j$S4KqlCkgo6}HF)VW2uhmXm48!Yd?}uF~9vEF)r)3Lf22{B3w1)T^R7{ld_|>My zSK!ye$152d5)jB8K(mh#&3(_#P+gO4_(ZaVT_noGR3Jf8=^HRq>+(-GySbp#C#%N5 zfi2H5upu{u+CZ!X2XozhEoYgmd#a+5fuz#SugmGEQLNOwSkJ#Tsy9&Y+GO3k1t0pc za<=`X+4T3{K8NLTb6vzJUX2q5OC20m7V9iq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kiY9qHP0Mi}fvGaaPqRU9=cLrvk{x+B593T63}8E6tli0sVjh)8<3 zqW0`)?;S2%+~IMXv4|r8$-E>!k*Xn6&IprT4g7%i{KNiVq#KWmrS}gG8dO!3mW;RP zwrlzH7ra{sS5|3wmMxFtm>2YCmwoW{3wAGm1^%p|S8K5krnl7h%`htLKBs1!zX&B6 z>qFtHAtnjL!}B)UGFpvC6i?pk#!26KS;Dp0x@u2L#k-az$YaARIP!!ARW#ft=#vARK+8+9%Eyqy6ke)+lo>(cda&2ddEPjQAu~KtA1lhG>&^$urn0{0tx8Cinv4aLyym*{5(O5Z=a;83 zOAodkRYr4R_sKp}3h=NkUqlhH=klmtvZ}t?BlVq6H8o9CH8d~Hb2E2jWpXy=tSl$F zW^)OCMt7C*dJ7nN$V)cpmPjD==Mx00nEKL)FVI2Tgjngs7HnehVr0x_uaWQuE|N(N zkV#lQZN;6>w~t%E-RT`zc$=N-y_R;X;rwVer}){s*%xZq=R8|sZhKS_D;sYf4>u#l zakGyp1Ps_%pazCv&jIu~e86Lo z68Qv(U(^I?x&iiXoWS!X4&-D&eCZ{q-wkl`pa4EE$$@k{{y{0=^A@>)wJrg|$bEvUxdczH$Oa`cDxkGt2|_OVXYc|l zMfgC+Iz9l}qy(Lm{F4{~p3?uWwf-l`l|M;A<+T5fbASS>{!s=1_a`4{zAIsf0kHaq zwg(f2cmSGzt&)!Z|G{Gdhd=E=D`UX*nB>1HaUfR#-?vmjph_F#>Z8hd>V=R G)AnDq{dIf* diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a4b44297..fae08049 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew.bat b/gradlew.bat index 24467a14..9109989e 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" diff --git a/settings.gradle b/settings.gradle.kts similarity index 90% rename from settings.gradle rename to settings.gradle.kts index 19da5241..6391e36c 100644 --- a/settings.gradle +++ b/settings.gradle.kts @@ -7,4 +7,4 @@ * in the user manual at https://docs.gradle.org/5.4/userguide/multi_project_builds.html */ -rootProject.name = 'nylas-java-sdk' +rootProject.name = "nylas-java-sdk" diff --git a/src/examples/java/com/nylas/examples/ExampleConf.java b/src/examples/java/com/nylas/examples/ExampleConf.java deleted file mode 100644 index 2f65771e..00000000 --- a/src/examples/java/com/nylas/examples/ExampleConf.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.nylas.examples; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import com.nylas.NameEmail; - -public class ExampleConf { - - private final Properties props = new Properties(); - - public ExampleConf() { - try (final InputStream in = ExampleConf.class.getResourceAsStream("/example.properties")) { - props.load(in); - } catch (IOException ioe) { - throw new RuntimeException("Failed to load example properties", ioe); - } - } - - /** - * Returns the configuration property for the given key - * - * @throws RuntimeException if no such property is found. - */ - public String get(String key) { - String value = getOrNull(key); - if (value == null) { - throw new RuntimeException("No example property found for key: " + key); - } - return value; - } - - /** - * Returns the configuration property for the given key or null if none is found. - */ - public String getOrNull(String key) { - return props.getProperty(key); - } - - /** - * Returns the configuration property for the given key or the given default value if none is found. - */ - public String get(String key, String defaultValue) { - return props.getProperty(key, defaultValue); - } - - public boolean contains(String key) { - return props.containsKey(key); - } - - public int getInt(String key, int defaultValue) { - String value = get(key); - if (value == null) { - return defaultValue; - } else { - return Integer.parseInt(value); - } - } - - public boolean getBoolean(String key, boolean defaultValue) { - String value = get(key); - if (value == null) { - return defaultValue; - } else { - return Boolean.parseBoolean(value); - } - } - - public NameEmail getNameEmail(String key) { - String name = get(key + ".name", ""); - String email = get(key + ".email", null); - return email == null ? null : new NameEmail(name, email); - } - - public List getNameEmailList(String key) { - NameEmail nameEmail = getNameEmail(key); - return nameEmail == null ? Collections.emptyList() : Arrays.asList(nameEmail); - } - - /** - * Return a map derived from all properties that start with a given prefix. - * The returned map has keys stripped of the prefix. - *

- * For example, if these are properties: - *

-	 * menu.open.color=blue
-	 * menu.open.size=10
-	 * menu.close.color=red
-	 * menu.close.size=5
-	 * 
- * then calling getPrefixedEntries("menu.open.") will return a map with these entries: - *
-	 * color=blue
-	 * size=10
-	 * 
- */ - public Map getPrefixedEntries(String prefix) { - int prefixLength = prefix.length(); - Map entries = new HashMap<>(); - for (String key : props.stringPropertyNames()) { - if (key.startsWith(prefix)) { - entries.put(key.substring(prefixLength), props.getProperty(key)); - } - } - return entries; - } -} diff --git a/src/examples/java/com/nylas/examples/Readme.md b/src/examples/java/com/nylas/examples/Readme.md deleted file mode 100644 index 5eeac162..00000000 --- a/src/examples/java/com/nylas/examples/Readme.md +++ /dev/null @@ -1,25 +0,0 @@ -# Nylas Java SDK Examples -The subdirectories found here contain example code that demonstrate how to use the Nylas Java SDK to take advantage of the features of the Nylas Communications Platform. If you're new here, please take a look at our [Java SDK quickstart guide](https://docs.nylas.com/docs/quickstart-java), it's the best resource to learn how to get up and running. - -These are the examples you will find here: - -* [Hosted Authentication](./hostedAuth) - Learn how to connect user accounts to Nylas via Hosted Authentication. This is the quickest and easiest way to authenticate user accounts. -* [Native Authentication](./nativeAuth) - Learn how to connect user accounts to Nylas via Native Authentication. This is for developers who want to whitelabel the login experience. -* [Webhooks](./webhooks) - Need to receive information about changes to email, calendars, or contacts? This example demonstrates how to receive webhook notifications from Nylas -* [Other Examples](./other) - Basic examples that demonstrate the Nylas Email, Calendar, and Contacts API endpoints. Take a look at our [Java SDK quickstart guide](https://docs.nylas.com/docs/quickstart-java) to learn more. - -## How to Run the Examples -Clone this repo to your machine - -`git clone https://github.com/nylas/nylas-java.git && cd nylas-java` - -Create an example.properties file from the [provided template](https://github.com/nylas/nylas-java/blob/master/src/examples/resources/example.properties.template), and modify the file to include the values you need for the examples you want to run. At the very least, you need to set `nylas.client.id` and `nylas.client.secret` to match your Nylas App. - -`cp src/examples/resources/example.properties.template src/examples/resources/example.properties` - - -Here is an example of how to run the Hosted Authentication example: - -`./gradlew runExample -Pexample=com.nylas.examples.hostedAuth.HostedAuthUrlExample` - -Replace `hostedAuth.HostedAuthUrlExample` with any of the examples found in the subdirectories here. \ No newline at end of file diff --git a/src/examples/java/com/nylas/examples/hostedAuth/HostedAuthFetchTokenExample.java b/src/examples/java/com/nylas/examples/hostedAuth/HostedAuthFetchTokenExample.java deleted file mode 100644 index 3b1336b0..00000000 --- a/src/examples/java/com/nylas/examples/hostedAuth/HostedAuthFetchTokenExample.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.nylas.examples.hostedAuth; - -import com.nylas.HostedAuthentication; -import com.nylas.NylasApplication; -import com.nylas.NylasClient; -import com.nylas.examples.ExampleConf; - -public class HostedAuthFetchTokenExample { - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasApplication application = client.application(conf.get("nylas.client.id"), conf.get("nylas.client.secret")); - HostedAuthentication authentication = application.hostedAuthentication(); - - String authorizationCode = conf.get("hosted.auth.code"); - System.out.println("Exchanging authorication code for long lived access token."); - String token = authentication.fetchToken(authorizationCode).getAccessToken(); - System.out.println("Authentication successful. Here is your access token:"); - System.out.println(token); - System.out.println("If you wish to use this for further examples, add it to your example.properties file"); - } - -} diff --git a/src/examples/java/com/nylas/examples/hostedAuth/HostedAuthUrlExample.java b/src/examples/java/com/nylas/examples/hostedAuth/HostedAuthUrlExample.java deleted file mode 100644 index a26a2855..00000000 --- a/src/examples/java/com/nylas/examples/hostedAuth/HostedAuthUrlExample.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.nylas.examples.hostedAuth; - -import com.nylas.HostedAuthentication; -import com.nylas.NylasApplication; -import com.nylas.NylasClient; -import com.nylas.Scope; -import com.nylas.examples.ExampleConf; - -public class HostedAuthUrlExample { - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasApplication application = client.application(conf.get("nylas.client.id"), conf.get("nylas.client.secret")); - HostedAuthentication authentication = application.hostedAuthentication(); - String hostedAuthUrl = authentication.urlBuilder() - .redirectUri("https://example.com/nylas-redirect") - .responseType("code") - .scopes(Scope.values()) - .loginHint(conf.get("hosted.login.hint")) - .state("example_csrf_token") - .forcePassword(true) - .buildUrl(); - - System.out.println("Forward the user to this URL for hosted authentication:"); - System.out.println(hostedAuthUrl); - System.out.println(); - - System.out.println("If the user authenticates and grants permission for Nylas to access their account,"); - System.out.println("then grab the authorication code included when the user is redirected to your server."); - System.out.println("Enter it in example.properties to use it for the fetch token example"); - - } - -} diff --git a/src/examples/java/com/nylas/examples/nativeAuth/HtmlTemplateResponder.java b/src/examples/java/com/nylas/examples/nativeAuth/HtmlTemplateResponder.java deleted file mode 100644 index 14f11b6d..00000000 --- a/src/examples/java/com/nylas/examples/nativeAuth/HtmlTemplateResponder.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.nylas.examples.nativeAuth; - -import java.io.IOException; - -import javax.servlet.http.HttpServletResponse; - -import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateException; -import freemarker.template.TemplateExceptionHandler; - -public class HtmlTemplateResponder { - - private final Configuration cfg; - - public HtmlTemplateResponder(String path) { - cfg = new Configuration(Configuration.VERSION_2_3_29); - cfg.setClassForTemplateLoading(HtmlTemplateResponder.class, path); - cfg.setDefaultEncoding("UTF-8"); - cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); - cfg.setFallbackOnNullLoopVariable(false); - } - - public void respond(String templateName, Object dataModel, HttpServletResponse response) throws IOException { - try { - Template template = cfg.getTemplate(templateName); - response.setStatus(HttpServletResponse.SC_OK); - response.setContentType("text/html"); - response.setCharacterEncoding("utf-8"); - template.process(dataModel, response.getWriter()); - } catch (TemplateException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/src/examples/java/com/nylas/examples/nativeAuth/NativeAuthGoogleExample.java b/src/examples/java/com/nylas/examples/nativeAuth/NativeAuthGoogleExample.java deleted file mode 100644 index dadc6b13..00000000 --- a/src/examples/java/com/nylas/examples/nativeAuth/NativeAuthGoogleExample.java +++ /dev/null @@ -1,299 +0,0 @@ -package com.nylas.examples.nativeAuth; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.servlet.ServletHandler; - -import com.google.common.collect.ImmutableMap; -import com.nylas.AccessToken; -import com.nylas.AccountDetail; -import com.nylas.GoogleProviderSettings; -import com.nylas.JsonHelper; -import com.nylas.NativeAuthentication; -import com.nylas.NativeAuthentication.AuthRequestBuilder; -import com.nylas.NylasAccount; -import com.nylas.NylasApplication; -import com.nylas.NylasClient; -import com.nylas.ProviderSettings; -import com.nylas.RequestFailedException; -import com.nylas.Scope; -import com.nylas.examples.ExampleConf; - -import okhttp3.FormBody; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -public class NativeAuthGoogleExample { - - private static final Logger log = LogManager.getLogger(NativeAuthGoogleExample.class); - - private static final String AUTHORIZED_PATH = "/login/google/authorized"; - private static final String AUTHORIZE_NYLAS_PATH = "/authorize_nylas"; - private static final String EXAMPLE_CSRF_TOKEN = "UNGUESSABLE_CSRF_TOKEN"; - - private static ExampleConf conf = new ExampleConf(); - private static HtmlTemplateResponder responder = new HtmlTemplateResponder("/html-templates/native-auth-google"); - private static OkHttpClient httpClient = new OkHttpClient(); - private static NylasClient nylasClient = new NylasClient(); - private static String baseUrl; - private static Set scopes = new HashSet() {{ - addAll(Arrays.asList(Scope.values())); - remove(Scope.EMAIL_METADATA); - }}; - - public static void main(String[] args) throws Exception { - int port = conf.getInt("http.local.port", 5000); - log.info("Starting http server listening on port {}", port); - Server server = new Server(port); - ServletHandler handler = new ServletHandler(); - handler.addServletWithMapping(StartServlet.class, ""); - handler.addServletWithMapping(AuthorizedServlet.class, AUTHORIZED_PATH); - handler.addServletWithMapping(AuthorizeNylasServlet.class, AUTHORIZE_NYLAS_PATH); - server.setHandler(handler); - server.start(); - - baseUrl = findBaseUrl(conf, port); - log.info("Using OAuth redirect URI of \"{}\"", getOAuthRedirectUri()); - log.info("Be sure that this is registered as an Authorized redirect URI " - + "for your OAuth Client in the Credentials section of the Google developer console."); - - log.info("Visit to {} to view this example", baseUrl); - } - - private static String getOAuthRedirectUri() { - return baseUrl + AUTHORIZED_PATH; - } - - public static class StartServlet extends HttpServlet { - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - Set googleScopes = GoogleProviderSettings.getMatchingGoogleScopes(scopes); - // userinfo.email is required for google userinfo endpoint to return email attribute - // Nylas also appears to require this when it fetches tokeninfo - googleScopes.add("https://www.googleapis.com/auth/userinfo.email"); - // userinfo.profile is required for google userinfo endpoint to return name attribute - // this makes the example nicer in fetching the user name from Google and using it with Nylas, but is not - // required by Nylas if you have the user name from somewhere else. - googleScopes.add("https://www.googleapis.com/auth/userinfo.profile"); - - HttpUrl url = HttpUrl.get("https://accounts.google.com/o/oauth2/v2/auth").newBuilder() - .addQueryParameter("client_id", getGoogleClientId()) - .addQueryParameter("redirect_uri", getOAuthRedirectUri()) - .addQueryParameter("response_type", "code") - .addQueryParameter("scope", String.join(" ", googleScopes)) - .addQueryParameter("access_type", "offline") - // A user prompt is required for Google to grant the refresh_token in addition to the access_token. - // Google may skip the prompt if the user has previously granted these scopes to this client. - // Adding this parameter prompt=consent ensures that the prompt is never skipped. - .addQueryParameter("prompt", "consent") - // in a real system, the state parameter should be a unguessable function of the user account - // or session to prevent CSRF attacks - .addQueryParameter("state", EXAMPLE_CSRF_TOKEN) - .build(); - - Map dataModel = ImmutableMap.of("googleAuthUrl", url.toString()); - - responder.respond("step1.ftlh", dataModel, response); - } - } - - public static class AuthorizedServlet extends HttpServlet { - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - String code = request.getParameter("code"); - String state = request.getParameter("state"); - - // in a real system, verify that the returned state matches the expected function of the current user - // account/session. this prevents a CSRF attack where an attacker can associate the wrong google account - // to this customer's user account. - if (!EXAMPLE_CSRF_TOKEN.equals(state)) { - log.error("Unexpected or missing OAuth state parameter in response: " + state); - return; - } - - HttpUrl tokenUrl = HttpUrl.get("https://oauth2.googleapis.com/token"); - FormBody params = new FormBody.Builder() - .add("client_id", getGoogleClientId()) - .add("client_secret", getGoogleClientSecret()) - .add("redirect_uri", getOAuthRedirectUri()) - .add("grant_type", "authorization_code") - .add("code", code) - .build(); - - Request tokenRequest = new Request.Builder().url(tokenUrl).post(params).build(); - Map tokenData = executeRequestForJson(tokenRequest); - String googleRefreshToken = (String) tokenData.get("refresh_token"); - String googleAccessToken = (String) tokenData.get("access_token"); - - HttpUrl userInfoUrl = HttpUrl.get("https://www.googleapis.com/oauth2/v3/userinfo").newBuilder() - .addQueryParameter("access_token", googleAccessToken) - .build(); - Map userInfoData = executeRequestForJson(new Request.Builder().url(userInfoUrl).build()); - String name = (String) userInfoData.get("name"); - String email = (String) userInfoData.get("email"); - - HttpUrl authorizeNylasUrl = HttpUrl.get(baseUrl + AUTHORIZE_NYLAS_PATH).newBuilder() - .addQueryParameter("google_refresh_token", googleRefreshToken) - .addQueryParameter("name", name) - .addQueryParameter("email", email) - .build(); - - Map dataModel = ImmutableMap.of( - "googleAccessToken", googleAccessToken, - "googleRefreshToken", googleRefreshToken, - "name", name, - "email", email, - "authNylasUrl", authorizeNylasUrl.toString()); - responder.respond("step2.ftlh", dataModel, response); - } - } - - private static Map executeRequestForJson(Request request) throws IOException { - try (Response response = httpClient.newCall(request).execute()) { - if (!response.isSuccessful()) { - throw new IOException("Unexpected response " + response); - } - - return JsonHelper.jsonToMap(response.body().string()); - } - } - - public static class AuthorizeNylasServlet extends HttpServlet { - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - - String googleRefreshToken = request.getParameter("google_refresh_token"); - String name = request.getParameter("name"); - String email = request.getParameter("email"); - - NylasApplication application = nylasClient.application( - conf.get("nylas.client.id"), - conf.get("nylas.client.secret")); - NativeAuthentication authentication = application.nativeAuthentication(); - - ProviderSettings settings = ProviderSettings.google() - .googleClientId(getGoogleClientId()) - .googleClientSecret(getGoogleClientSecret()) - .googleRefreshToken(googleRefreshToken); - - AuthRequestBuilder authRequest = authentication.authRequest() - .name(name) - .emailAddress(email) - .providerSettings(settings) - .scopes(scopes) - ; - - try { - log.info("Making a native authentication request for a Google account."); - String nylasAuthorizationCode = authRequest.execute(); - log.info("Succeeded. Returned authorization code: " + nylasAuthorizationCode); - - log.info("Using authorization code to request long lived access token."); - AccessToken nylasAccessToken = authentication.fetchToken(nylasAuthorizationCode); - log.info("Succeeded. Returned token: " + nylasAccessToken); - - log.info("Requesting account details with token."); - NylasAccount account = nylasClient.account(nylasAccessToken.getAccessToken()); - AccountDetail accountDetail = account.fetchAccountByAccessToken(); - log.info("Succeeded. Account detail: " + accountDetail); - - responder.respond("step3.ftlh", ImmutableMap.of("accountDetail", accountDetail), response); - } catch (RequestFailedException e) { - throw new IOException (e); - } - } - } - - static class Tunnel { String proto; String public_url; } - static class Tunnels { List tunnels; } - private static String findBaseUrl(ExampleConf conf, int port) { - // FIRST check for configuration - String baseUrl = conf.get("http.base.url", null); - if (baseUrl != null) { - log.info("Found base url in example.properties: {}", baseUrl); - return baseUrl; - } else { - log.info("No base url found in example.properties, checking to see if ngrok is running..."); - } - - // SECOND see if ngrok is running - Request request = new Request.Builder().url("http://localhost:4040/api/tunnels").build(); - try (Response response = httpClient.newCall(request).execute()) { - Tunnels tunnels = JsonHelper.adapter(Tunnels.class).fromJson(response.body().source()); - for (Tunnel t : tunnels.tunnels) { - if ("https".equals(t.proto)) { - baseUrl = t.public_url; - log.info("Found https base url from ngrok: {}", baseUrl); - return baseUrl; - } - } - log.debug("No https tunnel found in ngrok response"); - } catch (Exception e) { - log.debug("Failed to find https tunnel from local ngrok, exception: {}", e.getMessage()); - } - - // THIRD fall back to localhost - baseUrl = "http://localhost:" + port; - log.info("Falling back to using localhost base url: {}", baseUrl); - return baseUrl; - } - - private static String getGoogleClientId() { - return conf.get("google.client.id"); - } - - private static String getGoogleClientSecret() { - return conf.get("google.client.secret"); - } - - /** - * Debugging method for getting a google access token from a refresh token - */ - static void getAccessTokenFromRefreshToken(String refreshToken) - throws IOException { - HttpUrl url = HttpUrl.get("https://www.googleapis.com/oauth2/v4/token"); - - FormBody params = new FormBody.Builder() - .add("client_id", getGoogleClientId()) - .add("client_secret", getGoogleClientSecret()) - .add("refresh_token", refreshToken) - .add("grant_type", "refresh_token") - .build(); - - Request request = new Request.Builder().url(url) - .post(params) - .build(); - - Map accessTokenData = executeRequestForJson(request); - System.out.println(accessTokenData); - } - - /** - * Debugging method for getting token info from google about an access token - */ - static void getTokenInfo(String accessToken) throws IOException { - HttpUrl url = HttpUrl.get("https://www.googleapis.com/oauth2/v3/tokeninfo").newBuilder() - .addQueryParameter("access_token", accessToken) - .build(); - - Request request = new Request.Builder().url(url).build(); - - Map tokenInfoData = executeRequestForJson(request); - System.out.println(tokenInfoData); - } - -} diff --git a/src/examples/java/com/nylas/examples/nativeAuth/NativeAuthPasswordExample.java b/src/examples/java/com/nylas/examples/nativeAuth/NativeAuthPasswordExample.java deleted file mode 100644 index 3c18668c..00000000 --- a/src/examples/java/com/nylas/examples/nativeAuth/NativeAuthPasswordExample.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.nylas.examples.nativeAuth; - -import java.io.IOException; -import java.util.Map; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.nylas.AccessToken; -import com.nylas.AccountDetail; -import com.nylas.ImapProviderSettings; -import com.nylas.NativeAuthentication; -import com.nylas.NativeAuthentication.AuthRequestBuilder; -import com.nylas.examples.ExampleConf; -import com.nylas.NylasAccount; -import com.nylas.NylasApplication; -import com.nylas.NylasClient; -import com.nylas.ProviderSettings; -import com.nylas.RequestFailedException; -import com.nylas.Scope; - -public class NativeAuthPasswordExample { - - private static final Logger log = LogManager.getLogger(NativeAuthPasswordExample.class); - - public static void main(String[] args) throws IOException, RequestFailedException { - ExampleConf conf = new ExampleConf(); - - String provider = conf.get("native.auth.provider"); - Map providerConf = conf.getPrefixedEntries("native.auth." + provider + "."); - - String name = providerConf.get("name"); - String email = providerConf.get("email"); - String password = providerConf.get("password"); - ProviderSettings settings; - switch(provider) { - case "aol": - case "hotmail": - case "icloud": - case "outlook": - case "yahoo": - settings = knownImap(provider, email, password); - break; - case "exchange": - settings = exchange(providerConf, password, email); - break; - case "imap": - settings = imap(providerConf); - break; - case "gmail": - case "google": - case "office365": - throw new RuntimeException("This example does not support OAuth flows"); - default: - throw new RuntimeException("Unsupported native.auth.provider: " + provider); - } - - nativeAuth(conf, name, email, settings); - } - - public static ProviderSettings exchange(Map conf, String email, String password) - throws IOException, RequestFailedException { - return ProviderSettings.exchange() - .username(email) - .password(password) - .exchangeServerHost(conf.get("native.auth.exchange.server")) - ; - } - - public static ProviderSettings imap(Map conf) - throws IOException, RequestFailedException { - ImapProviderSettings settings = ProviderSettings.imap() - .imapHost(conf.get("host")) - .imapUsername(conf.get("username")) - .imapPassword(conf.get("password")) - .smtpHost(conf.get("smtp.host")) - .smtpUsername(conf.get("smtp.username")) - .smtpPassword(conf.get("smtp.password")) - .sslRequired(true) - ; - if (conf.containsKey("port")) { - settings.imapPort(Integer.parseInt(conf.get("port"))); - } - if (conf.containsKey("smtp.port")) { - settings.smtpPort(Integer.parseInt(conf.get("smtp.port"))); - } - if (conf.containsKey("ssl.required")) { - settings.sslRequired(Boolean.parseBoolean(conf.get("ssl.required"))); - } - return settings; - } - - public static ProviderSettings knownImap(String provider, String email, String password) - throws IOException, RequestFailedException { - return ProviderSettings.knownImap(provider) - .username(email) - .password(password) - ; - } - - public static void nativeAuth(ExampleConf conf, String name, String email, ProviderSettings provider) - throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasApplication application = client.application(conf.get("nylas.client.id"), conf.get("nylas.client.secret")); - NativeAuthentication authentication = application.nativeAuthentication(); - AuthRequestBuilder authRequest = authentication.authRequest() - .name(name) - .emailAddress(email) - .providerSettings(provider) - .scopes(Scope.values()); - - log.info("Making a native authentication request for " + email); - String authorizationCode = authRequest.execute(); - log.info("Succeeded. Returned authorization code: " + authorizationCode); - - log.info("Using authorization code to request long lived access token."); - AccessToken token = authentication.fetchToken(authorizationCode); - log.info("Succeeded. Returned token: " + token); - - log.info("Requesting account details with token."); - NylasAccount account = client.account(token.getAccessToken()); - AccountDetail accountDetail = account.fetchAccountByAccessToken(); - log.info("Succeeded. Account details: " + accountDetail); - } - -} diff --git a/src/examples/java/com/nylas/examples/other/AccountDetailExample.java b/src/examples/java/com/nylas/examples/other/AccountDetailExample.java deleted file mode 100644 index 217f8dad..00000000 --- a/src/examples/java/com/nylas/examples/other/AccountDetailExample.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nylas.examples.other; - -import com.nylas.AccountDetail; -import com.nylas.NylasAccount; -import com.nylas.NylasClient; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class AccountDetailExample { - - private static final Logger log = LogManager.getLogger(AccountDetailExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(conf.get("access.token")); - AccountDetail detail = account.fetchAccountByAccessToken(); - log.info(detail); - } - -} diff --git a/src/examples/java/com/nylas/examples/other/AccountsExample.java b/src/examples/java/com/nylas/examples/other/AccountsExample.java deleted file mode 100644 index 1ec6103d..00000000 --- a/src/examples/java/com/nylas/examples/other/AccountsExample.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.nylas.examples.other; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.nylas.*; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class AccountsExample { - - private static final Logger log = LogManager.getLogger(AccountsExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasApplication application = client.application(conf.get("nylas.client.id"), conf.get("nylas.client.secret")); - Accounts accounts = application.accounts(); - AccountQuery query = new AccountQuery() - .limit(2) - //.offset(10) - ; - List accountList = accounts.list(query).fetchAll(); - for (Account account : accountList) { - log.info(account); - } - - Account first = accounts.get(accountList.get(0).getId()); - log.info("first: " + first); - - String accessToken = conf.get("access.token"); - TokenInfo tokenInfo = accounts.tokenInfo(first.getId(), accessToken); - log.info("token info: " + tokenInfo); - - accounts.downgrade(first.getId()); - first = accounts.get(accountList.get(0).getId()); - log.info("after downgrade: " + first); - - accounts.upgrade(first.getId()); - first = accounts.get(accountList.get(0).getId()); - log.info("after upgrade: " + first); - - Map metadata = new HashMap<>(); - metadata.put("account_type", "test"); - accounts.setMetadata(accountList.get(0).getId(), metadata); - - MetadataQuery metadataQuery = new MetadataQuery().metadataKey("account_type"); - AccountQuery accountQuery = new AccountQuery().metadataQuery(metadataQuery); - List accountsWithMetadata = accounts.list(accountQuery).fetchAll(); - for (Account account : accountsWithMetadata) { - log.info("found account with 'account_type' metadata: " + account); - } - - //accounts.delete(first.getId()); - //accounts.revokeAllTokensForAccount(first.getId(), "blahblah"); - } - -} diff --git a/src/examples/java/com/nylas/examples/other/ApplicationDetailExample.java b/src/examples/java/com/nylas/examples/other/ApplicationDetailExample.java deleted file mode 100644 index 9d9a1638..00000000 --- a/src/examples/java/com/nylas/examples/other/ApplicationDetailExample.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.nylas.examples.other; - -import com.nylas.ApplicationDetail; -import com.nylas.NylasApplication; -import com.nylas.NylasClient; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class ApplicationDetailExample { - - private static final Logger log = LogManager.getLogger(ApplicationDetailExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasApplication application = client.application(conf.get("nylas.client.id"), conf.get("nylas.client.secret")); - ApplicationDetail detail = application.getApplicationDetail(); - log.info("existing application details: " + detail); - - detail = application.addRedirectUri("https://example.com/bogus_redirect"); - log.info("added new uri: " + detail); - - detail = application.addRedirectUri("https://example.com/bogus_redirect"); - log.info("skipped adding new uri again: " + detail); - - detail = application.removeRedirectUri("https://example.com/bogus_redirect"); - log.info("removed uri: " + detail); - - } - -} diff --git a/src/examples/java/com/nylas/examples/other/AuthenticationExample.java b/src/examples/java/com/nylas/examples/other/AuthenticationExample.java deleted file mode 100644 index 10844fec..00000000 --- a/src/examples/java/com/nylas/examples/other/AuthenticationExample.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.nylas.examples.other; - -import com.nylas.*; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; - -public class AuthenticationExample { - - private static final Logger log = LogManager.getLogger(AuthenticationExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasApplication application = client.application(conf.get("nylas.client.id"), conf.get("nylas.client.secret")); - Integrations integrations = application.authentication().integrations(); - - log.info("Creating a new Zoom integration"); - Integration integration = new Integration("Test Zoom Integration"); - integration.setClientId(conf.get("zoom.client.id")); - integration.setClientSecret(conf.get("zoom.client.secret")); - integration.addRedirectUris("https://www.nylas.com"); - integration.setExpiresIn(1209600L); - Integration created = integrations.create(integration, Authentication.Provider.ZOOM); - log.info("Created: " + created); - - log.info("Listing all integrations:"); - RemoteCollection allIntegrations = integrations.list(); - for(Integration currentIntegration : allIntegrations) { - log.info("Integration: " + currentIntegration); - } - - log.info("Updating the integration"); - created.setName("Updated Test Zoom Integration"); - created.setClientId(conf.get("zoom.client.id")); - created.setClientSecret(conf.get("zoom.client.secret")); - Integration update = integrations.update(created); - log.info("Updated: " + update); - - grantsExample(conf, application); - hostedAuthenticationExample(conf, application); - - log.info("Deleting integration"); - integrations.delete(Authentication.Provider.ZOOM); - } - - private static void grantsExample(ExampleConf conf, NylasApplication application) - throws RequestFailedException, IOException { - Grants grants = application.authentication().grants(); - - log.info("Creating a new Zoom grant"); - Map settings = Collections.singletonMap("refresh_token", conf.get("zoom.client.refresh_token")); - Grant grant = new Grant(Authentication.Provider.ZOOM, settings); - Grant created = grants.create(grant); - log.info("Created: " + created); - - log.info("Listing all grants:"); - RemoteCollection allGrants = grants.list(); - for(Grant currentGrant : allGrants) { - log.info("Grant: " + currentGrant); - } - - log.info("Deleting grant"); - grants.delete(created.getId()); - } - - private static void hostedAuthenticationExample(ExampleConf conf, NylasApplication application) - throws RequestFailedException, IOException { - log.info("Making a Hosted Authentication request"); - - IntegrationHostedAuthentication hostedAuthentication = application.authentication().hostedAuthentication(); - IntegrationHostedAuthentication.RequestBuilder builder = hostedAuthentication.requestBuilder() - .provider(Authentication.Provider.ZOOM) - .redirectUri("https://www.nylas.com") - .settings(Collections.singletonMap("refresh_token", conf.get("zoom.client.refresh_token"))) - .scope(Collections.singletonList("meeting:write")) - .metadata(Collections.singletonMap("SDK Test", "Java SDK")) - .loginHint("example@mail.com") - .state("my-state") - .expiresIn(43200L); - - LoginInfo loginInfo = hostedAuthentication.request(builder); - - log.info("Login Information: " + loginInfo); - } -} diff --git a/src/examples/java/com/nylas/examples/other/CalendarsExample.java b/src/examples/java/com/nylas/examples/other/CalendarsExample.java deleted file mode 100644 index e50f5adb..00000000 --- a/src/examples/java/com/nylas/examples/other/CalendarsExample.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.nylas.examples.other; - -import java.io.IOException; -import java.time.Instant; -import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; -import java.util.HashMap; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import com.nylas.*; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class CalendarsExample { - - private static final Logger log = LogManager.getLogger(CalendarsExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(conf.get("access.token")); - Calendars calendars = account.calendars(); - String calendarEmail = null; - String accountId = null; - String calendarId = null; - for (Calendar calendar : calendars.list()) { - log.info(calendar); - if (calendar.getName().contains("@")) { - calendarEmail = calendar.getName(); - accountId = calendar.getAccountId(); - calendarId = calendar.getId(); - } - } - if (calendarEmail == null) { - log.info("No calendar found with a name that looks like an email"); - } else { - log.info("Checking Free/Busy for the next 30 days"); - checkFreeBusy(calendars, calendarEmail); - - log.info("Checking availability for the next hour"); - availability(calendars, accountId, calendarId, calendarEmail); - } - - log.info("Creating a new calendar"); - createCalendar(account); - } - - protected static void checkFreeBusy(Calendars calendars, String email) throws RequestFailedException, IOException { - Instant end = ZonedDateTime.now().toInstant(); - Instant start = end.minus(30, ChronoUnit.DAYS); - FreeBusyQuery query = new FreeBusyQuery() - .startTime(start.getEpochSecond()) - .endTime(end.getEpochSecond()) - .emails(email); - List freeBusyInfo = calendars.checkFreeBusy(query); - for (FreeBusy freeBusy : freeBusyInfo) { - log.info(freeBusy); - } - } - - protected static void availability(Calendars calendars, String accountId, String calendarId, String email) - throws RequestFailedException, IOException { - FreeBusyCalendars freeBusyCalendars = new FreeBusyCalendars(accountId, Collections.singletonList(calendarId)); - SingleAvailabilityQuery query = new SingleAvailabilityQuery() - .durationMinutes(30) - .startTime(Instant.now()) - .endTime(Instant.now().plus(1, ChronoUnit.HOURS)) - .intervalMinutes(10) - .calendars(freeBusyCalendars); - - Availability availability = calendars.availability(query); - log.info(availability.toString()); - - MultipleAvailabilityQuery consecutiveQuery = new MultipleAvailabilityQuery() - .durationMinutes(30) - .startTime(Instant.now()) - .endTime(Instant.now().plus(1, ChronoUnit.HOURS)) - .intervalMinutes(10) - .emails(Collections.singletonList(Collections.singletonList(email))); - - List> consecutiveAvailability = calendars.consecutiveAvailability(consecutiveQuery); - log.info(consecutiveAvailability.toString()); - } - - protected static void createCalendar(NylasAccount account) throws RequestFailedException, IOException { - Calendars calendars = account.calendars(); - Calendar newCal = new Calendar(); - newCal.setName("New Test Calendar"); - newCal.setDescription("Testing calendar creation"); - newCal.setLocation("far, far away"); - newCal.setTimezone("America/Los_Angeles"); - Calendar created = calendars.create(newCal); - log.info("Created: " + created + " status: " + created.getJobStatusId()); - - created.setName("New Test Calendar (changed)"); - created.setDescription("this calendar has been updated!"); - created.setLocation("nearby"); - created.setTimezone("America/New_York"); - Map metadata = new HashMap<>(); - metadata.put("calendar_type", "test"); - created.setMetadata(metadata); - Calendar updated = calendars.update(created); - log.info("Updated: " + updated + " status: " + updated.getJobStatusId()); - - String deleteJobStatusId = calendars.delete(updated.getId()); - log.info("Deleted, deleted job status id: " + deleteJobStatusId); - - JobStatus deleteStatus = account.jobStatuses().get(deleteJobStatusId); - log.info("Deletion status: " + deleteStatus); - } -} diff --git a/src/examples/java/com/nylas/examples/other/ComponentsExample.java b/src/examples/java/com/nylas/examples/other/ComponentsExample.java deleted file mode 100644 index 3cd23cd2..00000000 --- a/src/examples/java/com/nylas/examples/other/ComponentsExample.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.nylas.examples.other; - -import com.nylas.*; -import com.nylas.examples.ExampleConf; - -public class ComponentsExample { - - public static void main(String[] args) throws Exception { - - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasApplication application = client.application(conf.get("nylas.client.id"), conf.get("nylas.client.secret")); - Components components = application.components(); - - Component component = new Component(); - component.setName("Java Component Test"); - component.setType("agenda"); - component.setPublicAccountId("ACCOUNT_ID"); - component.setAccessToken(conf.get("access.token")); - component = components.save(component); - - RemoteCollection componentList = components.list(); - for(Component comp : componentList) { - System.out.println(comp); - } - - Component fetchedComponent = components.get(component.getId()); - fetchedComponent.setName("Updated component name"); - fetchedComponent.addAllowedDomains("www.nylas.com"); - fetchedComponent.addSetting("Test", "yes"); - components.save(fetchedComponent); - - components.delete(fetchedComponent.getId()); - } -} diff --git a/src/examples/java/com/nylas/examples/other/ContactsExample.java b/src/examples/java/com/nylas/examples/other/ContactsExample.java deleted file mode 100644 index 1347fa40..00000000 --- a/src/examples/java/com/nylas/examples/other/ContactsExample.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.nylas.examples.other; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.Arrays; - -import com.nylas.Contact; -import com.nylas.ContactGroup; -import com.nylas.ContactGroups; -import com.nylas.ContactQuery; -import com.nylas.Contacts; -import com.nylas.NylasAccount; -import com.nylas.NylasClient; -import com.nylas.examples.ExampleConf; - -import okhttp3.ResponseBody; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class ContactsExample { - - private static final Logger log = LogManager.getLogger(ContactsExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(conf.get("access.token")); - Contacts contacts = account.contacts(); - - ContactQuery query = new ContactQuery() - .source("address_book") - .limit(10) - ; - Contact hasProfilePicture = null; - for (Contact c : contacts.list(query)) { - if (c.getPictureUrl() != null) { - hasProfilePicture = c; - } - log.info(c); - } - - if (hasProfilePicture == null) { - log.info("No contact has a profile pic"); - } else { - Path profilePicPath = Paths.get(System.getProperty("java.io.tmpdir") + "/contact.profile." - + hasProfilePicture.getId() + ".jpg"); - try (ResponseBody picResponse = contacts.downloadProfilePicture(hasProfilePicture.getId())) { - Files.copy(picResponse.byteStream(), - profilePicPath, - StandardCopyOption.REPLACE_EXISTING); - } - log.info("Downloaded profile pic to " + profilePicPath); - } - - - - Contact newContact = new Contact(); - newContact.setGivenName("Icarus"); - newContact.setMiddleName("J."); - newContact.setSurname("Daedaluson"); - newContact.setSuffix("Esq."); - newContact.setNickname("Ick"); - newContact.setBirthday("1959-03-31"); - newContact.setCompanyName("Solar Airlines"); - newContact.setJobTitle("Aviation Engineer"); - newContact.setManagerName("Minos"); - newContact.setNotes("Sensitive to solar radiation"); - newContact.setOfficeLocation("Crete"); - newContact.setEmails(Arrays.asList(new Contact.Email("work", "icarus@example.com"), - new Contact.Email("personal", "ickthestick@example.com"))); - newContact.setIMAddresses(Arrays.asList(new Contact.IMAddress("yahoo", "ickthestick"))); - newContact.setPhoneNumbers(Arrays.asList(new Contact.PhoneNumber("mobile", "510-555-5555"), - new Contact.PhoneNumber("business", "415-555-5555"))); - Contact.PhysicalAddress address = new Contact.PhysicalAddress(); - address.setStreetAddress("12345 Avian Ave."); - address.setType("other"); - address.setCity("Flyville"); - address.setState("CA"); - address.setCountry("USA"); - address.setPostalCode("00000"); - address.setFormat("structured"); - newContact.setPhysicalAddresses(Arrays.asList(address)); - - Contact created = contacts.create(newContact); - log.info("Created: " + created); - - created.setGivenName("Icarus (deceased)"); - Contact updated = contacts.update(created); - log.info("Updated: " + updated); - - contacts.delete(updated.getId()); - log.info("deleted"); - - ContactGroups groups = account.contactGroups(); - for (ContactGroup group : groups.listAll()) { - log.info(group); - } - } -} diff --git a/src/examples/java/com/nylas/examples/other/DeltaExample.java b/src/examples/java/com/nylas/examples/other/DeltaExample.java deleted file mode 100644 index c470e82c..00000000 --- a/src/examples/java/com/nylas/examples/other/DeltaExample.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.nylas.examples.other; - -import com.nylas.*; -import com.nylas.delta.*; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.io.IOException; - -class DeltaProcessor implements DeltaStreamListener, DeltaLongPollListener { - - private static final Logger log = LogManager.getLogger(DeltaProcessor.class); - - @Override - public void onDelta(Delta delta) { - log.info("Delta received! " + delta); - } - - @Override - public void onDeltaCursor(DeltaCursor deltaCursor) { - log.info("Delta Cursor received! " + deltaCursor); - } -} - -public class DeltaExample { - - private static final Logger log = LogManager.getLogger(DeltaExample.class); - - public static void main(String[] args) throws RequestFailedException, IOException { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(conf.get("access.token")); - Deltas deltas = account.deltas(); - - // Get the latest cursor - String latestCursor = deltas.latestCursor(); - log.info("The latest cursor is: " + latestCursor); - - // Get all the delta cursors since the latest cursor - DeltaCursor deltasSinceLatestCursor = deltas.since(latestCursor); - log.info("The delta cursors since the latest cursor: " + deltasSinceLatestCursor); - - // Create an instance of our class that will listen for new Delta and DeltaCursor types - DeltaProcessor deltaProcessor = new DeltaProcessor(); - - // Stream deltas since the latest cursor - deltas.stream(latestCursor); - - // Long-poll for deltas, with options passed in - DeltaQueryOptions options = new DeltaQueryOptions() - .expandedView(true) - .includeTypes(DeltaQueryOptions.Type.EVENT, DeltaQueryOptions.Type.MESSAGE); - deltas.longpoll(latestCursor, 30, deltaProcessor, options); - } -} diff --git a/src/examples/java/com/nylas/examples/other/DocExamples.java b/src/examples/java/com/nylas/examples/other/DocExamples.java deleted file mode 100644 index d6e46843..00000000 --- a/src/examples/java/com/nylas/examples/other/DocExamples.java +++ /dev/null @@ -1,359 +0,0 @@ -package com.nylas.examples.other; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.time.Instant; -import java.time.LocalDate; -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; -import com.nylas.Event; -import com.nylas.File; -import com.nylas.Message; -import com.nylas.NameEmail; -import com.nylas.NylasAccount; -import com.nylas.NylasApplication; -import com.nylas.NylasClient; -import com.nylas.Participant; -import com.nylas.RequestFailedException; -import com.nylas.Thread; -import com.nylas.ThreadQuery; -import com.nylas.Threads; -import com.nylas.Webhook; - -import okhttp3.ResponseBody; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -/** - * Code examples for the reference doc - */ -public class DocExamples { - - private static final Logger log = LogManager.getLogger(DocExamples.class); - - /** - * https://docs.nylas.com/reference#get-threads - */ - public static void getThreadsExample() throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasAccount account = client.account("YOUR_ACCESS_TOKEN"); - Threads threads = account.threads(); - - // Return all threads found in the user's inbox - threads.list(new ThreadQuery()); - - // Return threads that are filtered by specified arguments - // Available filters: subject, to, from, cc, bcc, in, unread, - // starred, filename, lastMessageBefore, lastMessageAfter, startedBefore, startedAfter - threads.list(new ThreadQuery().to("swag@nylas.com")); - - // Use offset, and limit to control pagination - threads.list(new ThreadQuery().limit(10).offset(10)); - - // Return all threads that meet a specified search criteria - threads.search("swag@nylas.com"); - - // Return the most recent thread - Thread thread = threads.list(new ThreadQuery().limit(1)).iterator().next(); - // or thread = threads.list(new ThreadQuery().limit(1)).fetchAll().get(0); - - // The following attributes are available for the thread object - thread.getSubject(); - thread.getMessageIds(); - thread.isUnread(); - thread.getLabels(); // Gmail accounts only - thread.getFolders(); // All providers other than Gmail - thread.getFirstMessageTimestamp(); - thread.getLastMessageTimestamp(); - thread.getLastMessageReceivedTimestamp(); - thread.getLastMessageSentTimestamp(); - thread.getAccountId(); - thread.getObjectType(); - thread.getId(); - thread.getSnippet(); - thread.getParticipants(); - thread.getDraftIds(); - thread.getVersion(); - thread.isStarred(); - } - - /* - * 2019-12-12 NOTE David Latham: - * currently with the Java SDK, updates to an object go through the collection interface. - * For example, `threads.setUnread(thread.getId(), true)` compared to the python `thread.mark_as_unread()` - * This is to maintain the invariant that all api network requests go through the collection objects - * and avoid any surprising behavior. - * - * Likewise, updating label ids requires specifying the entire set, so I removed the individual add/remove cases. - * - * However, after talking with Ben it seems that other threads perform auto batching when iterating - * collections, which would violate this invariant. If we're willing to throw out the invariant anyway, - * then we could make these object updates similar to other SDKs as well. E.g. `thread.setUnread(true)` - */ - /** - * https://docs.nylas.com/reference#threadsid-1 - */ - public static void putThreadsExample() throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasAccount account = client.account("YOUR_ACCESS_TOKEN"); - Threads threads = account.threads(); - - // Replace '{id}' with the appropriate value - Thread thread = threads.get("{id}"); - - // Mark thread read - threads.setUnread(thread.getId(), false); - - // Mark thread unread - threads.setUnread(thread.getId(), true); - - // Star a thread - threads.setStarred(thread.getId(), true); - - // Unstar a thread - threads.setStarred(thread.getId(), false); - - // Update labels on a thread (Gmail) - threads.setLabelIds(thread.getId(), Arrays.asList("{label_id}", "{another_label_id}")); - - // Move a thread to a different folder (Non-Gmail) - threads.setFolderId(thread.getId(), "{folder_id}"); - } - - /* - * 2019-12-12 NOTE David Latham: - * This example copies the python example's lead of calling "save" once at the end. - * Save performs either a "create" or a "update" under the covers depending on whether - * the passed draft was created only locally by the SDK or was previously retrieved from the server - * I think the example may be improved by demonstrating separate calls to create a new draft - * and later to update a previously created one. But left it as-is to match existing ones. - */ - /** - * https://docs.nylas.com/reference#post-draft - */ - public static void postDraftExample() throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasAccount account = client.account("YOUR_ACCESS_TOKEN"); - - // Create a new draft object - Draft draft = new Draft(); - - draft.setSubject("With Love, From Nylas"); - draft.setTo(Arrays.asList(new NameEmail("My Nylas Friend", "swag@nylas.com"))); - // You can also assign draft.cc, draft.bcc, and draft.from_ in the same manner - draft.setBody("This email was sent using the Nylas email API. Visit https://nylas.com for details."); - draft.setReplyTo(new NameEmail("Your Name", "you@example.com")); - // Note: changing from_ to a different email address may cause deliverability issues - draft.setFrom(new NameEmail("Your Name", "you@example.com")); - - // Replace {id} with the appropriate id for a file that you want to attach to a draft - File file = account.files().get("{id}"); - - // Attach a file to a draft - draft.attach(file); - - // Remove a file attachment from a draft - draft.detach(file); - - // You must save the draft for changes to take effect - draft = account.drafts().save(draft); - // Note: Nylas saves all drafts, but not all providers - // display the drafts on their user interface - } - - /* - * 2019-12-12 NOTE David Latham: - * Followed javascript example writing the result message to the console (system) output. - */ - /** - * https://docs.nylas.com/reference#sending-raw-mime - */ - public static void sendRawMimeExample() throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasAccount account = client.account("YOUR_ACCESS_TOKEN"); - String rawMime = ""; // rawMIME should be a MIME-format string with headers and multipart message - Message message = account.drafts().sendRawMime(rawMime); - log.info(message); - } - - /* - * 2019-12-12 NOTE David Latham: - * The python example says that the date/time can be set in 3 ways, but I think that's out of date - * as there are now 4 supported types. - * May want to improve this example when I revisit date object handling - * - * The example mentions that the event object must have `calendarId` and `when` before creation, - * and the Java API requires it explicitly, so even though the python example doesn't do it, - * this Java example includes a calendarId and date upfront rather than later on. - * - * The python example updates many fields locally but doesn't appear to save/update them back to the server - * I think it's important to show that, so I added a line for it in the Java example here - */ - /** - * https://docs.nylas.com/reference#post-event - */ - public static void postEventExample() throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasAccount account = client.account("YOUR_ACCESS_TOKEN"); - - // The event "when" (date/time) can be set as one of 4 types. - // For details: https://docs.nylas.com/reference#event-subobjects - Event.When when = null; - LocalDate today = LocalDate.now(); - when = new Event.Date(today); - when = new Event.Datespan(today, today.plusDays(1)); - Instant sixPmUtc = today.atTime(18, 0).toInstant(ZoneOffset.UTC); - when = new Event.Time(sixPmUtc); - when = new Event.Timespan(sixPmUtc, sixPmUtc.plus(1, ChronoUnit.HOURS)); - - // Create a new event object - // Provide the appropriate id for a calendar to add the event to a specific calendar - Event event = new Event("{calendarId}", when); - - // save() must be called to save the event to the third party provider - // notifyParticipants='true' will send a notification email to - // all email addresses specified in the participants - account.events().create(event, true); - - event.setTitle("Party!"); - event.setLocation("My House!"); - 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 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"))); - - // Update the event with the new values and notify the participants - account.events().update(event, true); - } - - /* - * 2019-12-12 NOTE David Latham: - * NOT TESTED - I have not been able to test this functionality as I cannot get - * any events to show up in my test "Emailed events" calendar. - */ - /** - * https://docs.nylas.com/reference#rsvping-to-invitations - */ - public static void sendRsvpExample() throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasAccount account = client.account("YOUR_ACCESS_TOKEN"); - // RSVP to an invite. Note that you can only RSVP to invites found in the "Emailed events" calendar. - // rsvp() accepts a status and an optional message - // If notifyParticipants is true, then the message will be sent via email to all participants - account.events().rsvp("{eventId}", "maybe", "{accountId}", "I may attend this event", true); - log.info("RSVP sent!"); - } - - /* - * 2019-12-12 NOTE David Latham: - * The python example creates and saves an empty contact, then makes a bunch of - * changes to it and never updates/saves them to the server. I think this is very misleading, so - * I changed this example to create it with all the fields instead. - */ - /** - * https://docs.nylas.com/reference#contacts-2 - */ - public static void postContactsExample() throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasAccount account = client.account("YOUR_ACCESS_TOKEN"); - - // Create a new contact - Contact contact = new Contact(); - - // The following attributes can be modified for the contact object - contact.setGivenName("My"); - contact.setMiddleName("Nylas"); - contact.setSurname("Friend"); - contact.setSuffix("API"); - contact.setNickname("Nylas"); - contact.setOfficeLocation("San Francisco"); - contact.setCompanyName("Nylas"); - contact.setNotes("Check out the Nylas Email, Calendar, and Contacts APIs"); - contact.setManagerName("Communications"); - contact.setJobTitle("Communications Platform"); - contact.setBirthday("2014-06-01"); - - // emails must be one of type personal, or work - contact.setEmails(Arrays.asList(new Contact.Email("personal", "swag@nylas.com"))); - - // physical_addresses must be one of type work, home, or other - Contact.PhysicalAddress address = new Contact.PhysicalAddress(); - address.setStreetAddress("695 Minna St"); - address.setType("work"); - address.setCity("San Francisco"); - address.setState("CA"); - address.setCountry("US"); - address.setPostalCode("94103"); - address.setFormat("structured"); - contact.setPhysicalAddresses(Arrays.asList(address)); - - // phone_numbers must be one of type - // business, organization_main, mobile, assistant, - // business_fax, home_fax, radio, car, home, or pager - contact.setPhoneNumbers(Arrays.asList(new Contact.PhoneNumber("business", "555 555-5555"))); - - // web_pages must be one of type homepage, profile, work, or blog - contact.setWebPages(Arrays.asList(new Contact.WebPage("homepage", "https://nylas.com"))); - - // im_addresses must be one of type gtalk, aim, - // yahoo, lync, skype, qq, msn, icc, or jabber - contact.setIMAddresses(Arrays.asList(new Contact.IMAddress("gtalk", "Nylas"))); - - // Save the contact to Nylas and the 3rd party provider - // This must be executed whenever you want to save changes. - contact = account.contacts().create(contact); - } - - /** - * https://docs.nylas.com/reference#webhooks-post - */ - public static void postWebhooksExample() throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasApplication application = client.application("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET"); - Webhook webhook = new Webhook(); - webhook.setCallbackUrl("https://wwww.myapp.com/webhook"); - webhook.setState("active"); - webhook.setTriggers(Arrays.asList("event.created", "event.updated")); - webhook = application.webhooks().create(webhook); - log.info(webhook); - } - - /* - * 2019-01-10 NOTE David Latham: - * The python example first fetches a contact object by it's ID, and then downloads the picture. - * In the Java SDK, you don't need to fetch the object in order to download the picture, so it can be done - * in a single request. To access the url, you do need to get the contact object, however. - */ - /** - * https://docs.nylas.com/reference#contactsidpicture - */ - public static void downloadContactPictureExample() throws IOException, RequestFailedException { - NylasClient client = new NylasClient(); - NylasAccount account = client.account("YOUR_ACCESS_TOKEN"); - - // Stream and save a contact's picture to a local file. - // use try-with-resources to make sure the response is properly closed after saving - try (ResponseBody picResponse = account.contacts().downloadProfilePicture("{contact_id}")) { - Files.copy(picResponse.byteStream(), Paths.get("picture.jpg")); - } - - // You can also access the url where Nylas stores the picture with the pictureUrl attribute - Contact contact = account.contacts().get("{contact_id}"); - contact.getPictureUrl(); - } -} diff --git a/src/examples/java/com/nylas/examples/other/DraftsExample.java b/src/examples/java/com/nylas/examples/other/DraftsExample.java deleted file mode 100644 index 12f6b588..00000000 --- a/src/examples/java/com/nylas/examples/other/DraftsExample.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.nylas.examples.other; - -import java.util.Arrays; -import java.util.List; - -import com.nylas.Draft; -import com.nylas.DraftQuery; -import com.nylas.Drafts; -import com.nylas.NameEmail; -import com.nylas.NylasAccount; -import com.nylas.NylasClient; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class DraftsExample { - - private static final Logger log = LogManager.getLogger(DraftsExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(conf.get("access.token")); - Drafts drafts = account.drafts(); - - DraftQuery query = new DraftQuery() - //.subject("now a subject and recipient") - //.to("bob@example.com") - //.cc("dude@dude.com") - //.bcc("georgejetson@example.com") - //.in("Example Label 2") - //.limit(1) - //.offset(1) - //.unread(true) - //.starred(false) - //.anyEmail("dude@dude.com") - //.filename("test.pdf") - //.hasAttachment(true) - //.threadId("53m7tluqh0i1500ntrljtif6e") - //.anyEmail("info@twitter.com") - ; - - List allDrafts = drafts.list(query).fetchAll(); - for (Draft draft : allDrafts) { - log.info(draft); - } - -// log.info(account.fetchAccountByAccessToken()); - -// Draft firstDraft = allDrafts.get(0); -// firstDraft = drafts.get(firstDraft.getId()); -// log.info("first = " + firstDraft); -// -// -// Files files = account.files(); -// List allFiles = files.list(); -// File iconFile = null; -// for (File file : allFiles) { -// log.info("File: " + file); -// if (file.getFilename().equals("icon.png")) { -// iconFile = file; -// break; -// } -// } -// log.info("iconFile = " + iconFile); -// -// allDrafts.get(0).attach(iconFile); -// drafts.update(allDrafts.get(0)); -//// -// File first = allFiles.get(0); -//// byte[] fileBytes = files.downloadBytes(first.getId()); -//// java.nio.file.Files.write(Paths.get("/tmp/" + first.getFilename()), fileBytes); -// byte[] fileBytes = java.nio.file.Files.readAllBytes(Paths.get("/tmp/desktop.ini")); -//// -// File uploaded = files.upload("desktop2.ini", first.getContentType(), fileBytes); -// firstDraft.getFiles().add(uploaded); - - -// Messages messages = account.messages(); -// -// Instant start = LocalDate.of(2019,10,7).atStartOfDay(ZoneId.systemDefault()).toInstant(); -// Instant end = start.plus(1, ChronoUnit.DAYS); -// MessageQuery mquery = new MessageQuery() -// .limit(3) -// //.hasAttachment(true) -// .receivedAfter(start) -// .receivedBefore(end) -// //.anyEmail("info@twitter.com") -//// .in("Example Label 2") -// ; -// -// -// List allMessages = messages.list(mquery); -// // for (Message msg : allMessages) -// Message firstMessage = allMessages.get(0); -// -// -// firstDraft.setReplyToMessageId(firstMessage.getId()); - - -// Draft putResult = drafts.put(firstDraft); -// log.info("put result = " + putResult); -// - Draft draft = new Draft(); - draft.setTo(Arrays.asList(new NameEmail("dude", "dude@b.com"))); - draft.setBody("this is the draft body text"); - draft.setSubject("I wonder if this draft will show up in gmail"); - Draft created = drafts.create(draft); - log.info("post result = " + created); - - created.setSubject("new subject"); - Draft updated = drafts.update(created); - log.info("updated"); - - drafts.delete(updated); - log.info("deleted"); - } - -} diff --git a/src/examples/java/com/nylas/examples/other/EventsExample.java b/src/examples/java/com/nylas/examples/other/EventsExample.java deleted file mode 100644 index 722652f7..00000000 --- a/src/examples/java/com/nylas/examples/other/EventsExample.java +++ /dev/null @@ -1,202 +0,0 @@ -package com.nylas.examples.other; - -import java.io.IOException; -import java.time.Instant; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.temporal.ChronoUnit; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import com.nylas.*; -import com.nylas.Event.Recurrence; -import com.nylas.Event.Time; -import com.nylas.Event.Timespan; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class EventsExample { - - private static final Logger log = LogManager.getLogger(EventsExample.class); - - public static void main(String[] args) throws Exception { - - ExampleConf conf = new ExampleConf(); - String accessToken = conf.get("access.token"); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(accessToken); - Events events = account.events(); - - RemoteCollection calendars = account.calendars().list(); - Calendar primary = null; - for (Calendar c : calendars) { - // primary calendar should be writable and have an email address - if (!c.isReadOnly() && c.getName().contains("@")) { - primary = c; - } - } - if (primary == null) { - log.info("Unable to find primary calendar"); - return; - } - log.info("Primary calendar: " + primary); - - - EventQuery query = new EventQuery() - .calendarId(primary.getId()) - .startsAfter(Instant.now()) - .startsBefore(Instant.now().plus(30, ChronoUnit.DAYS )) - .limit(50); - - for (Event event : events.list(query)) { - log.info("event: " + event); - } - - basicEventCrud(events, primary); - autocreateEvents(events, primary); - - generateICS(events, primary); - //overrideRecurringEvent(primary, events); - //fetchRoomResources(events); - - //events.rsvp("2ou66ruo7skqqc85g3za5yx8x", "yes", "7tc4ldy90u7gkbys880h8j2al", "totes!", true); - } - - protected static void basicEventCrud(Events events, Calendar primary) throws IOException, RequestFailedException { - Event event = createBasicEvent(events, primary); - Event created = events.create(event, true); - log.info("Created: " + created); - - Participant partier = new Participant("hamilton@example.com"); - partier.name("Alexander Hamilton"); - - Participant partier1 = new Participant("hmulligan@example.com"); - partier1.name("Hercules Mulligan"); - - Participant partier2 = new Participant("jlaurens@example.com"); - partier2.name("John Laurens"); - - Participant partier3 = new Participant("lafayette@example.com"); - partier3.name("Marquis de Lafayette"); - - ZoneId startTz = ZoneId.of("America/Los_Angeles"); - ZonedDateTime startTime = ZonedDateTime.now(startTz); - - created.setDescription("hopping good fun"); - created.setWhen(new Time(startTime)); // this party never ends - created.setTitle("Nonsurprise Party"); - created.setBusy(false); - created.setLocation("Lake Merritt"); - created.setRecurrence(new Recurrence(startTz.getId(), Collections.singletonList("RRULE:FREQ=WEEKLY;BYDAY=TH"))); - - Map metadata = new HashMap<>(); - metadata.put("event_category", "gathering"); - created.setMetadata(metadata); - - Event.Conferencing conferencing = new Event.Conferencing(); - conferencing.setProvider(Event.Conferencing.ConferencingProviders.ZOOM); - Event.Conferencing.Details details = new Event.Conferencing.Details(); - details.setMeetingCode("213"); - details.setPassword("xyz"); - details.setUrl("https://us02web.zoom.us/j/****************"); - details.setPhone(Collections.singletonList("+11234567890")); - conferencing.setDetails(details); - created.setConferencing(conferencing); - - Event updated = events.update(created, true); - log.info("Updated: " + updated); - - Event.EmailNotification notification = new Event.EmailNotification(); - notification.setMinutesBeforeEvent(60); - notification.setSubject("Test Event Notification"); - notification.setBody("Reminding you about our meeting."); - updated.setNotifications(Collections.singletonList(notification)); - updated.setParticipants(Arrays.asList(partier, partier1, partier2, partier3)); - - updated = events.update(updated, true); - log.info("Updated: " + updated); - - events.delete(updated.getId(), true); - log.info("Deleted"); - } - - protected static void autocreateEvents(Events events, Calendar primary) throws IOException, RequestFailedException { - Event event = createBasicEvent(events, primary); - Event created = events.create(event, true); - log.info("Created: " + created); - - Event.Conferencing conferencing = new Event.Conferencing(); - conferencing.setProvider("Zoom Meeting"); - Event.Conferencing.Autocreate autocreate = new Event.Conferencing.Autocreate(); - conferencing.setAutocreate(autocreate); - created.setConferencing(conferencing); - - Event updated = events.update(created, true); - log.info("Updated: " + updated); - - events.delete(updated.getId(), true); - log.info("Deleted"); - } - - protected static void overrideRecurringEvent(Calendar calendar, Events events) throws IOException, RequestFailedException { - EventQuery query = new EventQuery() - .expandRecurring(true) - .calendarId(calendar.getId()) - .startsAfter(Instant.now()) - .startsBefore(Instant.now().plus(30, ChronoUnit.DAYS )) - .limit(50); - - Event eventToOverride = null; - for (Event event : events.list(query)) { - if (event.getMasterEventId() != null) { - eventToOverride = event; - break; - } - } - log.info("Event to override: " + eventToOverride); - - if (eventToOverride != null) { - eventToOverride.setTitle("Altered " + eventToOverride.getTitle()); - eventToOverride = events.update(eventToOverride, false); - log.info("Overrode event instance:" + eventToOverride); - } - } - - protected static void generateICS(Events events, Calendar primary) throws RequestFailedException, IOException { - Event event = createBasicEvent(events, primary); - - // You can make an Event from an event that hasn't been created on the API yet - String icsFromLocalEvent = events.generateICS(event); - log.info(icsFromLocalEvent); - - // Or, from a pre-existing event on the API server - Event created = events.create(event, true); - log.info("Created: " + created); - String icsFromExistingEventID = events.generateICS(created.getId()); - log.info(icsFromExistingEventID); - - // You can also pass ICS Options for more configuration - Events.ICSOptions icsOptions = new Events.ICSOptions(); - icsOptions.setIcal_uid("test_uuid"); - icsOptions.setMethod(Events.ICSOptions.ICSMethod.ADD); - icsOptions.setProdid("test_prodid"); - String icsFromExistingEventWithOptions = events.generateICS(created, icsOptions); - log.info(icsFromExistingEventWithOptions); - } - - private static Event createBasicEvent(Events events, Calendar primary) throws IOException, RequestFailedException { - ZoneId startTz = ZoneId.of("America/Los_Angeles"); - ZoneId endTz = ZoneId.of("America/New_York"); - ZonedDateTime startTime = ZonedDateTime.now(startTz); - ZonedDateTime endTime = startTime.plusHours(2).withZoneSameInstant(endTz); - - Event event = new Event(primary.getId(), new Timespan(startTime, endTime)); - event.setTitle("Surprise Party"); - - return event; - } - -} diff --git a/src/examples/java/com/nylas/examples/other/FilesExample.java b/src/examples/java/com/nylas/examples/other/FilesExample.java deleted file mode 100644 index a231810f..00000000 --- a/src/examples/java/com/nylas/examples/other/FilesExample.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.nylas.examples.other; - -import java.nio.file.Path; - -import com.nylas.File; -import com.nylas.FileQuery; -import com.nylas.Files; -import com.nylas.NylasAccount; -import com.nylas.NylasClient; -import com.nylas.RemoteCollection; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class FilesExample { - - private static final Logger log = LogManager.getLogger(FilesExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(conf.get("access.token")); - Files files = account.files(); - RemoteCollection allFiles = files.list(new FileQuery()); - for (File file : allFiles) { - log.info("File: " + file); - } - - File first = allFiles.iterator().next(); - byte[] fileBytes = files.downloadBytes(first.getId()); - - Path tmpfile = java.nio.file.Files.createTempFile(first.getFilename(), null); - java.nio.file.Files.write(tmpfile, fileBytes); - - File uploaded = files.upload(first.getFilename(), first.getContentType(), fileBytes); - log.info("Uploaded: " + uploaded); - - files.delete(uploaded.getId()); - log.info("deleted"); - } - -} diff --git a/src/examples/java/com/nylas/examples/other/FoldersExample.java b/src/examples/java/com/nylas/examples/other/FoldersExample.java deleted file mode 100644 index 4f789a6a..00000000 --- a/src/examples/java/com/nylas/examples/other/FoldersExample.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nylas.examples.other; - -import java.util.List; - -import com.nylas.Folder; -import com.nylas.FolderQuery; -import com.nylas.Folders; -import com.nylas.NylasAccount; -import com.nylas.NylasClient; -import com.nylas.RequestFailedException; -import com.nylas.Thread; -import com.nylas.ThreadQuery; -import com.nylas.Threads; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - - -public class FoldersExample { - - private static final Logger log = LogManager.getLogger(FoldersExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(conf.get("access.token")); - - Folders folders = account.folders(); - - FolderQuery fQuery = new FolderQuery() - .limit(5) - .offset(0); - - List allFolders = folders.list(fQuery).fetchAll(); - Folder inbox = null; - for (Folder folder : allFolders) { - log.info(folder); - if ("inbox".equals(folder.getName())) { - inbox = folder; - } - } - - Folder newFolder = folders.create("Example Folder 7"); - log.info(newFolder); - newFolder.setDisplayName("My Renamed Folder"); - Folder updatedFolder = folders.update(newFolder); - log.info(updatedFolder); - - Threads threads = account.threads(); - List threadList = threads.list(new ThreadQuery().limit(1)).fetchAll(); - if (threadList.isEmpty()) { - log.info("No threads"); - return; - } - - String threadId = threadList.get(0).getId(); - - Thread thread = threads.setFolderId(threadId, updatedFolder.getId()); - log.info(thread); - - try { - folders.delete(updatedFolder.getId()); - } catch (RequestFailedException rfe) { - log.info(rfe.getErrorMessage()); - } - - - thread = threads.setFolderId(threadId, inbox.getId()); - log.info(thread); - - folders.delete(updatedFolder.getId()); - } -} diff --git a/src/examples/java/com/nylas/examples/other/IpAddressWhitelistExample.java b/src/examples/java/com/nylas/examples/other/IpAddressWhitelistExample.java deleted file mode 100644 index 4a944b80..00000000 --- a/src/examples/java/com/nylas/examples/other/IpAddressWhitelistExample.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nylas.examples.other; - -import com.nylas.IPAddressWhitelist; -import com.nylas.NylasApplication; -import com.nylas.NylasClient; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class IpAddressWhitelistExample { - - private static final Logger log = LogManager.getLogger(IpAddressWhitelistExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasApplication application = client.application(conf.get("nylas.client.id"), conf.get("nylas.client.secret")); - log.info("Fetching IP Address whitelist"); - IPAddressWhitelist ipAddresses = application.fetchIpAddressWhitelist(); - log.info("IP Address whitelist: " + ipAddresses); - } - -} diff --git a/src/examples/java/com/nylas/examples/other/JobStatusExample.java b/src/examples/java/com/nylas/examples/other/JobStatusExample.java deleted file mode 100644 index 1861fc67..00000000 --- a/src/examples/java/com/nylas/examples/other/JobStatusExample.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.nylas.examples.other; - -import com.nylas.JobStatus; -import com.nylas.JobStatusQuery; -import com.nylas.JobStatuses; -import com.nylas.NylasAccount; -import com.nylas.NylasClient; -import com.nylas.RemoteCollection; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class JobStatusExample { - - private static final Logger log = LogManager.getLogger(JobStatusExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(conf.get("access.token")); - JobStatuses jobStatuses = account.jobStatuses(); - - long count = jobStatuses.count(new JobStatusQuery()); - log.info("Job status count: " + count); - - JobStatusQuery query = new JobStatusQuery().limit(50); - RemoteCollection allJobStatuses = jobStatuses.list(query); - JobStatus lastStatus = null; - for (JobStatus jobStatus: allJobStatuses) { - log.info(jobStatus); - lastStatus = jobStatus; - } - - if (lastStatus != null) { - JobStatus jobStatus = jobStatuses.get(lastStatus.getId()); - log.info("status: " + jobStatus); - } - - } - -} diff --git a/src/examples/java/com/nylas/examples/other/LabelsExample.java b/src/examples/java/com/nylas/examples/other/LabelsExample.java deleted file mode 100644 index 9b6169dd..00000000 --- a/src/examples/java/com/nylas/examples/other/LabelsExample.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.nylas.examples.other; - -import java.util.Arrays; -import java.util.List; - -import com.nylas.Label; -import com.nylas.Labels; -import com.nylas.Message; -import com.nylas.MessageQuery; -import com.nylas.Messages; -import com.nylas.NylasAccount; -import com.nylas.NylasClient; -import com.nylas.RemoteCollection; -import com.nylas.examples.ExampleConf; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class LabelsExample { - - private static final Logger log = LogManager.getLogger(LabelsExample.class); - - public static void main(String[] args) throws Exception { - ExampleConf conf = new ExampleConf(); - NylasClient client = new NylasClient(); - NylasAccount account = client.account(conf.get("access.token")); - - Labels labels = account.labels(); - RemoteCollection