From dc9e9ff7b4d6f12f8149b94361a4a4a91ba44b02 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Tue, 6 Feb 2024 03:00:54 +0400 Subject: [PATCH] v6.0.0 (#460) # Description This PR is a culmination of all the PRs that contained v6-related development, with formal support for the Nylas API v3. This release is essentially the same as the v6.0.0.beta.4 release found on rubygems. Please refer to the readme for a quick start guide on using the new SDK, as well as links to the upgrade doc as well as the SDK reference docs. # Changelog * **BREAKING CHANGE**: Ruby SDK v6 supports the Nylas API v3 exclusively, dropping support for any endpoints that are not available in v3. * **BREAKING CHANGE**: Officially support minimum Ruby v3 * **BREAKING CHANGE**: Removed all models and typing from the SDK * **REMOVED**: Local Webhook development support is removed due to incompatibility * Rewrote the majority of SDK to be more modular and efficient * Created error classes for the different API errors as well as SDK-specific errors * Added a configurable timeout for outgoing calls to the API ======================================================================================== * Major Refactor and API v3 base implementation (#418) * AV-1468 Purge collections and models * new design * FIRST WORKING API CALL!!! * update * quik cfix * testing file * refactor http handling for resources * node sdk parity * refactor * refactor * application + redirect_uris * scopes * fix * more fix * fixes * more fix --------- Co-authored-by: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> * Generate SDK references github action (#423) * v3 Polish: Cleanup & documentation (#420) This PR: * adds Yard documentation * cleans up typos and just code tidy * Update dependencies and gemspec * Update readme * Repo cleanup * Bug fixes * v6.0.0.beta.1 Release (#425) This PR is for releasing the first beta of v6 on RubyGems. * Add better documentation, more errors, default timeout (#426) This PR adds an upgrade doc, updates the readme, adds more error classes and a default timeout. Co-authored-by: Lrubin * Add support for free-busy endpoint (#428) * Add support for read, update, and delete for messages (#429) * Update README for Hacktoberfest (#427) add blurb on hacktoberfest guidelines * Fix Rubocop complains None of them related to my code, but everything is fixed and tested * Remove hackathon blurb --------- Co-authored-by: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> * Add support for custom authentication, connectors, and credentials APIs (#431) Adds support for custom authentication, the connectors API and the credentials API. * Add Folders API support (#433) This PR adds support for the Folders API * Ruby SDK Messages, Threads, Drafts, and Send support (#432) This PR adds support to messages, threads, drafts, and send. * Ruby Attachments API support (#434) This PR adds support for the Attachments API * v6.0.0 beta 2 release (#436) * Added additional error classes (#426) * Added support for free/busy endpoint (#428) * Added support for Messages, Drafts, and Smart Compose APIs (#432) * Added support for custom authentication, connectors, and credentials APIs (#431) * Added support for folders API (#433) * Added support for attachments API (#434) * Set default timeout to 30 seconds (#426) * Fixed issue when sending message without attachments (#437) This PR fixes a bug that arises when sending messages and creating or modifying drafts without any attachments present. * Fix free-busy endpoint (#440) The endpoint for free-busy was "availability" when it should be "free-busy" * Add support for contacts API (#438) This PR adds support for the contacts API. * Update drafts.rb to include send Adding "send" to the drafts endpoint * Add missing webhooks (#445) Added webhook triggers for: * Message Opened * Message Link Clicked * Thread Replied * Fix doc lines * Added send-rsvp support for events api (#444) Added send-rsvp support for events api * Move `Grants` to `NylasClient` and custom authentication to `Auth` (#447) * Move grants out of auth * move grant create to custom auth * Update CHANGELOG.md * Fix OAuth URL building throwing an error (#449) There is a syntax error when calling build_query. * v6.0.0 beta 3 Release (#450) * Update CHANGELOG.md * linting * bump ver * Update CHANGELOG.md * Fix List and Find Scheduled Messages (#451) List and Find Scheduled messages are mixed up * Fix incorrect PKCE code challenge generation (#452) This PR fixes the PKCE code challenge generation; the correct method the API wants is for us to base64 encode the hex string as opposed to base64 encoding resulting hashed bytearray directly. * Fixed incompatible types when building OAuth2 URL (#453) We were encoding our URL prematurely, causing an error to be thrown when setting additional parameters (PKCE, etc.) * Update contact_groups to list_groups (#455) * Update connectors.rb (#454) * Added v6 beta tests and fixes (#458) Increase code coverage to ~100%. Fixes were also completed: * **BREAKING CHANGE**: Renamed `Applications.info()` to `Applications.get_details()` for consistency * **BREAKING CHANGE**: Changed return type of `Auth.url_for_oauth2_pkce()` from `OpenStruct` to a hash for consistency * Added support for detecting providers * Added enhanced support for the `Webhooks` API * Default `client_secret` to the configured `api_key` for token exchange methods if not provided * Fixed construction of query parameters * Fixed construction of OAuth2 URL * Fixed typo in paths for `Grants` class * v6.0.0 beta 4 release (#459) # Changelog * **BREAKING CHANGE**: Renamed `Applications.info()` to `Applications.get_details()` for consistency * **BREAKING CHANGE**: Changed return type of `Auth.url_for_oauth2_pkce()` from `OpenStruct` to a hash for consistency * Added support for detecting providers * Added enhanced support for the `Webhooks` API * Default `client_secret` to the configured `api_key` for token exchange methods if not provided * Fixed list and find scheduled messages * Fixed incorrect PKCE code challenge generation * Fixed incompatible types when building OAuth2 URL * Fixed construction of query parameters * Fixed construction of OAuth2 URL * Fixed typo in paths for `Grants` class * Update CHANGELOG.md * remove unneded changes from v5 * cleanup references to beta * add xml for simplecov for codecov support --------- Co-authored-by: Albert T Co-authored-by: Aaron de Mello <314152+AaronDDM@users.noreply.github.com> Co-authored-by: Lrubin Co-authored-by: Blag Co-authored-by: YIFAN WU <14408339+yifanplanet@users.noreply.github.com> --- .arcconfig | 3 - .codeclimate.yml | 4 - .github/workflows/rspec.yml | 20 +- .github/workflows/rubocop.yml | 32 +- .github/workflows/sdk-reference.yaml | 45 ++ .gitignore | 1 + .overcommit.yml | 21 - .rubocop.yml | 33 +- .yardopts | 6 + CHANGELOG.md | 13 +- README.md | 76 +- UPGRADE.md | 152 ++++ examples/.gitignore | 16 - examples/authentication/.env.example | 5 - examples/authentication/Gemfile | 9 - examples/authentication/README.md | 17 - examples/authentication/app.rb | 44 -- examples/helpers.rb | 13 - examples/listening-for-webhooks/Gemfile | 4 - examples/listening-for-webhooks/README.md | 13 - examples/listening-for-webhooks/demo-app.rb | 19 - examples/plain-ruby.rb | 16 - examples/plain-ruby/accounts.rb | 27 - examples/plain-ruby/calendars.rb | 22 - examples/plain-ruby/components.rb | 26 - examples/plain-ruby/contacts.rb | 75 -- examples/plain-ruby/deltas.rb | 34 - examples/plain-ruby/drafts.rb | 43 -- examples/plain-ruby/events.rb | 81 -- examples/plain-ruby/files.rb | 28 - examples/plain-ruby/folders.rb | 32 - examples/plain-ruby/job_status.rb | 18 - examples/plain-ruby/labels.rb | 32 - examples/plain-ruby/messages.rb | 48 -- examples/plain-ruby/neural.rb | 57 -- examples/plain-ruby/outbox.rb | 34 - examples/plain-ruby/room_resource.rb | 9 - examples/plain-ruby/scheduler.rb | 78 -- examples/plain-ruby/sending-messages.rb | 34 - examples/plain-ruby/streaming.rb | 32 - examples/plain-ruby/threads.rb | 48 -- examples/plain-ruby/webhooks.rb | 29 - gem_config.rb | 42 +- gemfiles/Gemfile.rails5 | 5 - gemfiles/Gemfile.rails6 | 6 - gemfiles/Gemfile.rest-client.1 | 5 - gemfiles/Gemfile.rest-client.2 | 5 - gemfiles/Gemfile.rubocop | 4 - lib/nylas-streaming.rb | 81 -- lib/nylas.rb | 179 +---- lib/nylas/account.rb | 56 -- lib/nylas/api.rb | 265 ------- lib/nylas/application_details.rb | 13 - lib/nylas/calendar.rb | 46 -- lib/nylas/calendar_collection.rb | 144 ---- lib/nylas/categorize.rb | 14 - lib/nylas/client.rb | 121 +++ lib/nylas/collection.rb | 175 ----- lib/nylas/component.rb | 35 - lib/nylas/component_collection.rb | 10 - lib/nylas/config.rb | 19 + lib/nylas/constraints.rb | 56 -- lib/nylas/contact.rb | 53 -- lib/nylas/contact_group.rb | 23 - lib/nylas/current_account.rb | 23 - lib/nylas/delta.rb | 56 -- lib/nylas/deltas.rb | 19 - lib/nylas/deltas_collection.rb | 40 - lib/nylas/draft.rb | 101 --- lib/nylas/email_address.rb | 12 - lib/nylas/errors.rb | 152 ++-- lib/nylas/event.rb | 144 ---- lib/nylas/event_collection.rb | 15 - lib/nylas/event_conferencing.rb | 12 - lib/nylas/event_conferencing_autocreate.rb | 10 - lib/nylas/event_conferencing_details.rb | 14 - lib/nylas/event_notification.rb | 17 - lib/nylas/file.rb | 75 -- lib/nylas/filter_attributes.rb | 25 - lib/nylas/folder.rb | 26 - lib/nylas/free_busy.rb | 13 - lib/nylas/free_busy_collection.rb | 48 -- lib/nylas/handler/api_operations.rb | 140 ++++ lib/nylas/handler/http_client.rb | 252 +++++++ lib/nylas/http_client.rb | 280 ------- lib/nylas/im_address.rb | 11 - lib/nylas/job_status.rb | 27 - lib/nylas/job_status_collection.rb | 21 - lib/nylas/label.rb | 27 - lib/nylas/logging.rb | 41 -- lib/nylas/message.rb | 98 --- lib/nylas/message_headers.rb | 27 - lib/nylas/message_tracking.rb | 13 - lib/nylas/model.rb | 217 ------ lib/nylas/model/attributable.rb | 89 --- lib/nylas/model/attribute_definition.rb | 24 - lib/nylas/model/attributes.rb | 97 --- lib/nylas/model/list_attribute_definition.rb | 39 - lib/nylas/model/transferable.rb | 53 -- lib/nylas/native_authentication.rb | 39 - lib/nylas/neural.rb | 87 --- lib/nylas/neural_categorizer.rb | 29 - lib/nylas/neural_clean_conversation.rb | 33 - lib/nylas/neural_contact_link.rb | 11 - lib/nylas/neural_contact_name.rb | 11 - lib/nylas/neural_message_options.rb | 35 - lib/nylas/neural_ocr.rb | 16 - lib/nylas/neural_sentiment_analysis.rb | 17 - lib/nylas/neural_signature_contact.rb | 81 -- lib/nylas/neural_signature_extraction.rb | 18 - lib/nylas/new_message.rb | 39 - lib/nylas/nylas_date.rb | 25 - lib/nylas/open_hours.rb | 15 - lib/nylas/outbox.rb | 116 --- lib/nylas/outbox_job_status.rb | 19 - lib/nylas/outbox_message.rb | 17 - lib/nylas/participant.rb | 13 - lib/nylas/phone_number.rb | 11 - lib/nylas/physical_address.rb | 17 - lib/nylas/raw_message.rb | 25 - lib/nylas/recurrence.rb | 11 - lib/nylas/registry.rb | 42 -- lib/nylas/resources/applications.rb | 27 + lib/nylas/resources/attachments.rb | 65 ++ lib/nylas/resources/auth.rb | 209 ++++++ lib/nylas/resources/calendars.rb | 101 +++ lib/nylas/resources/connectors.rb | 80 ++ lib/nylas/resources/contacts.rb | 89 +++ lib/nylas/resources/credentials.rb | 75 ++ lib/nylas/resources/drafts.rb | 102 +++ lib/nylas/resources/events.rb | 98 +++ lib/nylas/resources/folders.rb | 73 ++ lib/nylas/resources/grants.rb | 58 ++ lib/nylas/resources/messages.rb | 126 ++++ lib/nylas/resources/redirect_uris.rb | 68 ++ lib/nylas/resources/resource.rb | 18 + lib/nylas/resources/smart_compose.rb | 36 + lib/nylas/resources/threads.rb | 62 ++ lib/nylas/resources/webhooks.rb | 121 +++ lib/nylas/room_resource.rb | 19 - lib/nylas/rsvp.rb | 24 - lib/nylas/scheduler.rb | 51 -- lib/nylas/scheduler_booking_confirmation.rb | 24 - lib/nylas/scheduler_booking_request.rb | 17 - lib/nylas/scheduler_collection.rb | 104 --- lib/nylas/scheduler_config.rb | 20 - lib/nylas/scheduler_time_slot.rb | 14 - lib/nylas/search_collection.rb | 14 - lib/nylas/send_grid_verified_status.rb | 12 - lib/nylas/services/tunnel.rb | 128 ---- lib/nylas/thread.rb | 66 -- lib/nylas/time_slot.rb | 16 - lib/nylas/time_slot_capacity.rb | 13 - lib/nylas/timespan.rb | 20 - lib/nylas/token_info.rb | 20 - lib/nylas/types.rb | 169 ----- lib/nylas/utils/file_utils.rb | 58 ++ lib/nylas/version.rb | 2 +- lib/nylas/web_page.rb | 11 - lib/nylas/webhook.rb | 111 --- lib/nylas/when.rb | 75 -- nylas-streaming.gemspec | 13 - nylas.gemspec | 20 +- spec/nylas/account_spec.rb | 151 ---- spec/nylas/api_spec.rb | 325 -------- spec/nylas/calendar_collection_spec.rb | 264 ------- spec/nylas/calendar_spec.rb | 174 ----- spec/nylas/client_spec.rb | 57 ++ spec/nylas/collection_spec.rb | 254 ------- spec/nylas/component_spec.rb | 138 ---- spec/nylas/contact_group_spec.rb | 52 -- spec/nylas/contact_spec.rb | 159 ---- spec/nylas/current_account_spec.rb | 53 -- spec/nylas/delta_spec.rb | 78 -- spec/nylas/deltas_collection_spec.rb | 65 -- spec/nylas/deltas_spec.rb | 225 ------ spec/nylas/draft_spec.rb | 395 ---------- spec/nylas/event_spec.rb | 732 ------------------- spec/nylas/filter_attributes_spec.rb | 25 - spec/nylas/folder_spec.rb | 117 --- spec/nylas/free_busy_collection_spec.rb | 62 -- spec/nylas/free_busy_spec.rb | 47 -- spec/nylas/handler/api_operations_spec.rb | 238 ++++++ spec/nylas/handler/http_client_spec.rb | 442 +++++++++++ spec/nylas/http_client_spec.rb | 207 ------ spec/nylas/job_status_spec.rb | 83 --- spec/nylas/label_spec.rb | 38 - spec/nylas/message_spec.rb | 311 -------- spec/nylas/model/attributes_spec.rb | 30 - spec/nylas/model_spec.rb | 232 ------ spec/nylas/native_authentication_spec.rb | 174 ----- spec/nylas/neural_spec.rb | 371 ---------- spec/nylas/new_message_spec.rb | 30 - spec/nylas/outbox_job_status_spec.rb | 30 - spec/nylas/outbox_message_spec.rb | 93 --- spec/nylas/outbox_spec.rb | 114 --- spec/nylas/raw_message_spec.rb | 26 - spec/nylas/resources/applications_spec.rb | 61 ++ spec/nylas/resources/attachments_spec.rb | 83 +++ spec/nylas/resources/auth_spec.rb | 224 ++++++ spec/nylas/resources/calendars_spec.rb | 188 +++++ spec/nylas/resources/connectors_spec.rb | 117 +++ spec/nylas/resources/contacts_spec.rb | 176 +++++ spec/nylas/resources/credentials_spec.rb | 119 +++ spec/nylas/resources/drafts_spec.rb | 220 ++++++ spec/nylas/resources/events_spec.rb | 174 +++++ spec/nylas/resources/folders_spec.rb | 106 +++ spec/nylas/resources/grants_spec.rb | 82 +++ spec/nylas/resources/messages_spec.rb | 213 ++++++ spec/nylas/resources/redirect_uris_spec.rb | 114 +++ spec/nylas/resources/smart_compose_spec.rb | 40 + spec/nylas/resources/threads_spec.rb | 135 ++++ spec/nylas/resources/webhooks_spec.rb | 137 ++++ spec/nylas/room_resource_spec.rb | 66 -- spec/nylas/scheduler_collection_spec.rb | 240 ------ spec/nylas/scheduler_spec.rb | 226 ------ spec/nylas/search_collection_spec.rb | 24 - spec/nylas/send_grid_verified_status_spec.rb | 13 - spec/nylas/thread_spec.rb | 133 ---- spec/nylas/tunnel_spec.rb | 261 ------- spec/nylas/utils/file_utils_spec.rb | 81 ++ spec/nylas/webhook_spec.rb | 226 ------ spec/nylas/when_spec.rb | 38 - spec/spec_helper.rb | 115 +-- spec/support/nylas_helpers.rb | 19 + 225 files changed, 5440 insertions(+), 12103 deletions(-) delete mode 100644 .arcconfig delete mode 100644 .codeclimate.yml create mode 100644 .github/workflows/sdk-reference.yaml delete mode 100644 .overcommit.yml create mode 100644 .yardopts create mode 100644 UPGRADE.md delete mode 100644 examples/.gitignore delete mode 100644 examples/authentication/.env.example delete mode 100644 examples/authentication/Gemfile delete mode 100644 examples/authentication/README.md delete mode 100644 examples/authentication/app.rb delete mode 100644 examples/helpers.rb delete mode 100644 examples/listening-for-webhooks/Gemfile delete mode 100644 examples/listening-for-webhooks/README.md delete mode 100644 examples/listening-for-webhooks/demo-app.rb delete mode 100644 examples/plain-ruby.rb delete mode 100644 examples/plain-ruby/accounts.rb delete mode 100644 examples/plain-ruby/calendars.rb delete mode 100644 examples/plain-ruby/components.rb delete mode 100644 examples/plain-ruby/contacts.rb delete mode 100644 examples/plain-ruby/deltas.rb delete mode 100644 examples/plain-ruby/drafts.rb delete mode 100644 examples/plain-ruby/events.rb delete mode 100644 examples/plain-ruby/files.rb delete mode 100644 examples/plain-ruby/folders.rb delete mode 100644 examples/plain-ruby/job_status.rb delete mode 100644 examples/plain-ruby/labels.rb delete mode 100644 examples/plain-ruby/messages.rb delete mode 100644 examples/plain-ruby/neural.rb delete mode 100644 examples/plain-ruby/outbox.rb delete mode 100644 examples/plain-ruby/room_resource.rb delete mode 100644 examples/plain-ruby/scheduler.rb delete mode 100644 examples/plain-ruby/sending-messages.rb delete mode 100644 examples/plain-ruby/streaming.rb delete mode 100644 examples/plain-ruby/threads.rb delete mode 100644 examples/plain-ruby/webhooks.rb delete mode 100644 gemfiles/Gemfile.rails5 delete mode 100644 gemfiles/Gemfile.rails6 delete mode 100644 gemfiles/Gemfile.rest-client.1 delete mode 100644 gemfiles/Gemfile.rest-client.2 delete mode 100644 gemfiles/Gemfile.rubocop delete mode 100644 lib/nylas-streaming.rb delete mode 100644 lib/nylas/account.rb delete mode 100644 lib/nylas/api.rb delete mode 100644 lib/nylas/application_details.rb delete mode 100644 lib/nylas/calendar.rb delete mode 100644 lib/nylas/calendar_collection.rb delete mode 100644 lib/nylas/categorize.rb create mode 100644 lib/nylas/client.rb delete mode 100644 lib/nylas/collection.rb delete mode 100644 lib/nylas/component.rb delete mode 100644 lib/nylas/component_collection.rb create mode 100644 lib/nylas/config.rb delete mode 100644 lib/nylas/constraints.rb delete mode 100644 lib/nylas/contact.rb delete mode 100644 lib/nylas/contact_group.rb delete mode 100644 lib/nylas/current_account.rb delete mode 100644 lib/nylas/delta.rb delete mode 100644 lib/nylas/deltas.rb delete mode 100644 lib/nylas/deltas_collection.rb delete mode 100644 lib/nylas/draft.rb delete mode 100644 lib/nylas/email_address.rb delete mode 100644 lib/nylas/event.rb delete mode 100644 lib/nylas/event_collection.rb delete mode 100644 lib/nylas/event_conferencing.rb delete mode 100644 lib/nylas/event_conferencing_autocreate.rb delete mode 100644 lib/nylas/event_conferencing_details.rb delete mode 100644 lib/nylas/event_notification.rb delete mode 100644 lib/nylas/file.rb delete mode 100644 lib/nylas/filter_attributes.rb delete mode 100644 lib/nylas/folder.rb delete mode 100644 lib/nylas/free_busy.rb delete mode 100644 lib/nylas/free_busy_collection.rb create mode 100644 lib/nylas/handler/api_operations.rb create mode 100644 lib/nylas/handler/http_client.rb delete mode 100644 lib/nylas/http_client.rb delete mode 100644 lib/nylas/im_address.rb delete mode 100644 lib/nylas/job_status.rb delete mode 100644 lib/nylas/job_status_collection.rb delete mode 100644 lib/nylas/label.rb delete mode 100644 lib/nylas/logging.rb delete mode 100644 lib/nylas/message.rb delete mode 100644 lib/nylas/message_headers.rb delete mode 100644 lib/nylas/message_tracking.rb delete mode 100644 lib/nylas/model.rb delete mode 100644 lib/nylas/model/attributable.rb delete mode 100644 lib/nylas/model/attribute_definition.rb delete mode 100644 lib/nylas/model/attributes.rb delete mode 100644 lib/nylas/model/list_attribute_definition.rb delete mode 100644 lib/nylas/model/transferable.rb delete mode 100644 lib/nylas/native_authentication.rb delete mode 100644 lib/nylas/neural.rb delete mode 100644 lib/nylas/neural_categorizer.rb delete mode 100644 lib/nylas/neural_clean_conversation.rb delete mode 100644 lib/nylas/neural_contact_link.rb delete mode 100644 lib/nylas/neural_contact_name.rb delete mode 100644 lib/nylas/neural_message_options.rb delete mode 100644 lib/nylas/neural_ocr.rb delete mode 100644 lib/nylas/neural_sentiment_analysis.rb delete mode 100644 lib/nylas/neural_signature_contact.rb delete mode 100644 lib/nylas/neural_signature_extraction.rb delete mode 100644 lib/nylas/new_message.rb delete mode 100644 lib/nylas/nylas_date.rb delete mode 100644 lib/nylas/open_hours.rb delete mode 100644 lib/nylas/outbox.rb delete mode 100644 lib/nylas/outbox_job_status.rb delete mode 100644 lib/nylas/outbox_message.rb delete mode 100644 lib/nylas/participant.rb delete mode 100644 lib/nylas/phone_number.rb delete mode 100644 lib/nylas/physical_address.rb delete mode 100644 lib/nylas/raw_message.rb delete mode 100644 lib/nylas/recurrence.rb delete mode 100644 lib/nylas/registry.rb create mode 100644 lib/nylas/resources/applications.rb create mode 100644 lib/nylas/resources/attachments.rb create mode 100644 lib/nylas/resources/auth.rb create mode 100644 lib/nylas/resources/calendars.rb create mode 100644 lib/nylas/resources/connectors.rb create mode 100644 lib/nylas/resources/contacts.rb create mode 100644 lib/nylas/resources/credentials.rb create mode 100644 lib/nylas/resources/drafts.rb create mode 100644 lib/nylas/resources/events.rb create mode 100644 lib/nylas/resources/folders.rb create mode 100644 lib/nylas/resources/grants.rb create mode 100644 lib/nylas/resources/messages.rb create mode 100644 lib/nylas/resources/redirect_uris.rb create mode 100644 lib/nylas/resources/resource.rb create mode 100644 lib/nylas/resources/smart_compose.rb create mode 100644 lib/nylas/resources/threads.rb create mode 100644 lib/nylas/resources/webhooks.rb delete mode 100644 lib/nylas/room_resource.rb delete mode 100644 lib/nylas/rsvp.rb delete mode 100644 lib/nylas/scheduler.rb delete mode 100644 lib/nylas/scheduler_booking_confirmation.rb delete mode 100644 lib/nylas/scheduler_booking_request.rb delete mode 100644 lib/nylas/scheduler_collection.rb delete mode 100644 lib/nylas/scheduler_config.rb delete mode 100644 lib/nylas/scheduler_time_slot.rb delete mode 100644 lib/nylas/search_collection.rb delete mode 100644 lib/nylas/send_grid_verified_status.rb delete mode 100644 lib/nylas/services/tunnel.rb delete mode 100644 lib/nylas/thread.rb delete mode 100644 lib/nylas/time_slot.rb delete mode 100644 lib/nylas/time_slot_capacity.rb delete mode 100644 lib/nylas/timespan.rb delete mode 100644 lib/nylas/token_info.rb delete mode 100644 lib/nylas/types.rb create mode 100644 lib/nylas/utils/file_utils.rb delete mode 100644 lib/nylas/web_page.rb delete mode 100644 lib/nylas/webhook.rb delete mode 100644 lib/nylas/when.rb delete mode 100644 nylas-streaming.gemspec delete mode 100644 spec/nylas/account_spec.rb delete mode 100644 spec/nylas/api_spec.rb delete mode 100644 spec/nylas/calendar_collection_spec.rb delete mode 100644 spec/nylas/calendar_spec.rb create mode 100644 spec/nylas/client_spec.rb delete mode 100644 spec/nylas/collection_spec.rb delete mode 100644 spec/nylas/component_spec.rb delete mode 100644 spec/nylas/contact_group_spec.rb delete mode 100644 spec/nylas/contact_spec.rb delete mode 100644 spec/nylas/current_account_spec.rb delete mode 100644 spec/nylas/delta_spec.rb delete mode 100644 spec/nylas/deltas_collection_spec.rb delete mode 100644 spec/nylas/deltas_spec.rb delete mode 100644 spec/nylas/draft_spec.rb delete mode 100644 spec/nylas/event_spec.rb delete mode 100644 spec/nylas/filter_attributes_spec.rb delete mode 100644 spec/nylas/folder_spec.rb delete mode 100644 spec/nylas/free_busy_collection_spec.rb delete mode 100644 spec/nylas/free_busy_spec.rb create mode 100644 spec/nylas/handler/api_operations_spec.rb create mode 100644 spec/nylas/handler/http_client_spec.rb delete mode 100644 spec/nylas/http_client_spec.rb delete mode 100644 spec/nylas/job_status_spec.rb delete mode 100644 spec/nylas/label_spec.rb delete mode 100644 spec/nylas/message_spec.rb delete mode 100644 spec/nylas/model/attributes_spec.rb delete mode 100644 spec/nylas/model_spec.rb delete mode 100644 spec/nylas/native_authentication_spec.rb delete mode 100644 spec/nylas/neural_spec.rb delete mode 100644 spec/nylas/new_message_spec.rb delete mode 100644 spec/nylas/outbox_job_status_spec.rb delete mode 100644 spec/nylas/outbox_message_spec.rb delete mode 100644 spec/nylas/outbox_spec.rb delete mode 100644 spec/nylas/raw_message_spec.rb create mode 100644 spec/nylas/resources/applications_spec.rb create mode 100644 spec/nylas/resources/attachments_spec.rb create mode 100644 spec/nylas/resources/auth_spec.rb create mode 100644 spec/nylas/resources/calendars_spec.rb create mode 100644 spec/nylas/resources/connectors_spec.rb create mode 100644 spec/nylas/resources/contacts_spec.rb create mode 100644 spec/nylas/resources/credentials_spec.rb create mode 100644 spec/nylas/resources/drafts_spec.rb create mode 100644 spec/nylas/resources/events_spec.rb create mode 100644 spec/nylas/resources/folders_spec.rb create mode 100644 spec/nylas/resources/grants_spec.rb create mode 100644 spec/nylas/resources/messages_spec.rb create mode 100644 spec/nylas/resources/redirect_uris_spec.rb create mode 100644 spec/nylas/resources/smart_compose_spec.rb create mode 100644 spec/nylas/resources/threads_spec.rb create mode 100644 spec/nylas/resources/webhooks_spec.rb delete mode 100644 spec/nylas/room_resource_spec.rb delete mode 100644 spec/nylas/scheduler_collection_spec.rb delete mode 100644 spec/nylas/scheduler_spec.rb delete mode 100644 spec/nylas/search_collection_spec.rb delete mode 100644 spec/nylas/send_grid_verified_status_spec.rb delete mode 100644 spec/nylas/thread_spec.rb delete mode 100644 spec/nylas/tunnel_spec.rb create mode 100644 spec/nylas/utils/file_utils_spec.rb delete mode 100644 spec/nylas/webhook_spec.rb delete mode 100644 spec/nylas/when_spec.rb create mode 100644 spec/support/nylas_helpers.rb diff --git a/.arcconfig b/.arcconfig deleted file mode 100644 index 0df938ee..00000000 --- a/.arcconfig +++ /dev/null @@ -1,3 +0,0 @@ -{ - "conduit_uri" : "https://phab.nylas.com/" -} diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index fb464e0f..00000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,4 +0,0 @@ -version: "2" -plugins: - rubocop: - enabled: true diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 852529bc..e50a096e 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -20,17 +20,11 @@ jobs: fail-fast: false matrix: include: - - gemfile: rails5 - ruby: 2.5 - - gemfile: rails6 - ruby: 2.5 - - gemfile: rails5 - ruby: 2.6 - - gemfile: rails6 - ruby: 2.6 - - gemfile: rails6 - ruby: 3.0 - name: Ruby ${{ matrix.ruby }}, Gemfile ${{ matrix.gemfile }} + - ruby: 3.0 + - ruby: 3.1 + - ruby: 3.2 + + name: Ruby ${{ matrix.ruby }} steps: - uses: actions/checkout@v2 @@ -42,8 +36,8 @@ jobs: - name: Bundle install run: | - bundle config set gemfile "${GITHUB_WORKSPACE}/gemfiles/Gemfile.${{ matrix.gemfile }}" - bundle install --jobs 4 --retry 3 + bundle config set gemfile "${GITHUB_WORKSPACE}/Gemfile" + bundle install - name: Run tests run: bundle exec rspec spec diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index b3b94af0..982bfd3b 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -9,28 +9,22 @@ name: Rubocop on: push: - branches: [main] + branches: [ main ] pull_request: - branches: [main] + branches: [ main ] jobs: test: runs-on: ubuntu-latest - strategy: - matrix: - gemfile: [rubocop] - env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps - BUNDLE_GEMFILE: gemfiles/Gemfile.${{ matrix.gemfile }} - steps: - - uses: actions/checkout@v2 - - name: Set up Ruby - # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, - # change this to (see https://github.com/ruby/setup-ruby#versioning): - # uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e - with: - ruby-version: 3.0 - bundler-cache: true # runs 'bundle install' and caches installed gems automatically - - name: Run rubocop - run: bundle exec rubocop --config .rubocop.yml + - uses: actions/checkout@v2 + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + # uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e + with: + ruby-version: 3.0 + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Generate docs + run: bundle exec rubocop --config .rubocop.yml diff --git a/.github/workflows/sdk-reference.yaml b/.github/workflows/sdk-reference.yaml new file mode 100644 index 00000000..a521ae72 --- /dev/null +++ b/.github/workflows/sdk-reference.yaml @@ -0,0 +1,45 @@ +name: sdk-reference + +on: + push: + branches: + - main + pull_request: + +jobs: + docs: + runs-on: ubuntu-latest + environment: + name: sdk-reference + url: ${{ steps.deploy.outputs.url }} + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, + # change this to (see https://github.com/ruby/setup-ruby#versioning): + # uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e + with: + ruby-version: 3.0 + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Run rubocop + run: bundle exec yard + - name: Set env BRANCH + run: echo "BRANCH=$(echo $GITHUB_REF | cut -d'/' -f 3)" >> $GITHUB_ENV + - name: Set env CLOUDFLARE_BRANCH + run: | + if [[ $BRANCH == 'main' && $GITHUB_EVENT_NAME == 'push' ]]; then + echo "CLOUDFLARE_BRANCH=main" >> "$GITHUB_ENV" + else + echo "CLOUDFLARE_BRANCH=$BRANCH" >> "$GITHUB_ENV" + fi + - name: Publish to Cloudflare Pages + uses: cloudflare/pages-action@v1 + id: deploy + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + projectName: nylas-ruby-sdk-reference + directory: doc + wranglerVersion: "3" + branch: ${{ env.CLOUDFLARE_BRANCH }} diff --git a/.gitignore b/.gitignore index 4fa76ef6..956c01e3 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ TAGS *.swp vendor/ out +test.rb diff --git a/.overcommit.yml b/.overcommit.yml deleted file mode 100644 index b421aea1..00000000 --- a/.overcommit.yml +++ /dev/null @@ -1,21 +0,0 @@ -# Use this file to configure the Overcommit hooks you wish to use. This will -# extend the default configuration defined in: -# https://github.com/brigade/overcommit/blob/master/config/default.yml -# -# For a complete list of hooks, see: -# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook -# -# For a complete list of options that you can use to customize hooks, see: -# https://github.com/brigade/overcommit#configuration - -PreCommit: - RuboCop: - enabled: true - on_warn: fail # Treat all warnings as failures - required_executable: './bin/rubocop' - TrailingWhitespace: - enabled: true - -PrePush: - RSpec: - enabled: true diff --git a/.rubocop.yml b/.rubocop.yml index c0235d33..9e461599 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ inherit_from: .rubocop_todo.yml require: rubocop-rspec AllCops: - TargetRubyVersion: 2.5 + TargetRubyVersion: 3.0 DisplayCopNames: true DisplayStyleGuide: true Exclude: @@ -21,27 +21,23 @@ Metrics/BlockLength: - "*.gemspec" - "spec/**/*_spec.rb" -Metrics/ParameterLists: - Max: 8 - Exclude: - - "lib/nylas/calendar_collection.rb" +Metrics/AbcSize: + Enabled: false Metrics/MethodLength: - Exclude: - - "lib/nylas/calendar_collection.rb" - - "lib/nylas/services/tunnel.rb" - -Metrics/AbcSize: - Exclude: - - "lib/nylas/services/tunnel.rb" + Enabled: false Metrics/ModuleLength: - Exclude: - - "lib/nylas/model.rb" + Enabled: false -Naming/FileName: - Exclude: - - "lib/nylas-streaming.rb" +Metrics/ParameterLists: + Enabled: false + +Metrics/PerceivedComplexity: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false Metrics/ClassLength: Enabled: false @@ -57,3 +53,6 @@ RSpec/MultipleExpectations: RSpec/ExampleLength: Enabled: false + +RSpec/FilePath: + Enabled: false diff --git a/.yardopts b/.yardopts new file mode 100644 index 00000000..651f02d4 --- /dev/null +++ b/.yardopts @@ -0,0 +1,6 @@ +--no-private +--protected +--exclude lib/nylas/handler/api_operations.rb +--exclude lib/nylas/handler/http_client.rb +--exclude lib/nylas/resources/base_resource.rb +lib/**/*.rb \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cd50076..bf6ad3c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,13 @@ # Changelog -### Unreleased -* Add support for count on message/thread search -* Add support for detect provider endpoint -* Add accept header by default -* Fix contact picture encoding error +### 6.0.0 / 2024-02-05 +* **BREAKING CHANGE**: Ruby SDK v6 supports the Nylas API v3 exclusively, dropping support for any endpoints that are not available in v3. +* **BREAKING CHANGE**: Officially support minimum Ruby v3 +* **BREAKING CHANGE**: Removed all models and typing from the SDK +* **REMOVED**: Local Webhook development support is removed due to incompatibility +* Rewrote the majority of SDK to be more modular and efficient +* Created error classes for the different API errors as well as SDK-specific errors +* Added a configurable timeout for outgoing calls to the API ### 5.17.0 / 2022-04-04 * Add support for verifying webhook signatures diff --git a/README.md b/README.md index a9dcb756..5fc295ea 100644 --- a/README.md +++ b/README.md @@ -4,30 +4,29 @@ # Nylas Ruby SDK -[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/nylas/nylas-ruby/CI)](https://github.com/nylas/nylas-ruby/actions/workflows/rspec.yml) +[![Gem (including prereleases)](https://img.shields.io/gem/v/nylas?include_prereleases)](https://rubygems.org/gems/nylas) [![codecov](https://codecov.io/gh/nylas/nylas-ruby/branch/main/graph/badge.svg?token=IKH0YMH4KA)](https://codecov.io/gh/nylas/nylas-ruby) -The Nylas Communications Platform allows developers to quickly build features that connect to every inbox, calendar, and contacts book in the world. Nylas makes it easy to build an integration that can be completed in days, and provides pre-built security and compliance features, and a 99.9% guaranteed uptime. Integrations with the Nylas Communications Platform are secure, reliable, and easy to use and maintain. +This is the GitHub repository for the Nylas Ruby SDK. This repo is primarily for anyone who wants to make contributions to the SDK or install it from source. For documentation on how to use this SDK to access the Nylas Email, Calendar, or Contacts APIs, see the official [Ruby SDK Quickstart Guide](https://developer.nylas.com/docs/sdks/ruby/). -Nylas provides REST APIs for [Email](https://docs.nylas.com/docs/quickstart-email), [Calendar](https://docs.nylas.com/docs/quickstart-calendar), and [Contacts](https://docs.nylas.com/docs/quickstart-contacts), and the Ruby SDK is the quickest way to build your first integration using Ruby. +The Nylas Communications Platform provides REST APIs for [Email](https://developer.nylas.com/docs/email/), [Calendar](https://developer.nylas.com/docs/calendar/), and [Contacts](https://developer.nylas.com/docs/contacts/), and the Nylas SDK is the quickest way to build your integration using Ruby. -This is the GitHub repository for the Nylas Ruby SDK and is primarily for anyone who wants to make contributions to the SDK or install it from source. If you are looking to use Ruby to access the Nylas Email, Calendar, or Contacts API you should refer to our official [Ruby](https://docs.nylas.com/docs/quickstart-ruby) [SDK Quickstart Guide](https://docs.nylas.com/docs/quickstart-ruby). +Here are some resources to help you get started: -Here are some additional resources to help you get started: +- [Sign up for the Nylas v3 Beta program to access the v3 Dashboard](https://info.nylas.com/apiv3betasignup.html?utm_source=github&utm_medium=devrel-surfaces&utm_campaign=&utm_content=ruby-sdk-upgrade) +- [Nylas API v3 Quickstart Guide](https://developer.nylas.com/docs/v3-beta/v3-quickstart/) +- [Nylas SDK Reference](https://nylas-ruby-sdk-reference.pages.dev/) +- [Nylas API Reference](https://developer.nylas.com/docs/api/v3-beta/) +- [Nylas Samples repo for code samples and example applications](https://github.com/orgs/nylas-samples/repositories?q=&type=all&language=ruby) -- [Nylas SDK Tutorials](https://docs.nylas.com/docs/tutorials) -- [Get Started with the Nylas Communications Platform](https://docs.nylas.com/docs/getting-started) -- [Sign up for your Nylas developer account.](https://nylas.com/register) -- [Nylas API Reference](https://docs.nylas.com/reference) - -If you have a question that needs an answer, please reach out to support@nylas.com to get help. +If you have a question about the Nylas Communications Platform, [contact Nylas Support](https://support.nylas.com/) for help. ## ⚙️ Install + ### Prerequisites -- Ruby 2.3 or above. -- Ruby Frameworks: `rest-client`, `json`, `yajl-ruby`. -We support Rails 4.2 and above. A more detailed compatibility list can be found in our [list of Gemfiles](https://github.com/nylas/nylas-ruby/tree/master/gemfiles). +- Ruby 3.0 or above. +- Ruby Frameworks: `rest-client` and `yajl-ruby`. ### Install @@ -43,7 +42,7 @@ And then execute: bundle ``` -To run scripts that use the Nylas Ruby SDK, install the nylas gem. +To run scripts that use the Nylas Ruby SDK, install the `nylas` gem. ```bash gem install nylas @@ -56,7 +55,7 @@ git clone https://github.com/nylas/nylas-ruby.git && cd nylas-ruby bundle install ``` -### Setup Ruby SDK for Development +### Set up Ruby SDK for Development Install [RubyGems](https://rubygems.org/pages/download) if you don't already have it: @@ -76,52 +75,47 @@ You can run tests locally using ```rspec```: ```shell rspec spec ``` - -### MacOS 10.11 (El Capitan) Note - -Apple stopped bundling OpenSSL with MacOS 10.11. However, one of the dependencies of this gem (EventMachine) requires it. If you're on El Capitan and are unable to install the gem, try running the following commands in a terminal: - -```bash -sudo brew install openssl -sudo brew link openssl --force -gem install nylas -``` ## ⚡️ Usage -To use this SDK, you first need to [sign up for a free Nylas developer account](https://nylas.com/register). +To use this SDK, you must first [sign up for the v3 Beta and get a free Nylas account](https://info.nylas.com/apiv3betasignup.html?utm_source=github&utm_medium=devrel-surfaces&utm_campaign=&utm_content=ruby-sdk-upgrade). -Then, follow our guide to [setup your first app and get your API access keys](https://docs.nylas.com/docs/get-your-developer-api-keys). +Then, follow the Quickstart guide to [set up your first app and get your API keys](https://developer.nylas.com/docs/v3-beta/v3-quickstart/). -All of the functionality of the Nylas Communications Platform is available through the `API` object. To access data for an account that’s connected to Nylas, create a new API client object and pass the variables you gathered when you got your developer API keys. In the following example, replace `CLIENT_ID`, `CLIENT_SECRET`, and `ACCESS_TOKEN` with your values. +For code examples that demonstrate how to use this SDK, take a look at our [Ruby repos in the Nylas Samples collection](https://github.com/orgs/nylas-samples/repositories?q=&type=all&language=ruby). +### 🚀 Making Your First Request + +All of the functionality of the Nylas Communications Platform is available through the `Client` object. To access data for an account that’s connected to Nylas, create a new API client object and pass in your Nylas API key. In the following example, replace `NYLAS_API_KEY` with your Nylas API Key, and you can provide other additional configurations such as the Nylas API url and the timeout. ```ruby require 'nylas' -nylas = Nylas::API.new( - app_id: CLIENT_ID, - app_secret: CLIENT_SECRET, - access_token: ACCESS_TOKEN +nylas = Nylas::Client.new( + api_key: "NYLAS_API_KEY", ) ``` -Now, you can use `nylas` to access full email, calendar, and contacts functionality. For example, here is how you would print the subject line for the most recent email message to the console. - +Now, you can use `nylas` to access full email, calendar, and contacts functionality, for example to list all the calendars for a given account: ```ruby -message = nylas.messages.first -puts(message.subject) +calendars, _request_ids = nylas.calendars.list(identifier: "GRANT_ID") ``` -To learn more about how to use the Nylas Ruby SDK, please refer to our [Ruby](https://docs.nylas.com/docs/quickstart-ruby) [SDK QuickStart Guide](https://docs.nylas.com/docs/quickstart-ruby). +## 📚 Documentation + +Nylas maintains a [reference guide for the Ruby SDK](https://nylas-ruby-sdk-reference.pages.dev/) to help you get familiar with the available methods and classes. + +## ✨ Upgrading from 5.x + +See [UPGRADE.md](UPGRADE.md) for instructions on upgrading from 5.x to 6.x. + +**Note**: The Ruby SDK v6.x is not compatible with the Nylas API earlier than v3-beta. If you are using Nylas v2.7 or earlier, continue using the v5.x Nylas Ruby SDK. ## 💙 Contributing Please refer to [Contributing](Contributing.md) for information about how to make contributions to this project. We welcome questions, bug reports, and pull requests. -Taking part in Hacktoberfest 2023 (i.e. issue is tagged with `hacktoberfest`)? Read our [Nylas Hacktoberfest 2023 contribution guidelines](https://github.com/nylas-samples/nylas-hacktoberfest-2023/blob/main/readme.md). - ## 📝 License -This project is licensed under the terms of the MIT license. Please refer to [LICENSE](LICENSE.txt) for the full terms. +This project is licensed under the terms of the MIT license. Please refer to [LICENSE](LICENSE.txt) for the full terms. diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 00000000..48f3bfbf --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,152 @@ +# Upgrading to Nylas Ruby SDK v6.0 + +The Nylas Ruby SDK has been refactored and large parts of it have been rewritten for the upcoming release of the [Nylas API v3](https://developer.nylas.com/docs/v3-beta/). The goal was to have a product that is intuitive and easier to use. This guide helps you upgrade your code to use the new SDK. The new SDK also includes [documentation for the SDK's methods and usage](https://nylas-ruby-sdk-reference.pages.dev/) so you can easily find the implementation details you need. + +Head's up! Nylas API v3 [contains a lot of changes](https://developer.nylas.com/docs/v3-beta/features-and-changes/), and you should familiarize yourself with them before you start upgrading. + +⚠️ **Note:** The Nylas Ruby SDK v6.0 is not compatible with Nylas APIs earlier than 3.0 beta. If you are still using an earlier version of the API (such as Nylas v2.7), keep using the Nylas Ruby SDK v5.x until you can upgrade. + +## Initial Set up + +To upgrade to the new SDK, update your dependencies to use the new version. You do this by using RubyGems to install the new version of the SDK. + +**Note:** The minimum Ruby version is now at the oldest supported LTS, Ruby v3.0. + +```bash +gem install nylas --pre +``` + +The first step to using the new SDK is to initialize a new instance of the Nylas SDK. Do this by passing in your API key to the constructor. Notice the syntax change in the example below. + +```ruby +require 'nylas' + +nylas = Nylas::API.new( + api_key: "NYLAS_API_KEY", +) +``` + +From here, you can use the `Nylas` instance to make API requests using your API key to access the different resources. + +## Making Requests to the Nylas API + +You use the `Nylas` instance that you configured earlier to make requests to the Nylas API. The SDK is organized into different resources for each of the Email, Calendar, and Contacts APIs, and each resource has all the available methods to make requests to the API. + +For example, to get a list of calendars, you can do so like: + +```ruby +require 'nylas' + +nylas = Nylas::API.new( + api_key: "NYLAS_API_KEY", +) + +events, _request_ids = nylas.events.list(identifier: "grant_id") +``` + +You might notice that there are some new concepts in the example SDK code above when making requests. These concepts are explained in more detail below. + +### Resource Parameters + +Each resource takes different parameters. All resources take an "identifier", which is the ID of the account you want to make the request on behalf of. This is usually the Grant ID or the email address of the account. Some resources also take "query parameters" which are mainly used to filter data or pass in additional information. + +### Response Objects + +The Nylas API returns a JSON response for each request. The SDK parses the JSON response and returns a response hash that contains the data returned from the API, and a string that represents the request ID for the request it responds to. You can use this ID for debugging and troubleshooting. + +List request responses include the same items, except the response hash contains an _array_ of the data returned from the API. If there are multiple pages of data, the response hash also contains a `next_cursor` key that includes a token that represents the next page of data. You can extract this token and use it as a query parameter for the next request to get the next page of data. Pagination features are coming soon. + +### Error Objects + +Like the response objects, Nylas v3 now has standard error objects for all requests (excluding OAuth endpoints, see below). There are two superclass error classes, `AbstractNylasApiError`, used for errors returned by the API, and `AbstractNylasSdkError`, used for errors returned by the SDK. + +The `AbstractNylasApiError` includes two subclasses: `NylasOAuthError`, used for API errors that are returned from the OAuth endpoints, and `NylasApiError`, used for any other Nylas API errors. + +The SDK extracts the error details from the response and stores them in the error object, along with the request ID and the HTTP status code. + +`AbstractNylasSdkError` is used for errors returned by the SDK. Right now there's only one type of error we return, and that's a `NylasSdkTimeoutError` which is thrown when a request times out. + +Putting it all together, the following example code shows how to make a request to create a new Event and handle any errors that may occur: + +```ruby +require 'nylas' + +nylas = Nylas::API.new( + api_key: "NYLAS_APP_KEY", +) + +begin + # Build the create event request + create_event_request = nylas.events.create( + identifier: "GRANT_ID", + query_params: { + calendar_id: "CALENDAR_ID", # A calendar ID is required + }, + request_body: { + when: { + start_time: 1686765600, + end_time: 1686769200, + }, # A "When" type is required + title: "My Event", # Title is optional + description: "My event description", # Description is optional + location: "My event location", # Location is optional + } + ) +rescue Nylas::NylasApiError => e + # Handle the error + puts e.message + puts e.request_id + puts e.status_code +rescue Nylas::NylasSdkTimeoutError => e + # Handle the error + puts e.message + puts e.url +end +``` + +## Authentication + +The SDK's authentication methods reflect [the methods available in the new Nylas API v3](https://developer.nylas.com/docs/developer-guide/v3-authentication/). While you can only create and manage your application's connectors (formerly called integrations) in the dashboard, you can manage almost everything else directly from the SDK. This includes managing grants, redirect URIs, OAuth tokens, and authenticating your users. + +There are two main methods to focus on when authenticating users to your application. The first is the `Auth#urlForOAuth2` method, which returns the URL that you redirect your users to in order to authenticate them using Nylas' OAuth 2.0 implementation. + +The second is the `Auth#exchangeCodeForToken` method. Use this method to exchange the code Nylas returned from the authentication redirect for an access token from the OAuth provider. Nylas's response to this request includes both the access token, and information about the grant that was created. You don't _need_ to use the `grant_id` to make requests. Instead, you can use the authenticated email address directly as the identifier for the account. If you prefer to use the `grant_id`, you can extract it from the `CodeExchangeResponse` object and use that instead. + +The following code shows how to authenticate a user into a Nylas application: + +```ruby +require 'nylas' + +nylas = Nylas::API.new( + api_key: "NYLAS_APP_KEY", +) + +# Build the URL for authentication +auth_url = nylas.auth.url_for_oauth2( + client_id: "CLIENT_ID", + redirect_uri: "REDIRECT_URI", + login_hint: "example@email.com" +) + +# Write code here to redirect the user to the url and parse the code +... + +# Exchange the code for an access token + +code_exchange_response = nylas.auth.exchange_code_for_token({ + redirect_uri: "REDIRECT_URI", + client_id: "CLIENT_ID", + client_secret: "CLIENT_SECRET", + code: "CODE" +}) + +# Now you can either use the email address that was authenticated or the grant ID in the response as the identifier + +response_with_email = nylas.calendars.list( + identifier: "example@email.com" +) + +response_with_grant = nylas.calendars.list( + identifier: code_exchange_response.grant_id +) +``` diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index 6a502e99..00000000 --- a/examples/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -# See https://help.github.com/articles/ignoring-files for more about ignoring files. -# -# If you find yourself ignoring temporary files generated by your text editor -# or operating system, you probably want to add a global ignore instead: -# git config --global core.excludesfile '~/.gitignore_global' - -# Ignore bundler config. -/.bundle - -# Ignore the default SQLite database. -/db/*.sqlite3 -/db/*.sqlite3-journal - -# Ignore all logfiles and tempfiles. -/log/*.log -/tmp diff --git a/examples/authentication/.env.example b/examples/authentication/.env.example deleted file mode 100644 index 371ca2a6..00000000 --- a/examples/authentication/.env.example +++ /dev/null @@ -1,5 +0,0 @@ -export NYLAS_LOG_LEVEL=INFO # Set this to DEBUG if you want to see every request / response sent to nylas -export NYLAS_APP_ID="GET THIS FROM dashboard.nylas.com" -export NYLAS_APP_SECRET="GET THIS FROM dashboard.nylas.com" -export GOOGLE_CLIENT_ID="GET THIS FROM console.cloud.google.com" -export GOOGLE_CLIENT_SECRET="GET THIS FROM console.cloud.google.com" diff --git a/examples/authentication/Gemfile b/examples/authentication/Gemfile deleted file mode 100644 index 63300f7a..00000000 --- a/examples/authentication/Gemfile +++ /dev/null @@ -1,9 +0,0 @@ -source 'https://rubygems.org' - - -gem 'pry' -gem 'sinatra' -gem 'omniauth' -gem 'omniauth-google-oauth2' -gem 'dotenv' -gemspec path: '../..', name: 'nylas' diff --git a/examples/authentication/README.md b/examples/authentication/README.md deleted file mode 100644 index f6d32704..00000000 --- a/examples/authentication/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Authentication - -Nylas supports two forms of authentication: - -* Native Authentication, where the developer is responsible for building the user interface for retrieiving the appropriate credentials for a users contacts, mail and/or calendar provider. See the [Nylas Native Authentication Reference Documentation](https://docs.nylas.com/reference#native-authentication-1) for more details. - -* Nylas OAuth, where Nylas acts as an OAuth Provider that abstracts away the supported providers. This allows you to get up and running quickly without having to build potentially complex user interfaces for supporting any number of providers. See the [Nylas OAuth Authentication Reference Documentation](https://docs.nylas.com/reference#oauth) for more details. - -## Running the Example - -1. Clone the repository -1. Install the dependencies by using `bundle install` -1. Get a Nylas App ID and App Secret from the [Nylas Dashboard](https://dashboard.nylas.com/) -1. Get a Google Cloud Platform Access Token by following the [Nylas Google Setup Guide](https://docs.nylas.com/docs/creating-a-google-project-for-dev). Make sure to set the callback to `localhost:4567/auth/google/callback`. -1. Copy `.env.example` to `.env` and set the values based upon the previous steps. -1. Run the app web server: `bundle exec dotenv ruby app.rb` -1. Login to whichever mail, contact, and calendaring providers you want using the different authentication mechanisms. diff --git a/examples/authentication/app.rb b/examples/authentication/app.rb deleted file mode 100644 index abe2e128..00000000 --- a/examples/authentication/app.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'pry' -require 'nylas' -require 'sinatra' -require 'omniauth' -require 'omniauth-google-oauth2' - -use Rack::Session::Cookie -use OmniAuth::Builder do - provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'], - { name: 'google', access_type: :offline, approval_prompt: "force", prompt: 'consent', - scope: ['email', 'profile', 'https://mail.google.com/', - 'https://www.googleapis.com/auth/contacts', - 'calendar'].join(', ') } -end -get "/" do - 'Authenticate a Google Account' -end - -get "/auth/failure" do - params[:message] -end - -%w(get post).each do |method| - send(method, "/auth/:provider/callback") do - auth_hash = env['omniauth.auth'] # => OmniAuth::AuthHash - - api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET']) - nylas_token = api.authenticate(name: auth_hash[:info][:name], email_address: auth_hash[:info][:email], - provider: :gmail, - settings: { google_client_id: ENV['GOOGLE_CLIENT_ID'], - google_client_secret: ENV['GOOGLE_CLIENT_SECRET'], - google_refresh_token: auth_hash[:credentials][:refresh_token] }) - - api_as_user = api.as(nylas_token) - - an_email = api_as_user.messages.first - - # Revoke the nylas access token so it cannot be used in the future (you probably don't want to do this - # unless people deactivate their account with your software) - api.revoke(nylas_token) - - "An email you've received has the subject #{an_email.subject} and the body #{an_email.body}" - end -end diff --git a/examples/helpers.rb b/examples/helpers.rb deleted file mode 100644 index df85a88e..00000000 --- a/examples/helpers.rb +++ /dev/null @@ -1,13 +0,0 @@ -$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))) -require "nylas" -require "faker" -require "pry" -require "awesome_print" - -require "method_source" -def demonstrate(&block) - block.source.display - result = yield - ap result - result -end diff --git a/examples/listening-for-webhooks/Gemfile b/examples/listening-for-webhooks/Gemfile deleted file mode 100644 index 4a7cb031..00000000 --- a/examples/listening-for-webhooks/Gemfile +++ /dev/null @@ -1,4 +0,0 @@ -source 'https://rubygems.org' - -gem 'sinatra' -gemspec path: '../..', name: 'nylas' diff --git a/examples/listening-for-webhooks/README.md b/examples/listening-for-webhooks/README.md deleted file mode 100644 index a1082e60..00000000 --- a/examples/listening-for-webhooks/README.md +++ /dev/null @@ -1,13 +0,0 @@ -This example application listens for webhook events and logs them directly to -the screen, first as the entire JSON blob that is received, then as each Delta, -then as the particular data as a hash - -## Running the Example - -1. Clone the repository -1. Install the dependencies by using `bundle install` -1. Get a Nylas App ID and App Secret from the [Nylas Dashboard](https://dashboard.nylas.com/) -1. Run the app web server: `bundle exec ruby demo-app.rb` -1. Use a service like `ngrok` to expose your local app server to the public internet. -1. Set up a webhook to point to the public url for your local instance at the path `/webhook-event-received` by following the [instructions for creating a webhook](https://docs.nylas.com/v1.0/reference#creating-a-webhook). -1. Perform some kind of interactions that would trigger the webhook. diff --git a/examples/listening-for-webhooks/demo-app.rb b/examples/listening-for-webhooks/demo-app.rb deleted file mode 100644 index 8c5b875a..00000000 --- a/examples/listening-for-webhooks/demo-app.rb +++ /dev/null @@ -1,19 +0,0 @@ -require 'sinatra' -require 'nylas' - -get '/webhook-event-received' do - params[:challenge] -end - -post '/webhook-event-received' do - request.body.rewind - json = request.body.read - logger.info ["json", json] - data = JSON.parse(json, symbolize_names: true) - deltas = Nylas::Deltas.new(**data) - deltas.map do |delta| - logger.info ["delta", delta.to_h] - logger.info ["instance", delta.instance.class, delta.instance.to_h] - end - params[:challenge] -end diff --git a/examples/plain-ruby.rb b/examples/plain-ruby.rb deleted file mode 100644 index 3aa5325f..00000000 --- a/examples/plain-ruby.rb +++ /dev/null @@ -1,16 +0,0 @@ -require_relative 'helpers' - -require_relative 'plain-ruby/accounts' -require_relative 'plain-ruby/calendars' -require_relative 'plain-ruby/contacts' -require_relative 'plain-ruby/drafts' -require_relative 'plain-ruby/deltas' -require_relative 'plain-ruby/events' -require_relative 'plain-ruby/files' -require_relative 'plain-ruby/folders' -require_relative 'plain-ruby/labels' -require_relative 'plain-ruby/messages' -require_relative 'plain-ruby/sending-messages' -require_relative 'plain-ruby/threads' - -require_relative 'plain-ruby/streaming' diff --git a/examples/plain-ruby/accounts.rb b/examples/plain-ruby/accounts.rb deleted file mode 100644 index 431f2a9b..00000000 --- a/examples/plain-ruby/accounts.rb +++ /dev/null @@ -1,27 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It -# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Retrieving the account information for given access token -demonstrate { api.current_account.to_h } - -# Retrieving the accounts you may manage -demonstrate { api.accounts.limit(5).map(&:to_h) } - -# Deactivating an account -account = api.accounts.first -demonstrate { account.downgrade } -demonstrate { account.to_h } - -# Activating an account -demonstrate { account.upgrade } -demonstrate { account.to_h } - -# Get token info for access token -demonstrate { api.accounts.first.token_info(ENV['NYLAS_ACCESS_TOKEN']).to_h } - -# Getting application details -demonstrate { api.application_details } diff --git a/examples/plain-ruby/calendars.rb b/examples/plain-ruby/calendars.rb deleted file mode 100644 index f9bd99af..00000000 --- a/examples/plain-ruby/calendars.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas -# Calendar API. -# See https://docs.nylas.com/reference#calendars -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - - -# Retrieving the ids of all the calendars -demonstrate { api.calendars.ids } - -# Retrieving the count of the calendars -demonstrate { api.calendars.count } - -# Listing calendars -demonstrate { api.calendars.limit(2).map(&:to_h) } - - -# Retrieving a single calendar by ID -example_calendar = api.calendars.first -demonstrate { api.calendars.find(example_calendar.id).to_h } diff --git a/examples/plain-ruby/components.rb b/examples/plain-ruby/components.rb deleted file mode 100644 index f4c7b525..00000000 --- a/examples/plain-ruby/components.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It -# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET']) - -# Create a component -# NOTE: you will need to set the account_id and the access_token -demonstrate { api.components.create(name: "Ruby Component Test", type: "agenda", public_account_id: ENV['NYLAS_ACCOUNT_ID'], access_token: ENV['NYLAS_ACCESS_TOKEN']) } - -# Get all components -demonstrate { api.components } - -# Retrieving a particular component -example_component = api.components.last -demonstrate { api.components.find(example_component.id).to_h } - -# Editing a particular component -demonstrate do example_component.update( - name: "New Updated Ruby Name" -) -end -demonstrate { example_component.name } - -# Delete a component -demonstrate { example_component.destroy } \ No newline at end of file diff --git a/examples/plain-ruby/contacts.rb b/examples/plain-ruby/contacts.rb deleted file mode 100644 index 6da518fa..00000000 --- a/examples/plain-ruby/contacts.rb +++ /dev/null @@ -1,75 +0,0 @@ -require_relative '../helpers' -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It -# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) -# Retrieving a count of contacts -demonstrate { api.contacts.count } - -# Retrieving a subset of contacts using limit -demonstrate { api.contacts.limit(5).map(&:to_h) } - -data = { - given_name: Faker::Name.first_name, - surname: Faker::Name.last_name, - picture_url: 'https://placekitten.com/g/300/300', - physical_addresses: [{ format: "structured", - type: ['home', 'work', nil].sample, - street_address: Faker::Address.street_address, - postal_code: Faker::Address.postcode, - city: Faker::Address.city, - state: Faker::Address.state, - country: ["USA", "America", "Canada"].sample }], - phone_numbers: [{ type: ['business', 'home', 'mobile', 'pager', 'business_fax', 'home_fax', - 'organization_main', 'assistant', 'radio'].sample, - number: Faker::PhoneNumber.cell_phone }], - emails: [{ type: ['personal', 'work', nil].sample, email: "contact-with-picture@example.com" }, - { type: ['personal', 'work', nil].sample, email: Faker::Internet.safe_email }], - web_pages: [{ type: ['profile', 'blog', 'homepage', 'work'].sample, url: Faker::Internet.url('example.com') }], - web_page: { type: ['profile', 'blog', 'homepage', 'work'].sample, url: Faker::Internet.url('example.com') }, -} -contact = api.contacts.create(data) - -# Setting picture_url creates a picture for the contact hosted on nylas server -demonstrate { contact.picture_url } - - -# Searching contacts! -demonstrate do - api.contacts.where(email: contact.emails.first.email, - #country: contact.physical_addresses.first.country, - phone_number: contact.phone_numbers.first.number, - street_address: contact.physical_addresses.first.street_address).map(&:to_h) - -end - -# Retrieve all pages of contacts -demonstrate { api.contacts.limit(200).find_each.map(&:to_h) } - -demonstrate { contact.update(surname: Faker::Name.last_name) } - -# Retrieving a contact by ID -same_contact_different_instance = demonstrate { api.contacts.find(contact.id) } - -# Updating a found contact -demonstrate do - same_contact_different_instance.update(surname: Faker::Name.last_name) - same_contact_different_instance.surname -end - -# Reloading a contact -demonstrate { contact.reload } -demonstrate { contact.surname } - -# You may download the contacts picture. -contact_with_picture = api.contacts.where(email: 'contact-with-picture@example.com').first -demonstrate { contact_with_picture.picture_url } -begin -demonstrate { contact_with_picture.picture } -rescue Nylas::ResourceNotFound - puts "That contacts picture didn't propagate yet :/" -end - - -# Destroying a contact -demonstrate { contact.destroy } diff --git a/examples/plain-ruby/deltas.rb b/examples/plain-ruby/deltas.rb deleted file mode 100644 index 5e8fa4cf..00000000 --- a/examples/plain-ruby/deltas.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas # -# Deltas API. -# See https://docs.nylas.com/reference#deltas -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - - -# Retrieves the latest colletion of deltas -latest_deltas = demonstrate { api.deltas.latest.class } - -# Retrieves a particular cursor -deltas_from_cursor = demonstrate { api.deltas.since(ENV['NYLAS_PREVIOUS_CURSOR']) } - -# Get the deltas metadata -demonstrate { deltas_from_cursor.cursor_end } -demonstrate { deltas_from_cursor.cursor_start } -demonstrate { deltas_from_cursor.count } -# Retrieves the latest cursor -demonstrate { api.deltas.latest_cursor } - - -# Retrieving multiple pages of deltas -demonstrate { deltas_from_cursor.find_each.map(&:id).count } - -# 5 delta's -demonstrate { deltas_from_cursor.take(5).map(&:to_h) } - -# Models are cast to Nylas::Model objects -demonstrate { deltas_from_cursor.first&.model&.class } - -# And can be viewed directly -demonstrate { deltas_from_cursor.first&.to_h } diff --git a/examples/plain-ruby/drafts.rb b/examples/plain-ruby/drafts.rb deleted file mode 100644 index b71f790f..00000000 --- a/examples/plain-ruby/drafts.rb +++ /dev/null @@ -1,43 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas -# Drafts API. See https://docs.nylas.com/reference#drafts for API documentation -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Creating a draft -demonstrate do - example_draft = api.drafts.create(subject: "A new draft!") - example_draft.to_h -end - -# Retrieving a count of drafts -demonstrate { api.drafts.count } - -# Retrieving drafts as a collection draft -demonstrate { api.drafts.limit(2).map(&:to_h) } -example_draft = api.drafts.first - -# Retrieving a particular drafts -demonstrate { api.drafts.find(example_draft.id) } - -# Sending a draft -demonstrate do - draft = api.drafts.create(to: [{ email: ENV.fetch('NYLAS_EXAMPLE_EMAIL', 'not-a-real-email@example.com')}], - subject: "A new draft!", - metadata: {test: "yes"}) - draft.send! -end - -# Updating a draft -demonstrate do - example_draft.to << { name: "Other person", email: "other@example.com" } - example_draft.save - api.drafts.find(example_draft.id).to.map(&:to_h) -end - -# Destroying a draft - -demonstrate do - example_draft.destroy -end diff --git a/examples/plain-ruby/events.rb b/examples/plain-ruby/events.rb deleted file mode 100644 index 3aa1b95c..00000000 --- a/examples/plain-ruby/events.rb +++ /dev/null @@ -1,81 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas -# Events API. -# See https://docs.nylas.com/reference#events -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Counting the events -demonstrate { api.events.count } - -# Retrieving a few events -demonstrate { api.events.limit(2).map(&:to_h) } - -# Expand recurring events into independent event objects -demonstrate { api.events.expand_recurring.map(&:to_h) } - -# Include cancelled events -demonstrate { api.events.show_cancelled.map(&:to_h) } - -# Retrieving a particular event -example_event = api.events.last -demonstrate { api.events.find(example_event.id).to_h } - -calendar = api.calendars.reject(&:read_only?).first -# Creating an event -demonstrate { api.events.create(title: "A fun event!", location: "The Party Zone", calendar_id: calendar.id, - when: { start_time: Time.now + 60, end_time: Time.now + 120 }).to_h } - -example_event = api.events.where(location: "The Party Zone").last - -# Updating an event -demonstrate do example_event.update( - location: "Somewhere else!", - metadata: { - event_type: "gathering" - } -) -end -demonstrate { api.events.find(example_event.id).location } -demonstrate { api.events.where(metadata_pair:{"event_type": "gathering"}).last.metadata[:event_type] } - -# TODO::Uncomment below when job status support is implemented -# as we can't delete an event with conferencing/notifications -# until the job status is complete. -# -# Adding conferencing and notifications -# demonstrate do example_event.update( -# conferencing:{ -# provider: "Zoom Meeting", -# autocreate:{} -# }, -# notifications: [{ -# type: "email", -# minutes_before_event: 600, -# subject: "Test Event Notification", -# body: "Reminding you about our meeting." -# }] -# ) -# end -# -# TODO::Add some sort of loop until - -# Deleting an event -demonstrate { example_event.destroy } - -# RSVPing to an Event -calendar = api.calendars.select { |c| c.name == "Emailed events" }.first -event = calendar.events.first -event.rsvp(:yes, notify_participants: true) -event.rsvp(:no, notify_participants: true) -event.rsvp(:maybe, notify_participants: true) - -# Generating an ICS File -demonstrate { event.generate_ics } - -demonstrate { event.generate_ics( - ical_uid: "test_uuid", - method: "add", - prodid: "test_prodid" -) } diff --git a/examples/plain-ruby/files.rb b/examples/plain-ruby/files.rb deleted file mode 100644 index c3c40a5b..00000000 --- a/examples/plain-ruby/files.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas Files -# API. -# See https://docs.nylas.com/reference#files -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Listing files -demonstrate { api.files.limit(2).map(&:to_h) } - -# Retrieving file metadata -example_file = api.files.first -demonstrate { api.files.find(example_file.id).to_h } - -# Downloading a particular file -demonstrate { example_file.download } - -# Downloading a particular file is cached. Notice the path didn't change -demonstrate { example_file.download } - -# Re-downloading a file, notice the path does change. -demonstrate { example_file.download! } - -# Uploading a file -demonstrate do - api.files.create(file: File.open(File.expand_path(__FILE__), 'r')).to_h -end diff --git a/examples/plain-ruby/folders.rb b/examples/plain-ruby/folders.rb deleted file mode 100644 index 2f005646..00000000 --- a/examples/plain-ruby/folders.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It -# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_FOLDER_USERS_ACCESS_TOKEN']) - -# Retrieving the count of folders -demonstrate { api.folders.count } - -# Retrieving a list of folders -demonstrate { api.folders.map(&:to_h) } -folder = api.folders.last - -# Retrieving a folder by ID -demonstrate { api.folders.find(folder.id).to_h } - -# Creating a folder -demonstrate { api.folders.create(display_name: "Example folder").to_h } - -example_folders = api.folders.select do |folder| - folder.display_name == "Example folder" -end - -# Changing a folder -folder_to_change = example_folders.first -demonstrate { folder_to_change.update(display_name: "Changed name") } -demonstrate { api.folders.find(folder_to_change.id).to_h } - - -# Destroying the folder -demonstrate { folder_to_change.destroy } diff --git a/examples/plain-ruby/job_status.rb b/examples/plain-ruby/job_status.rb deleted file mode 100644 index ad80b460..00000000 --- a/examples/plain-ruby/job_status.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas -# Drafts API. See https://docs.nylas.com/reference#drafts for API documentation -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Getting all job statuses -demonstrate { api.job_statuses } - -# Get a specific job status -demonstrate do - job_status = api.job_statuses.first - api.job_statuses.find(job_status.job_status_id).to_h -end - -# Get a boolean value representing status -demonstrate { api.job_statuses.first.successful? } \ No newline at end of file diff --git a/examples/plain-ruby/labels.rb b/examples/plain-ruby/labels.rb deleted file mode 100644 index 43621fe7..00000000 --- a/examples/plain-ruby/labels.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It -# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Retrieving the count of labels -demonstrate { api.labels.count } - -# Retrieving a list of labels -demonstrate { api.labels.map(&:to_h) } -label = api.labels.last - -# Retrieving a label by ID -demonstrate { api.labels.find(label.id).to_h } - -# Creating a label -demonstrate { api.labels.create(display_name: "Example label").to_h } - -example_labels = api.labels.select do |label| - label.display_name == "Example label" -end - -# Changing a label -label_to_change = example_labels.first -demonstrate { label_to_change.update(display_name: "Changed name") } -demonstrate { api.labels.find(label_to_change.id).to_h } - - -# Destroying the label -demonstrate { label_to_change.destroy } diff --git a/examples/plain-ruby/messages.rb b/examples/plain-ruby/messages.rb deleted file mode 100644 index 30b6e52f..00000000 --- a/examples/plain-ruby/messages.rb +++ /dev/null @@ -1,48 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas -# Messages API. See https://docs.nylas.com/reference#messages for API documentation -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Retrieving a count of messages -demonstrate { api.messages.count } - -# Retrieving a message -demonstrate { api.messages.first.to_h } - -# Retrieving an expanded message -demonstrate { api.messages.expanded.first.to_h } - -message = api.messages.first -# Retrieving a raw message -demonstrate { api.messages.raw.find(message.id) } - -# Starring and marking a message as unread -demonstrate { message.update(starred: true, unread: true) } -reloaded_message = api.messages.first -demonstrate { { starred: reloaded_message.starred, unread: reloaded_message.unread } } - -# Messages cannot be created -demonstrate do - begin - api.messages.create - rescue Nylas::ModelNotCreatableError => e - "#{e.class}: #{e.message}" - end -end - -# Messages cannot be destroyed -message = api.messages.first -demonstrate do - begin - message.destroy - rescue Nylas::ModelNotDestroyableError => e - "#{e.class}: #{e.message}" - end -end - -# Messages may be searched. -# See https://docs.nylas.com/reference#messages-search and https://docs.nylas.com/reference#search -demonstrate { api.messages.search("That really important email").map(&:to_h) } - diff --git a/examples/plain-ruby/neural.rb b/examples/plain-ruby/neural.rb deleted file mode 100644 index 6fd558da..00000000 --- a/examples/plain-ruby/neural.rb +++ /dev/null @@ -1,57 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It -# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -message_id = api.messages.first.id - -# Perform sentiment analysis on a string -sentiment = api.neural.sentiment_analysis_text("Hello world") -demonstrate { sentiment.to_h } - -# Perform sentiment analysis on a message -sentiments = api.neural.sentiment_analysis_message([message_id]) -demonstrate { sentiments[0].to_h } - -# Perform extracting a signature and parsing its contact information -signatures = api.neural.extract_signature([message_id]) -demonstrate { signatures[0].to_h } -# Convert the parsed contact to a Nylas contact object -contact = signatures[0].contacts.to_contact_object -demonstrate { contact.to_h } - -# Perform OCR request on a page (with a page range) -file = api.files.first -if file.nil? - puts "No file was found" -else - begin - file_id = api.files.first.id - # Optionally you can add a range, like below, of the pages OCR can be performed on - # Also just pass in the file ID without a range to perform OCR on all pages - ocr = api.neural.ocr_request(file_id, [1]) - demonstrate { ocr.to_h } - rescue Nylas::Error => e - puts "#{e.class}: #{e.message}" - end -end - -# Perform category analysis on a message -categorize_list = api.neural.categorize([message_id]) -demonstrate { categorize_list[0].to_h } -# Re-categorize the message to a different category -categorize = categorize_list[0].recategorize("conversation") -demonstrate { categorize.to_h } - -# Clean the conversation of a message -conversations = api.neural.clean_conversation([message_id]) -demonstrate { conversations[0].to_h } -# Provide some options to the endpoint -options = Nylas::NeuralMessageOptions.new(ignore_images: false) -conversations = api.neural.clean_conversation([message_id], options) -demonstrate { conversations[0].to_h } -# Parse the images from the clean conversation -extracted_images = conversations[0].extract_images -demonstrate { extracted_images } diff --git a/examples/plain-ruby/outbox.rb b/examples/plain-ruby/outbox.rb deleted file mode 100644 index 4f2364bd..00000000 --- a/examples/plain-ruby/outbox.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../helpers' -require 'date' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It -# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Prepare the draft and timestamps -draft = Nylas::Draft.new(to: [{ email: ENV.fetch('NYLAS_EXAMPLE_EMAIL', 'not-a-real-email@example.com'), name: "Me" }], - subject: "A new draft!", - metadata: {sdk: "Ruby SDK"}) -tomorrow = Date.today + 1 -day_after = tomorrow + 1 - -# Send the message to the outbox -outbox_job_status = demonstrate { api.outbox.send(draft, send_at: tomorrow.to_time.to_i, retry_limit_datetime: day_after.to_time.to_i) } - -# You can update the draft directly and use that object -demonstrate do - draft.subject = "Another Updated Subject" - api.outbox.update(outbox_job_status.job_status_id, message: draft) -end - -# Or, you can update the outbox message using the OutboxMessage object directly in the Job Status -demonstrate do - job_status = api.job_statuses.find(outbox_job_status.job_status_id) - message = job_status.original_data - message.subject = "Updated Subject" - api.outbox.update(outbox_job_status.job_status_id, message: message) -end - -# Delete the outbox draft status -demonstrate { api.outbox.delete(outbox_job_status.job_status_id) } diff --git a/examples/plain-ruby/room_resource.rb b/examples/plain-ruby/room_resource.rb deleted file mode 100644 index ebc33788..00000000 --- a/examples/plain-ruby/room_resource.rb +++ /dev/null @@ -1,9 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It -# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Retrieving a list of room resources -demonstrate { api.room_resources.map(&:to_h) } diff --git a/examples/plain-ruby/scheduler.rb b/examples/plain-ruby/scheduler.rb deleted file mode 100644 index d5d65692..00000000 --- a/examples/plain-ruby/scheduler.rb +++ /dev/null @@ -1,78 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas -# Scheduler API. -# See https://developer.nylas.com/docs/api/scheduler/#overview -nylas = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Create a scheduler page -demonstrate { nylas.scheduler.create(access_tokens: [ENV['NYLAS_ACCESS_TOKEN']], name: "Ruby SDK Example", slug: "ruby_example_#{Time.now.to_i}") } - -# List all scheduler pages -demonstrate { nylas.scheduler } - -# Return a specific scheduler page -example_scheduler = nylas.scheduler.last -demonstrate { nylas.scheduler.find(example_scheduler.id).to_h } - -# Modify a specific scheduler page -demonstrate do example_scheduler.update( - name: "Updated name" -) -end -demonstrate { example_scheduler.name } - -# Get available calendars -demonstrate { example_scheduler.get_available_calendars } - -# Upload an image -demonstrate { example_scheduler.upload_image(content_type: "image/png", object_name: "test.png") } - -# Get Google Availability -begin - demonstrate { nylas.scheduler.get_google_availability } -rescue Nylas::Error => e - puts "#{e.class}: #{e.message}" -end - -# Get Office 365 Availability -begin - demonstrate { nylas.scheduler.get_office_365_availability } -rescue Nylas::Error => e - puts "#{e.class}: #{e.message}" -end - -# Get a Scheduler page by Slug -demonstrate { nylas.scheduler.get_page_slug(example_scheduler.slug) } - -# Get all available time slots -available_timeslots = nylas.scheduler.get_available_time_slots(example_scheduler.slug) -demonstrate { available_timeslots.inspect } - -# Book a timeslot -booking_request = Nylas::SchedulerBookingRequest.new( - additional_values: { - important: "true" - }, - email: "recipient@example.com", - locale: "en_US", - name: "John Doe", - timezone: "America/New_York", - slot: available_timeslots[0] -) -booking_confirmation = nylas.scheduler.book_time_slot(example_scheduler.slug, booking_request) -demonstrate { booking_confirmation.inspect } - -# Cancel a booking -demonstrate { nylas.scheduler.cancel_booking(example_scheduler.slug, booking_confirmation.edit_hash, "Was just a test.") } - -# Confirm a booking (Expect an error because we already cancelled this meeting) -begin - demonstrate { nylas.scheduler.confirm_booking(example_scheduler.slug, booking_confirmation.edit_hash) } -rescue Nylas::Error => e - puts "#{e.class}: #{e.message}" -end - -# Delete a scheduler page -demonstrate { example_scheduler.destroy } diff --git a/examples/plain-ruby/sending-messages.rb b/examples/plain-ruby/sending-messages.rb deleted file mode 100644 index a12f2a9e..00000000 --- a/examples/plain-ruby/sending-messages.rb +++ /dev/null @@ -1,34 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to send messages via the API -# See https://docs.nylas.com/reference#sending -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - -# Sending a message as a hash -demonstrate do - api.send!(to: [{ email: ENV.fetch('NYLAS_EXAMPLE_EMAIL', 'not-a-real-email@example.com'), - name: "An example recipient" }], - subject: "you've got mail!", - body: "It's a really good mail!").to_h -end - -# Sending a message by instantiating a message instance -demonstrate do - message = Nylas::NewMessage.new(to: [{ email: ENV.fetch('NYLAS_EXAMPLE_EMAIL', 'not-a-real-email@example.com'), - name: "An example recipient" }], - subject: "you've got another mail!", - body: "It's a really good another mail!", api: api) - message.send!.to_h -end - -# Sending a message as a mime string -# -demonstrate do - message_string = "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\n" \ - "Subject: A mime email\n" \ - "From: You \n" \ - "To: You <#{ENV.fetch('NYLAS_EXAMPLE_EMAIL', 'not-real@example.com')}>\n\n" \ - "This is the body of the message sent as a raw mime!" - api.send!(message_string) -end diff --git a/examples/plain-ruby/streaming.rb b/examples/plain-ruby/streaming.rb deleted file mode 100644 index b15bddd5..00000000 --- a/examples/plain-ruby/streaming.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to listen for streamed Deltas -# See https://docs.nylas.com/reference#streaming-delta-updates -require 'nylas-streaming' - -puts "Once this starts, it will listen forever, hit ctrl+c to move forward in the examples listening!" -def interactive_stream(include_types: [], exclude_types: []) - EventMachine.run do - puts "Hit enter to listen for events with include_types #{include_types} and exclude_types " \ - "#{exclude_types}" - gets - Signal.trap("INT") do - puts "Done listening for events with include_types #{include_types} and exclude_types #{exclude_types}!" - EventMachine.stop - end - Signal.trap("TERM") { EventMachine.stop } - - api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - Nylas::Streaming.deltas(api: api, cursor: ENV['NYLAS_PREVIOUS_CURSOR'], - include_types: include_types, exclude_types: exclude_types) do |delta| - puts "#{delta.event} of #{delta.object} #{delta.model.id} as a #{delta.class}" - end - - end -end - -interactive_stream - -interactive_stream(include_types:['message']) -interactive_stream(exclude_types:['message']) diff --git a/examples/plain-ruby/threads.rb b/examples/plain-ruby/threads.rb deleted file mode 100644 index 7123075e..00000000 --- a/examples/plain-ruby/threads.rb +++ /dev/null @@ -1,48 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It -# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference). -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'], - access_token: ENV['NYLAS_ACCESS_TOKEN']) - - -# How many threads are there? -demonstrate { api.threads.count } - -thread = api.threads.first -# Threads have quite a bit of information -demonstrate { thread.to_h } - -# Threads may be expanded -# demonstrate { api.threads.expanded.first } - -# Threads may have their unread/starred statuses updated -demonstrate { thread.update(starred: true, unread: true) } -reloaded_thread = api.threads.first -demonstrate { { starred: reloaded_thread.starred, unread: reloaded_thread.unread } } - -# Threads cannot be created -demonstrate do - begin - api.threads.create - rescue Nylas::ModelNotCreatableError => e - "#{e.class}: #{e.message}" - end -end - - - -# Threads may not be destroyed -demonstrate do - begin - thread.destroy - rescue Nylas::ModelNotDestroyableError => e - "#{e.class}: #{e.message}" - end -end - - -# Threads may be searched. -# See https://docs.nylas.com/reference#search-threads and https://docs.nylas.com/reference#search -demonstrate { api.threads.search("That really important email").map(&:to_h) } - diff --git a/examples/plain-ruby/webhooks.rb b/examples/plain-ruby/webhooks.rb deleted file mode 100644 index 3ff11a0a..00000000 --- a/examples/plain-ruby/webhooks.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative '../helpers' - -# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas -# Webhooks API. See https://docs.nylas.com/reference#webhooks for API documentation -api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET']) - - -# Webhooks can be retrieved as a collection -demonstrate { api.webhooks.map(&:to_h) } - -# Or independently -example_webhook = api.webhooks.first -demonstrate { api.webhooks.find(example_webhook.id).to_h } - -# Create a webhook -demonstrate do - api.webhooks.create( - callback_url: ENV['NYLAS_WEBHOOK_URL'], - state: WebhookState::ACTIVE, - triggers: [WebhookTrigger::EVENT_CREATED], - ) -end - -# Update the status of the webhook -created_webhook = api.webhooks.last -demonstrate { created_webhook.update(WebhookState::INACTIVE) } - -# Delete webhook -demonstrate { created_webhook.destroy } diff --git a/gem_config.rb b/gem_config.rb index 5f373170..1585b54b 100644 --- a/gem_config.rb +++ b/gem_config.rb @@ -4,21 +4,21 @@ # Consistently apply nylas' standard gem data across gems module GemConfig - def self.apply(gem, name) - gem.name = name - gem.files = Dir.glob("lib/{#{name}.rb,#{name}/**/*.rb}") + def self.apply(gem) + gem.description = %(Gem for interacting with the Nylas API.) + gem.files = Dir.glob("lib/{nylas.rb,nylas/**/*.rb}") gem.license = "MIT" gem.version = Nylas::VERSION gem.platform = "ruby" - gem.required_ruby_version = ">= 2.3" - append_nylas_data(gem) + gem.required_ruby_version = ">= 3.0" + gem.metadata = metadata + add_author_info(gem) dev_dependencies.each do |dependency| gem.add_development_dependency(*dependency) end end - def self.append_nylas_data(gem) - gem.metadata = metadata + def self.add_author_info(gem) gem.email = "support@nylas.com" gem.authors = ["Nylas, Inc."] end @@ -27,32 +27,26 @@ def self.metadata { "bug_tracker_uri" => "https://github.com/nylas/nylas-ruby/issues", "changelog_uri" => "https://github.com/nylas/nylas-ruby/blob/master/CHANGELOG.md", - "documentation_uri" => "http://www.rubydoc.info/gems/nylas", + "documentation_uri" => "https://developer.nylas.com/docs/sdks/ruby/", "homepage_uri" => "https://www.nylas.com", "source_code_uri" => "https://github.com/nylas/nylas-ruby", - "wiki_uri" => "https://github.com/nylas/nylas-ruby/wiki" + "github_repo" => "https://github.com/nylas/nylas-ruby" } end def self.dev_dependencies [["bundler", ">= 1.3.0"], - ["yard", "~> 0.9.0"], - ["awesome_print", "~> 1.0"], - ["rubocop", "~> 1.24.1"], - ["rubocop-rspec", "~> 2.7.0"], - ["overcommit", "~> 0.41"]] + testing_and_debugging_dependencies + ["yard", "~> 0.9.34"], + ["rubocop", "~> 1.51"], + ["rubocop-rspec", "~> 2.22"]] + testing_and_debugging_dependencies end def self.testing_and_debugging_dependencies - [["pry", "~> 0.14.1"], - ["pry-nav", "~> 1.0.0"], - ["pry-stack_explorer", "~> 0.4.9.3"], - ["rspec", "~> 3.7"], - ["rspec-json_matcher", "~> 0.1"], - ["webmock", "~> 3.0"], - ["faker", "~> 1.8"], - ["informed", "~> 1.0"], - ["simplecov", "~> 0.21.2"], - ["simplecov-cobertura", "~> 2.1.0"]] + [["rspec", "~> 3.12"], + ["rspec-json_matcher", "~> 0.2.0"], + ["webmock", "~> 3.18", ">= 3.18.1"], + ["simplecov", "~> 0.22.0"], + ["simplecov-cobertura", "~> 2.1.0"], + ["webrick", "~> 1.8", ">= 1.8.1"]] end end diff --git a/gemfiles/Gemfile.rails5 b/gemfiles/Gemfile.rails5 deleted file mode 100644 index 28c795f9..00000000 --- a/gemfiles/Gemfile.rails5 +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' - -gem 'rails', '>= 5.2.8.1' - -gemspec path: "..", name: 'nylas-streaming' diff --git a/gemfiles/Gemfile.rails6 b/gemfiles/Gemfile.rails6 deleted file mode 100644 index fd92df76..00000000 --- a/gemfiles/Gemfile.rails6 +++ /dev/null @@ -1,6 +0,0 @@ -source 'https://rubygems.org' - -gem 'rails', '~> 6' - -# Load all gems from `gemspec` file. -gemspec path: "..", name: 'nylas-streaming' diff --git a/gemfiles/Gemfile.rest-client.1 b/gemfiles/Gemfile.rest-client.1 deleted file mode 100644 index 057853ce..00000000 --- a/gemfiles/Gemfile.rest-client.1 +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' - -gem 'rest-client', '~> 1.6' - -gemspec path: "..", name: 'nylas-streaming' diff --git a/gemfiles/Gemfile.rest-client.2 b/gemfiles/Gemfile.rest-client.2 deleted file mode 100644 index 0bbf7185..00000000 --- a/gemfiles/Gemfile.rest-client.2 +++ /dev/null @@ -1,5 +0,0 @@ -source 'https://rubygems.org' - -gem 'rest-client', '~> 2.0' - -gemspec path: "..", name: 'nylas-streaming' diff --git a/gemfiles/Gemfile.rubocop b/gemfiles/Gemfile.rubocop deleted file mode 100644 index 90d734f0..00000000 --- a/gemfiles/Gemfile.rubocop +++ /dev/null @@ -1,4 +0,0 @@ -source 'https://rubygems.org' - -gem 'rubocop' -gem 'rubocop-rspec' diff --git a/lib/nylas-streaming.rb b/lib/nylas-streaming.rb deleted file mode 100644 index 867c991a..00000000 --- a/lib/nylas-streaming.rb +++ /dev/null @@ -1,81 +0,0 @@ -# frozen_string_literal: true - -require "yajl" -require "em-http" -require "nylas" - -module Nylas - # Provides methods to work with the Nylas Streaming Deltas API - # @see https://docs.nylas.com/reference#streaming-delta-updates - module Streaming - # @see Nylas::Streaming::DeltaStream#initialize - def self.deltas(**kwargs, &callback) - DeltaStream.new(**kwargs).stream(&callback) - end - - # A live stream of deltas that stays open until explicitely closed - class DeltaStream - attr_accessor :cursor, :api, :exclude_types, :include_types, :expanded, - :connect_timeout, :inactivity_timeout - - # @param cursor [String] Cursor to start listening for changes on - # @param api [Nylas::API] - # @param expanded [Boolean] Expands threads and messages - # @param exclude_types [Array] List of Object types *not* to include in the stream - # @param include_types [Array] List of Object types to exclusively include in the stream - # @param connect_timeout [Integer] How long to wait before timing out on attempted connection - # @param inactivity_timeout [Integer] How long to wait before timing out on inactivity - def initialize(cursor:, api:, exclude_types: [], include_types: [], expanded: false, connect_timeout: 0, - inactivity_timeout: 0) - self.cursor = cursor - self.api = api - self.exclude_types = exclude_types - self.include_types = include_types - self.expanded = expanded - self.connect_timeout = connect_timeout - self.inactivity_timeout = inactivity_timeout - end - - def stream - parser.on_parse_complete = lambda do |data| - begin - yield(Types.registry[:delta].cast(data.merge(api: api))) - rescue Nylas::Error => e - Nylas::Logging.logger.error(e) - raise e - end - end - - listener.stream { |chunk| parser << chunk } - end - - def url - "#{api.client.url_for_path('/delta/streaming')}?#{query}" - end - - def query - query = ["cursor=#{cursor}"] - query << "view=expanded" if expanded - query << "include_types=#{include_types.join(',')}" unless include_types.empty? - query << "exclude_types=#{exclude_types.join(',')}" unless exclude_types.empty? - query.join("&") - end - - def listener - @listener ||= EventMachine::HttpRequest.new(url, connect_timeout: connect_timeout, - inactivity_timeout: inactivity_timeout).get - end - - def http_error_handler(client) - raise Nylas::Error, client.error - end - - def parser - return @parser if @parser - - @parser = Yajl::Parser.new(symbolize_keys: true) - @parser - end - end - end -end diff --git a/lib/nylas.rb b/lib/nylas.rb index 86f1c992..b0375607 100644 --- a/lib/nylas.rb +++ b/lib/nylas.rb @@ -7,15 +7,14 @@ # See https://github.com/sparklemotion/http-cookie/issues/27 # and https://github.com/sparklemotion/http-cookie/issues/6 # -# CookieJar uses unsafe class caching for dynamically loading cookie jars -# If 2 rest-client instances are instantiated at the same time, (in threads) -# non-deterministic behaviour can occur whereby the Hash cookie jar isn't -# properly loaded and cached. -# Forcing an instantiation of the jar onload will force the CookieJar to load -# before the system has a chance to spawn any threads. -# Note this should technically be fixed in rest-client itself however that -# library appears to be stagnant so we're forced to fix it here -# This object should get GC'd as it's not referenced by anything +# CookieJar uses unsafe class caching for dynamically loading cookie jars. +# If two rest-client instances are instantiated at the same time (in threads), non-deterministic +# behaviour can occur whereby the Hash cookie jar isn't properly loaded and cached. +# Forcing an instantiation of the jar onload will force the CookieJar to load before the system has +# a chance to spawn any threads. +# Note that this should technically be fixed in rest-client itself, however that library appears to +# be stagnant so we're forced to fix it here. +# This object should get GC'd as it's not referenced by anything. HTTP::CookieJar.new require "ostruct" @@ -23,142 +22,26 @@ require_relative "nylas/version" require_relative "nylas/errors" - -require_relative "nylas/logging" -require_relative "nylas/registry" -require_relative "nylas/types" -require_relative "nylas/constraints" - -require_relative "nylas/http_client" -require_relative "nylas/api" -require_relative "nylas/collection" -require_relative "nylas/model" - -# Attribute types supported by the API -require_relative "nylas/email_address" -require_relative "nylas/event" -require_relative "nylas/file" -require_relative "nylas/folder" -require_relative "nylas/im_address" -require_relative "nylas/label" -require_relative "nylas/message_headers" -require_relative "nylas/message_tracking" -require_relative "nylas/participant" -require_relative "nylas/physical_address" -require_relative "nylas/phone_number" -require_relative "nylas/recurrence" -require_relative "nylas/rsvp" -require_relative "nylas/timespan" -require_relative "nylas/web_page" -require_relative "nylas/nylas_date" -require_relative "nylas/when" -require_relative "nylas/free_busy" -require_relative "nylas/time_slot" -require_relative "nylas/time_slot_capacity" -require_relative "nylas/open_hours" -require_relative "nylas/event_conferencing" -require_relative "nylas/event_conferencing_details" -require_relative "nylas/event_conferencing_autocreate" -require_relative "nylas/event_notification" -require_relative "nylas/component" - -# Custom collection types -require_relative "nylas/event_collection" -require_relative "nylas/search_collection" -require_relative "nylas/deltas_collection" -require_relative "nylas/free_busy_collection" -require_relative "nylas/calendar_collection" -require_relative "nylas/component_collection" -require_relative "nylas/scheduler_collection" -require_relative "nylas/job_status_collection" -require_relative "nylas/outbox" - -# Models supported by the API -require_relative "nylas/account" -require_relative "nylas/calendar" -require_relative "nylas/contact" -require_relative "nylas/contact_group" -require_relative "nylas/current_account" -require_relative "nylas/deltas" -require_relative "nylas/delta" -require_relative "nylas/draft" -require_relative "nylas/message" -require_relative "nylas/room_resource" -require_relative "nylas/new_message" -require_relative "nylas/raw_message" -require_relative "nylas/thread" -require_relative "nylas/webhook" -require_relative "nylas/scheduler" -require_relative "nylas/job_status" -require_relative "nylas/token_info" -require_relative "nylas/application_details" -require_relative "nylas/outbox_message" -require_relative "nylas/outbox_job_status" -require_relative "nylas/send_grid_verified_status" - -# Neural specific types -require_relative "nylas/neural" -require_relative "nylas/neural_sentiment_analysis" -require_relative "nylas/neural_ocr" -require_relative "nylas/neural_categorizer" -require_relative "nylas/neural_clean_conversation" -require_relative "nylas/neural_contact_link" -require_relative "nylas/neural_contact_name" -require_relative "nylas/neural_signature_contact" -require_relative "nylas/neural_signature_extraction" -require_relative "nylas/neural_message_options" -require_relative "nylas/categorize" -require_relative "nylas/scheduler_config" -require_relative "nylas/scheduler_time_slot" -require_relative "nylas/scheduler_booking_request" -require_relative "nylas/scheduler_booking_confirmation" - -require_relative "nylas/native_authentication" - -require_relative "nylas/filter_attributes" - -require_relative "nylas/services/tunnel" -# an SDK for interacting with the Nylas API -# @see https://docs.nylas.com/reference -module Nylas - Types.registry[:account] = Types::ModelType.new(model: Account) - Types.registry[:calendar] = Types::ModelType.new(model: Calendar) - Types.registry[:contact] = Types::ModelType.new(model: Contact) - Types.registry[:delta] = DeltaType.new - Types.registry[:draft] = Types::ModelType.new(model: Draft) - Types.registry[:email_address] = Types::ModelType.new(model: EmailAddress) - Types.registry[:event] = Types::ModelType.new(model: Event) - Types.registry[:file] = Types::ModelType.new(model: File) - Types.registry[:folder] = Types::ModelType.new(model: Folder) - Types.registry[:im_address] = Types::ModelType.new(model: IMAddress) - Types.registry[:label] = Types::ModelType.new(model: Label) - Types.registry[:room_resource] = Types::ModelType.new(model: RoomResource) - Types.registry[:message] = Types::ModelType.new(model: Message) - Types.registry[:message_headers] = MessageHeadersType.new - Types.registry[:message_tracking] = Types::ModelType.new(model: MessageTracking) - Types.registry[:participant] = Types::ModelType.new(model: Participant) - Types.registry[:physical_address] = Types::ModelType.new(model: PhysicalAddress) - Types.registry[:phone_number] = Types::ModelType.new(model: PhoneNumber) - Types.registry[:recurrence] = Types::ModelType.new(model: Recurrence) - Types.registry[:thread] = Types::ModelType.new(model: Thread) - Types.registry[:timespan] = Types::ModelType.new(model: Timespan) - Types.registry[:web_page] = Types::ModelType.new(model: WebPage) - Types.registry[:nylas_date] = NylasDateType.new - Types.registry[:contact_group] = Types::ModelType.new(model: ContactGroup) - Types.registry[:when] = Types::ModelType.new(model: When) - Types.registry[:time_slot] = Types::ModelType.new(model: TimeSlot) - Types.registry[:time_slot_capacity] = Types::ModelType.new(model: TimeSlotCapacity) - Types.registry[:event_conferencing] = Types::ModelType.new(model: EventConferencing) - Types.registry[:event_conferencing_details] = Types::ModelType.new(model: EventConferencingDetails) - Types.registry[:event_conferencing_autocreate] = Types::ModelType.new(model: EventConferencingAutocreate) - Types.registry[:event_notification] = Types::ModelType.new(model: EventNotification) - Types.registry[:neural] = Types::ModelType.new(model: Neural) - Types.registry[:categorize] = Types::ModelType.new(model: Categorize) - Types.registry[:neural_signature_contact] = Types::ModelType.new(model: NeuralSignatureContact) - Types.registry[:neural_contact_link] = Types::ModelType.new(model: NeuralContactLink) - Types.registry[:neural_contact_name] = Types::ModelType.new(model: NeuralContactName) - Types.registry[:scheduler_config] = Types::ModelType.new(model: SchedulerConfig) - Types.registry[:scheduler_time_slot] = Types::ModelType.new(model: SchedulerTimeSlot) - Types.registry[:job_status] = Types::ModelType.new(model: JobStatus) - Types.registry[:outbox_message] = Types::ModelType.new(model: OutboxMessage) -end +require_relative "nylas/client" +require_relative "nylas/config" + +require_relative "nylas/handler/http_client" + +require_relative "nylas/resources/applications" +require_relative "nylas/resources/attachments" +require_relative "nylas/resources/auth" +require_relative "nylas/resources/calendars" +require_relative "nylas/resources/connectors" +require_relative "nylas/resources/contacts" +require_relative "nylas/resources/credentials" +require_relative "nylas/resources/drafts" +require_relative "nylas/resources/events" +require_relative "nylas/resources/folders" +require_relative "nylas/resources/grants" +require_relative "nylas/resources/messages" +require_relative "nylas/resources/smart_compose" +require_relative "nylas/resources/threads" +require_relative "nylas/resources/redirect_uris" +require_relative "nylas/resources/webhooks" + +require_relative "nylas/utils/file_utils" diff --git a/lib/nylas/account.rb b/lib/nylas/account.rb deleted file mode 100644 index cec19799..00000000 --- a/lib/nylas/account.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -module Nylas - # Representation of the accounts for Account management purposes. - # @see https://docs.nylas.com/reference#account-management - class Account - include Model - self.listable = true - self.showable = true - self.updatable = true - self.destroyable = true - self.filterable = true - self.auth_method = HttpClient::AuthMethod::BASIC - - attribute :id, :string, read_only: true - attribute :account_id, :string, read_only: true - attribute :billing_state, :string, read_only: true - attribute :sync_state, :string, read_only: true - attribute :provider, :string, read_only: true - attribute :authentication_type, :string, read_only: true - - attribute :email, :string, read_only: true - attribute :trial, :boolean, read_only: true - attribute :metadata, :hash - - def upgrade - response = execute(method: :post, path: "#{resource_path}/upgrade") - response[:success] - end - - def downgrade - response = execute(method: :post, path: "#{resource_path}/downgrade") - response[:success] - end - - def revoke_all(keep_access_token: nil) - payload = JSON.dump(keep_access_token: keep_access_token) if keep_access_token - - response = execute(method: :post, path: "#{resource_path}/revoke-all", payload: payload) - response[:success] - end - - # Return information about an account's access token - # @param access_token [String] The access token to inquire about - # @return [TokenInfo] The access token information - def token_info(access_token) - payload = JSON.dump(access_token: access_token) - response = execute(method: :post, path: "#{resource_path}/token-info", payload: payload) - TokenInfo.new(**response) - end - - def self.resources_path(api:) - "/a/#{api.app_id}/accounts" - end - end -end diff --git a/lib/nylas/api.rb b/lib/nylas/api.rb deleted file mode 100644 index 2c260933..00000000 --- a/lib/nylas/api.rb +++ /dev/null @@ -1,265 +0,0 @@ -# frozen_string_literal: true - -module Nylas - # Methods to retrieve data from the Nylas API as Ruby objects - class API - attr_accessor :client - - extend Forwardable - def_delegators :client, :execute, :get, :post, :put, :delete, :app_id, :api_server - - include Logging - - # @param client [HttpClient] Http Client to use for retrieving data - # @param app_id [String] Your application id from the Nylas Dashboard - # @param app_secret [String] Your application secret from the Nylas Dashboard - # @param access_token [String] (Optional) Your users access token. - # @param api_server [String] (Optional) Which Nylas API Server to connect to. Only change this if - # you're using a self-hosted Nylas instance. - # @return [Nylas::API] - def initialize(client: nil, app_id: nil, app_secret: nil, access_token: nil, - api_server: "https://api.nylas.com") - self.client = client || HttpClient.new(app_id: app_id, app_secret: app_secret, - access_token: access_token, api_server: api_server) - end - - # @return [String] A Nylas access token for that particular user. - def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: nil, scopes: nil, - return_full_response: false) - NativeAuthentication.new(api: self).authenticate( - name: name, - email_address: email_address, - provider: provider, - settings: settings, - reauth_account_id: reauth_account_id, - scopes: scopes, - return_full_response: return_full_response - ) - end - - def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil, - provider: nil, redirect_on_error: nil, disable_provider_selection: nil) - params = { client_id: app_id, redirect_uri: redirect_uri, response_type: response_type, - login_hint: login_hint } - - params[:state] = state if state - params[:scopes] = scopes.join(",") if scopes - params[:provider] = provider if provider - params[:redirect_on_error] = redirect_on_error if redirect_on_error - params[:disable_provider_selection] = disable_provider_selection if disable_provider_selection - - "#{api_server}/oauth/authorize?#{URI.encode_www_form(params)}" - end - - # Exchanges an authorization code for an access token - # @param code [String] The authorization code to exchange - # @param return_full_response [Boolean] If true, returns the full response body instead of just the token - # @return [String | Hash] Returns just the access token as a string, or the full response as a hash - def exchange_code_for_token(code, return_full_response: false) - data = { - "client_id" => app_id, - "client_secret" => client.app_secret, - "grant_type" => "authorization_code", - "code" => code - } - - response = execute(method: :post, path: "/oauth/token", payload: data) - return_full_response ? response : response[:access_token] - end - - # @return [Collection] A queryable collection of Contacts - def contacts - @contacts ||= Collection.new(model: Contact, api: self) - end - - # @return [Collection] A queryable collection of Contact Groups - def contact_groups - @contact_groups ||= Collection.new(model: ContactGroup, api: self) - end - - # @return [CurrentAccount] The account details for whomevers access token is set - def current_account - prevent_calling_if_missing_access_token(:current_account) - CurrentAccount.from_hash(execute(method: :get, path: "/account"), api: self) - end - - # @return [Collection] A queryable collection of {Account}s - def accounts - @accounts ||= Collection.new(model: Account, api: as(client.app_secret)) - end - - # @return [CalendarCollection] A queryable collection of {Calendar}s - def calendars - @calendars ||= CalendarCollection.new(model: Calendar, api: self) - end - - # @return [DeltasCollection] A queryable collection of Deltas, which are themselves a collection. - def deltas - @deltas ||= DeltasCollection.new(api: self) - end - - # @return[Collection] A queryable collection of {Draft} objects - def drafts - @drafts ||= Collection.new(model: Draft, api: self) - end - - # @return [EventCollection] A queryable collection of {Event}s - def events - @events ||= EventCollection.new(model: Event, api: self) - end - - # @return [Collection] A queryable collection of {Folder}s - def folders - @folders ||= Collection.new(model: Folder, api: self) - end - - # @return [Collection] A queryable collection of {File}s - def files - @files ||= Collection.new(model: File, api: self) - end - - # @return [Collection