From 11c50cb640e2fcc9b9ebc38695c31916296d1d89 Mon Sep 17 00:00:00 2001 From: kraju3 Date: Wed, 2 Oct 2024 22:13:41 -0500 Subject: [PATCH 01/14] Scheduling API Client --- lib/nylas/resources/availability.rb | 22 ++++++++ lib/nylas/resources/bookings.rb | 77 +++++++++++++++++++++++++++ lib/nylas/resources/configurations.rb | 76 ++++++++++++++++++++++++++ lib/nylas/resources/scheduling.rb | 24 +++++++++ lib/nylas/resources/sessions.rb | 33 ++++++++++++ 5 files changed, 232 insertions(+) create mode 100644 lib/nylas/resources/availability.rb create mode 100644 lib/nylas/resources/bookings.rb create mode 100644 lib/nylas/resources/configurations.rb create mode 100644 lib/nylas/resources/scheduling.rb create mode 100644 lib/nylas/resources/sessions.rb diff --git a/lib/nylas/resources/availability.rb b/lib/nylas/resources/availability.rb new file mode 100644 index 00000000..8af639b2 --- /dev/null +++ b/lib/nylas/resources/availability.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require_relative "resource" +require_relative "../handler/api_operations" + +module Nylas + # Nylas Messages API + class Availability < Resource + include ApiOperations::Get + + # Return availabilities for a configuration. + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Array(Hash), String, String)] The list of configurations, API Request ID, + # and next cursor. + def list(query_params: nil) + get_list( + path: "#{api_uri}/v3/scheduling/availability", + query_params: query_params + ) + end + end +end diff --git a/lib/nylas/resources/bookings.rb b/lib/nylas/resources/bookings.rb new file mode 100644 index 00000000..bb3f6d02 --- /dev/null +++ b/lib/nylas/resources/bookings.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require_relative "resource" +require_relative "../handler/api_operations" + +module Nylas + # Nylas Messages API + class Bookings < Resource + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + include ApiOperations::Patch + + # Return a booking. + # @param booking_id [String] The id of the booking to return. + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Hash, String)] The booking and API request ID. + def find(booking_id:, query_params:) + get( + path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}", + query_params: query_params + ) + end + + # Create a booking. + # @param request_body [Hash] The values to create the booking with. + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Hash, String)] The created booking and API Request ID. + def create(request_body:, query_params:) + post( + path: "#{api_uri}/v3/scheduling/bookings", + request_body: request_body, + query_params: query_params + ) + end + + # Create a booking. + # @param request_body [Hash] The values to update the booking with. + # @param booking_id [String] The id of the booking to update. + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Hash, String)] The created booking and API Request ID. + def update(request_body:, booking_id:, query_params:) + patch( + path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}", + request_body: request_body, + query_params: query_params + ) + end + + # Confirm a booking. + # @param booking_id [String] The id of the booking to confirm. + # @param request_body [Hash] The values to update the booking with + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Hash, String)] The updated booking and API Request ID. + def confirm_booking(booking_id:, request_body:, query_params:) + put( + path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}", + request_body: request_body, + query_params: query_params + ) + end + + # Delete a booking. + # @param booking_id [String] The id of the booking to delete. + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(booking_id:, query_params:) + _, request_id = delete( + path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}", + query_params: query_params + ) + + [true, request_id] + end + end +end diff --git a/lib/nylas/resources/configurations.rb b/lib/nylas/resources/configurations.rb new file mode 100644 index 00000000..cd64a8b4 --- /dev/null +++ b/lib/nylas/resources/configurations.rb @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +require_relative "resource" +require_relative "../handler/api_operations" + +module Nylas + # Nylas Messages API + class Configurations < Resource + include ApiOperations::Get + include ApiOperations::Post + include ApiOperations::Put + include ApiOperations::Delete + + # Return all Scheduler Configurations. + # + # @param identifier [String] Grant ID or email account to query. + # @param query_params [Hash, nil] Query params to pass to the request. + # @return [Array(Array(Hash), String, String)] The list of configurations, API Request ID, + # and next cursor. + def list(identifier:, query_params: nil) + get_list( + path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations", + query_params: query_params + ) + end + + # Return a Configuration. + # + # @param identifier [String] Grant ID or email account to query. + # @param configuration_id [String] The id of the configuration to return. + # @return [Array(Hash, String)] The configuration and API request ID. + def find(identifier:, configuration_id:) + get( + path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations/#{configuration_id}" + ) + end + + # Create a configuration. + # + # @param identifier [String] Grant ID or email account in which to create the object. + # @param request_body [Hash] The values to create the configuration with. + # @return [Array(Hash, String)] The created configuration and API Request ID. + def create(identifier:, request_body:) + post( + path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations", + request_body: request_body + ) + end + + # Update a configuration. + # + # @param identifier [String] Grant ID or email account in which to update an object. + # @param configuration_id [String] The id of the configuration to update. + # @param request_body [Hash] The values to update the configuration with + # @return [Array(Hash, String)] The updated configuration and API Request ID. + def update(identifier:, configuration_id:, request_body:) + put( + path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations/#{configuration_id}", + request_body: request_body + ) + end + + # Delete a configuration. + # + # @param identifier [String] Grant ID or email account from which to delete an object. + # @param configuration_id [String] The id of the configuration to delete. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(identifier:, configuration_id:) + _, request_id = delete( + path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations/#{configuration_id}" + ) + + [true, request_id] + end + end +end diff --git a/lib/nylas/resources/scheduling.rb b/lib/nylas/resources/scheduling.rb new file mode 100644 index 00000000..7693a27e --- /dev/null +++ b/lib/nylas/resources/scheduling.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative "resource" +require_relative "bookings" +require_relative "availability" +require_relative "configurations" +require_relative "sessions" + +module Nylas + # Nylas Scheduling API + class Scheduling < Resource + attr_reader :confiugrations, :bookings, :sessions, :availability + + # Initializes the scheduling resource. + # @param sdk_instance [Nylas::API] The API instance to which the resource is bound. + def initialize(sdk_instance) + super(sdk_instance) + @configurations = Configurations.new(sdk_instance) + @bookings = Bookings.new(sdk_instance) + @sessions = Sessions.new(sdk_instance) + @availability = Availability.new(sdk_instance) + end + end +end diff --git a/lib/nylas/resources/sessions.rb b/lib/nylas/resources/sessions.rb new file mode 100644 index 00000000..7ab835eb --- /dev/null +++ b/lib/nylas/resources/sessions.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require_relative "resource" +require_relative "../handler/api_operations" + +module Nylas + # Nylas Messages API + class Configurations < Resource + include ApiOperations::Post + include ApiOperations::Delete + + # Create a session for a configuration. + # @param request_body [Hash] The values to create a configuration sessions. + # @return [Array(Hash, String)] The created configuration and API Request ID. + def create(request_body:) + post( + path: "#{api_uri}/v3/scheduling/sessions", + request_body: request_body + ) + end + + # Delete a session for a configuration. + # @param session_id [String] The id of the session to delete. + # @return [Array(TrueClass, String)] True and the API Request ID for the delete operation. + def destroy(session_id:) + _, request_id = delete( + path: "#{api_uri}/v3/scheduling/sessions/#{session_id}" + ) + + [true, request_id] + end + end +end From 0aed828559f65090ea33f7f991b8f13933d4a564 Mon Sep 17 00:00:00 2001 From: kraju3 Date: Thu, 3 Oct 2024 10:24:53 -0500 Subject: [PATCH 02/14] Scheduling resource --- lib/nylas/client.rb | 8 +++++++ lib/nylas/resources/scheduling.rb | 35 +++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/nylas/client.rb b/lib/nylas/client.rb index 700d626c..f4e262e5 100644 --- a/lib/nylas/client.rb +++ b/lib/nylas/client.rb @@ -8,6 +8,7 @@ require_relative "resources/webhooks" require_relative "resources/applications" require_relative "resources/folders" +require_relative "resources/scheduling" module Nylas # Methods to retrieve data from the Nylas API as Ruby objects. @@ -117,5 +118,12 @@ def threads def webhooks Webhooks.new(self) end + + # The scheduling resources for your Nylas application. + # + # @return [Nylas::Scheduling] Scheduling resources for your Nylas application. + def scheduling + Scheduling.new(self) + end end end diff --git a/lib/nylas/resources/scheduling.rb b/lib/nylas/resources/scheduling.rb index 7693a27e..9cb0ab73 100644 --- a/lib/nylas/resources/scheduling.rb +++ b/lib/nylas/resources/scheduling.rb @@ -9,16 +9,33 @@ module Nylas # Nylas Scheduling API class Scheduling < Resource - attr_reader :confiugrations, :bookings, :sessions, :availability + # The configuration resources for your Nylas application. + # + # @return [Nylas::Scheduling::Confiugrations] Scheduling configuration resources + # for your Nylas application. + def configurations + Configurations.new(self) + end + + # The Booking resources for your Nylas application. + # + # @return [Nylas::Scheduling::Bookings] Scheduling booking resources for your Nylas application. + def bookings + Bookings.new(self) + end + + # The Session resources for your Nylas application. + # + # @return [Nylas::Scheduling::Sessions] Scheduling session resources for your Nylas application. + def sessions + Sessions.new(self) + end - # Initializes the scheduling resource. - # @param sdk_instance [Nylas::API] The API instance to which the resource is bound. - def initialize(sdk_instance) - super(sdk_instance) - @configurations = Configurations.new(sdk_instance) - @bookings = Bookings.new(sdk_instance) - @sessions = Sessions.new(sdk_instance) - @availability = Availability.new(sdk_instance) + # The availability resources for your Nylas application. + # + # @return [Nylas::Scheduling::Availability] Scheduling availability resources for your Nylas application. + def availability + Availability.new(self) end end end From 91000ed8efc074d49cf457c331d615ca178edecf Mon Sep 17 00:00:00 2001 From: kraju3 Date: Thu, 3 Oct 2024 17:50:38 -0500 Subject: [PATCH 03/14] Removing scheduling class --- lib/nylas/client.rb | 35 ++++++++++++++++++++++---- lib/nylas/resources/scheduling.rb | 41 ------------------------------- 2 files changed, 30 insertions(+), 46 deletions(-) delete mode 100644 lib/nylas/resources/scheduling.rb diff --git a/lib/nylas/client.rb b/lib/nylas/client.rb index f4e262e5..05c2bfb5 100644 --- a/lib/nylas/client.rb +++ b/lib/nylas/client.rb @@ -8,7 +8,10 @@ require_relative "resources/webhooks" require_relative "resources/applications" require_relative "resources/folders" -require_relative "resources/scheduling" +require_relative "resources/configurations" +require_relative "resources/sessions" +require_relative "resources/availability" +require_relative "resources/bookings" module Nylas # Methods to retrieve data from the Nylas API as Ruby objects. @@ -119,11 +122,33 @@ def webhooks Webhooks.new(self) end - # The scheduling resources for your Nylas application. + # The configuration resources for your Nylas application. # - # @return [Nylas::Scheduling] Scheduling resources for your Nylas application. - def scheduling - Scheduling.new(self) + # @return [Nylas::Scheduling::Confiugrations] Scheduling configuration resources + # for your Nylas application. + def configurations + Configurations.new(self) + end + + # The Booking resources for your Nylas application. + # + # @return [Nylas::Scheduling::Bookings] Scheduling booking resources for your Nylas application. + def bookings + Bookings.new(self) + end + + # The Session resources for your Nylas application. + # + # @return [Nylas::Scheduling::Sessions] Scheduling session resources for your Nylas application. + def sessions + Sessions.new(self) + end + + # The availability resources for your Nylas application. + # + # @return [Nylas::Scheduling::Availability] Scheduling availability resources for your Nylas application. + def availability + Availability.new(self) end end end diff --git a/lib/nylas/resources/scheduling.rb b/lib/nylas/resources/scheduling.rb deleted file mode 100644 index 9cb0ab73..00000000 --- a/lib/nylas/resources/scheduling.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require_relative "resource" -require_relative "bookings" -require_relative "availability" -require_relative "configurations" -require_relative "sessions" - -module Nylas - # Nylas Scheduling API - class Scheduling < Resource - # The configuration resources for your Nylas application. - # - # @return [Nylas::Scheduling::Confiugrations] Scheduling configuration resources - # for your Nylas application. - def configurations - Configurations.new(self) - end - - # The Booking resources for your Nylas application. - # - # @return [Nylas::Scheduling::Bookings] Scheduling booking resources for your Nylas application. - def bookings - Bookings.new(self) - end - - # The Session resources for your Nylas application. - # - # @return [Nylas::Scheduling::Sessions] Scheduling session resources for your Nylas application. - def sessions - Sessions.new(self) - end - - # The availability resources for your Nylas application. - # - # @return [Nylas::Scheduling::Availability] Scheduling availability resources for your Nylas application. - def availability - Availability.new(self) - end - end -end From 6b00c0c5d11aac9b47200a741bd7f67893ec42b7 Mon Sep 17 00:00:00 2001 From: kraju3 Date: Thu, 3 Oct 2024 20:29:46 -0500 Subject: [PATCH 04/14] Fix Sessions --- lib/nylas/resources/sessions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nylas/resources/sessions.rb b/lib/nylas/resources/sessions.rb index 7ab835eb..7c392643 100644 --- a/lib/nylas/resources/sessions.rb +++ b/lib/nylas/resources/sessions.rb @@ -5,7 +5,7 @@ module Nylas # Nylas Messages API - class Configurations < Resource + class Sessions < Resource include ApiOperations::Post include ApiOperations::Delete From 23618ba964a59f0849626116c6196f569927fbe2 Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Thu, 24 Oct 2024 14:03:30 +0200 Subject: [PATCH 05/14] Adding configurations, availability, sessions, bookings endpoint under Scheduler to match with other SDKs architecture --- lib/nylas/client.rb | 32 ++++-------------------- lib/nylas/resources/scheduling.rb | 41 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 lib/nylas/resources/scheduling.rb diff --git a/lib/nylas/client.rb b/lib/nylas/client.rb index 05c2bfb5..c122cba2 100644 --- a/lib/nylas/client.rb +++ b/lib/nylas/client.rb @@ -8,6 +8,7 @@ require_relative "resources/webhooks" require_relative "resources/applications" require_relative "resources/folders" +require_relative "resources/scheduling" require_relative "resources/configurations" require_relative "resources/sessions" require_relative "resources/availability" @@ -122,33 +123,10 @@ def webhooks Webhooks.new(self) end - # The configuration resources for your Nylas application. - # - # @return [Nylas::Scheduling::Confiugrations] Scheduling configuration resources - # for your Nylas application. - def configurations - Configurations.new(self) - end - - # The Booking resources for your Nylas application. - # - # @return [Nylas::Scheduling::Bookings] Scheduling booking resources for your Nylas application. - def bookings - Bookings.new(self) - end - - # The Session resources for your Nylas application. - # - # @return [Nylas::Scheduling::Sessions] Scheduling session resources for your Nylas application. - def sessions - Sessions.new(self) - end - - # The availability resources for your Nylas application. - # - # @return [Nylas::Scheduling::Availability] Scheduling availability resources for your Nylas application. - def availability - Availability.new(self) + # The Scheduler resources for your Nylas application. + # @return [Nylas::Scheduler] Scheduler resources for your Nylas application. + def scheduler + Scheduler.new(self) end end end diff --git a/lib/nylas/resources/scheduling.rb b/lib/nylas/resources/scheduling.rb new file mode 100644 index 00000000..553fb013 --- /dev/null +++ b/lib/nylas/resources/scheduling.rb @@ -0,0 +1,41 @@ +require_relative './configurations' +require_relative './sessions' +require_relative './bookings' +require_relative './availability' + +module Nylas + class Scheduler + def initialize(api_client) + @api_client = api_client + @configurations = Configurations.new(@api_client) + @bookings = Bookings.new(@api_client) + @sessions = Sessions.new(@api_client) + @availability = Availability.new(@api_client) + end + + # The configuration resources for your Nylas application. + # @return [Nylas::Scheduler::Confiugrations] Scheduler configuration resources + # for your Nylas application. + def configurations + @configurations + end + + # The Session resources for your Nylas application. + # @return [Nylas::Scheduler::Sessions] Scheduler session resources for your Nylas application. + def sessions + @sessions + end + + # The Booking resources for your Nylas application. + # @return [Nylas::Scheduler::Bookings] Scheduler booking resources for your Nylas application. + def bookings + @bookings + end + + # The availability resources for your Nylas application. + # @return [Nylas::Scheduler::Availability] Scheduling availability resources for your Nylas application. + def availability + @availability + end + end +end From cebc7addcdff120c1d2c341f3c43facd6d813b64 Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Thu, 24 Oct 2024 14:12:13 +0200 Subject: [PATCH 06/14] Change fileName to match the className, fix lint --- lib/nylas/resources/{scheduling.rb => scheduler.rb} | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) rename lib/nylas/resources/{scheduling.rb => scheduler.rb} (87%) diff --git a/lib/nylas/resources/scheduling.rb b/lib/nylas/resources/scheduler.rb similarity index 87% rename from lib/nylas/resources/scheduling.rb rename to lib/nylas/resources/scheduler.rb index 553fb013..23bd0eff 100644 --- a/lib/nylas/resources/scheduling.rb +++ b/lib/nylas/resources/scheduler.rb @@ -1,7 +1,9 @@ -require_relative './configurations' -require_relative './sessions' -require_relative './bookings' -require_relative './availability' +# frozen_string_literal: true + +require_relative "./configurations" +require_relative "./sessions" +require_relative "./bookings" +require_relative "./availability" module Nylas class Scheduler From 1a9de6ccaa87ba24360e2df3668759c2589831bf Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Thu, 24 Oct 2024 14:33:11 +0200 Subject: [PATCH 07/14] Use attr_reader and adding comment for documentation --- lib/nylas/client.rb | 2 +- lib/nylas/resources/scheduler.rb | 38 +++++++++++--------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/lib/nylas/client.rb b/lib/nylas/client.rb index c122cba2..7a2846cd 100644 --- a/lib/nylas/client.rb +++ b/lib/nylas/client.rb @@ -8,7 +8,7 @@ require_relative "resources/webhooks" require_relative "resources/applications" require_relative "resources/folders" -require_relative "resources/scheduling" +require_relative "resources/scheduler" require_relative "resources/configurations" require_relative "resources/sessions" require_relative "resources/availability" diff --git a/lib/nylas/resources/scheduler.rb b/lib/nylas/resources/scheduler.rb index 23bd0eff..6ad9dae0 100644 --- a/lib/nylas/resources/scheduler.rb +++ b/lib/nylas/resources/scheduler.rb @@ -6,7 +6,20 @@ require_relative "./availability" module Nylas + # Nylas Scheduler API + # This class provides access to the Scheduler resources, including + # configurations, bookings, sessions, and availability. + # + # @attr_reader [Nylas::Configurations] configurations The Scheduler configurations resource for your Nylas application. + # @attr_reader [Nylas::Bookings] bookings The Scheduler bookings resource for your Nylas application. + # @attr_reader [Nylas::Sessions] sessions The Scheduler sessions resource for your Nylas application. + # @attr_reader [Nylas::Availability] availability The Scheduler availability resource for your Nylas application. class Scheduler + attr_reader :configurations, :sessions, :bookings, :availability + + # Initializes the Scheduler class. + # + # @param api_client [APIClient] The Nylas API client instance for making requests. def initialize(api_client) @api_client = api_client @configurations = Configurations.new(@api_client) @@ -14,30 +27,5 @@ def initialize(api_client) @sessions = Sessions.new(@api_client) @availability = Availability.new(@api_client) end - - # The configuration resources for your Nylas application. - # @return [Nylas::Scheduler::Confiugrations] Scheduler configuration resources - # for your Nylas application. - def configurations - @configurations - end - - # The Session resources for your Nylas application. - # @return [Nylas::Scheduler::Sessions] Scheduler session resources for your Nylas application. - def sessions - @sessions - end - - # The Booking resources for your Nylas application. - # @return [Nylas::Scheduler::Bookings] Scheduler booking resources for your Nylas application. - def bookings - @bookings - end - - # The availability resources for your Nylas application. - # @return [Nylas::Scheduler::Availability] Scheduling availability resources for your Nylas application. - def availability - @availability - end end end From aa3314cfac50186f9a5ea25245a956224c4f0c27 Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Thu, 24 Oct 2024 14:38:46 +0200 Subject: [PATCH 08/14] Fix Rubocup --- lib/nylas/resources/scheduler.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/nylas/resources/scheduler.rb b/lib/nylas/resources/scheduler.rb index 6ad9dae0..eeabc215 100644 --- a/lib/nylas/resources/scheduler.rb +++ b/lib/nylas/resources/scheduler.rb @@ -10,10 +10,14 @@ module Nylas # This class provides access to the Scheduler resources, including # configurations, bookings, sessions, and availability. # - # @attr_reader [Nylas::Configurations] configurations The Scheduler configurations resource for your Nylas application. - # @attr_reader [Nylas::Bookings] bookings The Scheduler bookings resource for your Nylas application. - # @attr_reader [Nylas::Sessions] sessions The Scheduler sessions resource for your Nylas application. - # @attr_reader [Nylas::Availability] availability The Scheduler availability resource for your Nylas application. + # @attr_reader [Nylas::Configurations] configurations The Scheduler configurations resource for your + # Nylas application. + # @attr_reader [Nylas::Bookings] bookings The Scheduler bookings resource for your + # Nylas application. + # @attr_reader [Nylas::Sessions] sessions The Scheduler sessions resource for your + # Nylas application. + # @attr_reader [Nylas::Availability] availability The Scheduler availability resource for your + # Nylas application. class Scheduler attr_reader :configurations, :sessions, :bookings, :availability From 1e3fcefa0799240230484fe7eab4334f672e6d5d Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Thu, 24 Oct 2024 14:40:10 +0200 Subject: [PATCH 09/14] Fix Rubocup whitespace --- lib/nylas/resources/scheduler.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/nylas/resources/scheduler.rb b/lib/nylas/resources/scheduler.rb index eeabc215..50af898a 100644 --- a/lib/nylas/resources/scheduler.rb +++ b/lib/nylas/resources/scheduler.rb @@ -10,13 +10,13 @@ module Nylas # This class provides access to the Scheduler resources, including # configurations, bookings, sessions, and availability. # - # @attr_reader [Nylas::Configurations] configurations The Scheduler configurations resource for your + # @attr_reader [Nylas::Configurations] configurations The Scheduler configurations resource for your # Nylas application. - # @attr_reader [Nylas::Bookings] bookings The Scheduler bookings resource for your + # @attr_reader [Nylas::Bookings] bookings The Scheduler bookings resource for your # Nylas application. # @attr_reader [Nylas::Sessions] sessions The Scheduler sessions resource for your # Nylas application. - # @attr_reader [Nylas::Availability] availability The Scheduler availability resource for your + # @attr_reader [Nylas::Availability] availability The Scheduler availability resource for your # Nylas application. class Scheduler attr_reader :configurations, :sessions, :bookings, :availability From d47289d91ea45436223eaa0bc7cc11433ff85572 Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Fri, 25 Oct 2024 10:49:11 +0200 Subject: [PATCH 10/14] Add spec for availability --- spec/nylas/resources/availability_spec.rb | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/nylas/resources/availability_spec.rb diff --git a/spec/nylas/resources/availability_spec.rb b/spec/nylas/resources/availability_spec.rb new file mode 100644 index 00000000..05994463 --- /dev/null +++ b/spec/nylas/resources/availability_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +describe Nylas::Availability do + let(:availability) { described_class.new(client) } + let(:response) do + [{ + "emails": ["user1@example.com"], + "start_time": 1659367800, + "end_time": 1659369600 + }, + { + "emails": ["user1@example.com"], + "start_time": 1659376800, + "end_time": 1659378600 + }] + end + + describe "#list" do + let(:list_response) do + response + end + + it "calls the get method with the correct parameters" do + query_params = { "start_time": 1659376800, "end_time": 1659369600, + configuration_id: "confifiguration-123" } + path = "#{api_uri}/v3/scheduling/availability" + allow(availability).to receive(:get_list) + .with(path: path, query_params: query_params) + .and_return(list_response) + + availability_response = availability.list(query_params: query_params) + expect(availability_response).to eq(list_response) + end + end +end From 28f77b60afebc1975fe932ee4a7583715701fdd8 Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Fri, 25 Oct 2024 12:03:06 +0200 Subject: [PATCH 11/14] Add spec for configurations --- lib/nylas.rb | 1 + lib/nylas/resources/configurations.rb | 2 +- spec/nylas/resources/configurations_spec.rb | 265 ++++++++++++++++++++ 3 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 spec/nylas/resources/configurations_spec.rb diff --git a/lib/nylas.rb b/lib/nylas.rb index b0375607..93a609d3 100644 --- a/lib/nylas.rb +++ b/lib/nylas.rb @@ -43,5 +43,6 @@ require_relative "nylas/resources/threads" require_relative "nylas/resources/redirect_uris" require_relative "nylas/resources/webhooks" +require_relative "nylas/resources/scheduler" require_relative "nylas/utils/file_utils" diff --git a/lib/nylas/resources/configurations.rb b/lib/nylas/resources/configurations.rb index cd64a8b4..0d3cf6b0 100644 --- a/lib/nylas/resources/configurations.rb +++ b/lib/nylas/resources/configurations.rb @@ -4,7 +4,7 @@ require_relative "../handler/api_operations" module Nylas - # Nylas Messages API + # Nylas Scheduler Configurations API class Configurations < Resource include ApiOperations::Get include ApiOperations::Post diff --git a/spec/nylas/resources/configurations_spec.rb b/spec/nylas/resources/configurations_spec.rb new file mode 100644 index 00000000..d02bd436 --- /dev/null +++ b/spec/nylas/resources/configurations_spec.rb @@ -0,0 +1,265 @@ +# frozen_string_literal: true + +describe Nylas::Configurations do + let(:configurations) { described_class.new(client) } + let(:response) do + [{ + "id": "configuration-123", + "slug": nil, + "participants": [ + { + "email": "nylas-scheduler-1@gmail.com", + "is_organizer": true, + "name": "Nylas Scheduler", + "availability": { + "calendar_ids": [ + "primary" + ] + }, + "booking": { + "calendar_id": "nylas-scheduler-1@gmail.com" + }, + "timezone": "Europe/Amsterdam" + } + ], + "requires_session_auth": false, + "availability": { + "duration_minutes": 30, + "interval_minutes": 30, + "availability_rules": { + "availability_method": "collective", + "buffer": { + "before": 0, + "after": 0 + }, + "default_open_hours": [ + { + "days": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ], + "exdates": nil, + "timezone": "Europe/Amsterdam", + "start": "00:15", + "end": "23:45" + } + ], + "round_robin_group_id": "" + } + }, + "event_booking": { + "title": "SDK - test", + "timezone": "Europe/Amsterdam", + "description": "", + "location": "", + "booking_type": "booking", + "conferencing": {}, + "hide_participants": nil, + "disable_emails": nil + }, + "scheduler": { + "available_days_in_future": 30, + "min_cancellation_notice": 0, + "min_booking_notice": 60, + "confirmation_redirect_url": "", + "hide_rescheduling_options": false, + "hide_cancellation_options": false, + "hide_additional_guests": false, + "cancellation_policy": "", + "email_template": { + "booking_confirmed": {} + } + }, + "appearance": nil + }, + { + "id": "configuration-456", + "slug": nil, + "participants": [ + { + "email": "nylas-scheduler-1@gmail.com", + "is_organizer": true, + "name": "Nylas Scheduler", + "availability": { + "calendar_ids": [ + "primary" + ] + }, + "booking": { + "calendar_id": "nylas-scheduler-1@gmail.com" + }, + "timezone": "Europe/Amsterdam" + } + ], + "requires_session_auth": false, + "availability": { + "duration_minutes": 30, + "availability_rules": { + "availability_method": "collective", + "buffer": { + "before": 0, + "after": 0 + }, + "default_open_hours": [ + { + "days": [ + 1, + 2, + 3, + 4, + 5 + ], + "exdates": nil, + "timezone": "Europe/Amsterdam", + "start": "06:00", + "end": "23:00" + } + ], + "round_robin_group_id": "" + } + }, + "event_booking": { + "title": "test - 2", + "timezone": "Europe/Amsterdam", + "description": "", + "location": "", + "booking_type": "booking", + "conferencing": {}, + "hide_participants": nil, + "disable_emails": nil + }, + "scheduler": { + "available_days_in_future": 30, + "min_cancellation_notice": 0, + "min_booking_notice": 60, + "hide_rescheduling_options": false, + "hide_cancellation_options": false, + "hide_additional_guests": false, + "cancellation_policy": "", + "email_template": { + "booking_confirmed": {} + } + }, + "appearance": nil + }] + end + + describe "#list" do + let(:list_response) do + response + end + + it "calls the get method with the correct parameters" do + identifier = "grant-123" + path = "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations" + allow(configurations).to receive(:get_list) + .with(path: path, query_params: nil) + .and_return(list_response) + + configurations_response = configurations.list(identifier: identifier, query_params: nil) + expect(configurations_response).to eq(list_response) + end + end + + describe "#find" do + it "calls the get method with the correct parameters" do + identifier = "grant-123" + configuration_id = "configuration-123" + path = "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations/#{configuration_id}" + allow(configurations).to receive(:get) + .with(path: path) + .and_return(response[0]) + + configuration_response = configurations.find(identifier: identifier, configuration_id: configuration_id) + expect(configuration_response).to eq(response[0]) + end + end + + describe "#create" do + it "calls the post method with the correct parameters" do + identifier = "grant-123" + request_body = { + "requires_session_auth": false, + "participants": [ + { + name: "Test", + email: "nylas-scheduler-1@gmail.com", + is_organizer: true, + availability: { + calendar_ids: [ + "primary" + ] + }, + booking: { + calendar_id: "primary" + } + } + ], + availability: { + duration_minutes: 30 + }, + event_booking: { + title: "My test event" + } + } + path = "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations" + allow(configurations).to receive(:post) + .with(path: path, request_body: request_body) + .and_return(response[0]) + + configuration_response = configurations.create(identifier: identifier, request_body: request_body) + + expect(configuration_response).to eq(response[0]) + end + end + + describe "#update" do + let(:update_response) do + updated_data = response[0].dup + updated_data[:event_booking][:title] = "Updated Title" + updated_data + end + + it "calls the put method with the correct parameters" do + identifier = "grant-123" + configuration_id = "configuration-123" + request_body = { + event_booking: { + title: "Updated Title" + } + } + path = "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations/#{configuration_id}" + allow(configurations).to receive(:put) + .with(path: path, request_body: request_body) + .and_return(update_response) + + configuration_response = configurations.update( + identifier: identifier, + configuration_id: configuration_id, request_body: request_body + ) + + expect(configuration_response).to eq(update_response) + end + end + + describe "#destroy" do + it "calls the delete method with the correct parameters" do + identifier = "grant-123" + configuration_id = "configuration-123" + path = "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations/#{configuration_id}" + allow(configurations).to receive(:delete) + .with(path: path) + .and_return([true, "request-id-123"]) + + configuration_response = configurations.destroy(identifier: identifier, + configuration_id: configuration_id) + + expect(configuration_response).to eq([true, "request-id-123"]) + end + end +end From 3113fa4109dc78a14c948cf7ad8191ab3ff24c11 Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Fri, 25 Oct 2024 14:09:20 +0200 Subject: [PATCH 12/14] Add spec for bookings --- spec/nylas/resources/bookings_spec.rb | 117 ++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 spec/nylas/resources/bookings_spec.rb diff --git a/spec/nylas/resources/bookings_spec.rb b/spec/nylas/resources/bookings_spec.rb new file mode 100644 index 00000000..6fcf3498 --- /dev/null +++ b/spec/nylas/resources/bookings_spec.rb @@ -0,0 +1,117 @@ +# frozen_string_literal: true + +describe Nylas::Bookings do + let(:bookings) { described_class.new(client) } + let(:response) do + [{ + "event_id": "eventid123", + "booking_id": "booking-123", + "title": "My test event", + "description": "test", + "organizer": { + "email": "scheduler-booking@nylas.com", + "name": "Test" + }, + "status": "booked" + }, "mock_request_id"] + end + + describe "#find" do + it "calls the get method with the correct parameters" do + booking_id = "booking-123" + path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}" + allow(bookings).to receive(:get) + .with(path: path, query_params: nil) + .and_return(response) + + bookings_response = bookings.find(booking_id: booking_id, query_params: nil) + + expect(bookings_response).to eq(response) + end + end + + describe "#create" do + it "calls the post method with the correct parameters" do + request_body = { + start_time: 1730194200, + end_time: 1730196000, + participants: [ + { + email: "scheduler-booking@nylas.com" + } + ], + guest: { + name: "TEST", + email: "test@nylas.com" + } + } + path = "#{api_uri}/v3/scheduling/bookings" + allow(bookings).to receive(:post) + .with(path: path, request_body: request_body, query_params: nil) + .and_return(response) + + bookings_response = bookings.create(request_body: request_body, query_params: nil) + + expect(bookings_response).to eq(response) + end + end + + describe "#update" do + it "calls the patch method with the correct parameters" do + booking_id = "booking-123" + request_body = { + start_time: 1730194200, + end_time: 1730196000 + } + path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}" + allow(bookings).to receive(:patch) + .with(path: path, request_body: request_body, query_params: nil) + .and_return(response) + + bookings_response = bookings.update( + request_body: request_body, + booking_id: booking_id, + query_params: nil + ) + + expect(bookings_response).to eq(response) + end + end + + describe "#confirm_booking" do + it "calls the put method with the correct parameters" do + booking_id = "booking-123" + request_body = { + salt: "_salt", + status: "cancelled" + } + path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}" + allow(bookings).to receive(:put) + .with(path: path, request_body: request_body, query_params: nil) + .and_return(response) + + bookings_response = bookings.confirm_booking( + booking_id: booking_id, + request_body: request_body, + query_params: nil + ) + + expect(bookings_response).to eq(response) + end + end + + describe "#destroy" do + let(:delete_response) { [true, "mock_request_id"] } + + it "calls the delete method with the correct parameters" do + booking_id = "booking-123" + path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}" + allow(bookings).to receive(:delete) + .with(path: path, query_params: nil) + .and_return(delete_response) + + bookings_response = bookings.destroy(booking_id: booking_id, query_params: nil) + expect(bookings_response).to eq(delete_response) + end + end +end From 5979b506ae88c050a696234d205c254e2e75c0bc Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Fri, 25 Oct 2024 14:15:53 +0200 Subject: [PATCH 13/14] Add spec for sessions --- spec/nylas/resources/sessions_spec.rb | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spec/nylas/resources/sessions_spec.rb diff --git a/spec/nylas/resources/sessions_spec.rb b/spec/nylas/resources/sessions_spec.rb new file mode 100644 index 00000000..0a885064 --- /dev/null +++ b/spec/nylas/resources/sessions_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +describe Nylas::Sessions do + let(:sessions) { described_class.new(client) } + let(:response) do + [{ + "session_id": "session-id-123" + }, "mock_request_id"] + end + + describe "#create" do + it "calls the post method with the correct parameters" do + request_body = { + configuration_id: "configuration-123", + time_to_live: 30 + } + path = "#{api_uri}/v3/scheduling/sessions" + allow(sessions).to receive(:post) + .with(path: path, request_body: request_body) + .and_return(response) + + sessions_response = sessions.create(request_body: request_body) + expect(sessions_response).to eq(response) + end + end + + describe "#destroy" do + it "calls the delete method with the correct parameters" do + session_id = "session-123" + path = "#{api_uri}/v3/scheduling/sessions/#{session_id}" + allow(sessions).to receive(:delete) + .with(path: path) + .and_return([true, "mock_request_id"]) + + sessions_response = sessions.destroy(session_id: session_id) + expect(sessions_response).to eq([true, "mock_request_id"]) + end + end +end From f56ec997c171c5337dd2812b1e73bc43ff28fdb7 Mon Sep 17 00:00:00 2001 From: Subash Pradhan Date: Fri, 25 Oct 2024 14:26:52 +0200 Subject: [PATCH 14/14] Code cleanup --- lib/nylas/client.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/nylas/client.rb b/lib/nylas/client.rb index 7a2846cd..d92ddc70 100644 --- a/lib/nylas/client.rb +++ b/lib/nylas/client.rb @@ -9,10 +9,6 @@ require_relative "resources/applications" require_relative "resources/folders" require_relative "resources/scheduler" -require_relative "resources/configurations" -require_relative "resources/sessions" -require_relative "resources/availability" -require_relative "resources/bookings" module Nylas # Methods to retrieve data from the Nylas API as Ruby objects.