diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b068dc6..891f5823 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### Unreleased +* Add support for private Scheduling configuration. + ### 6.2.1 / 2024-11-12 * Added support for scheduler APIs * Added `query_params` field to `Folders` & `Threads` find diff --git a/lib/nylas/resources/bookings.rb b/lib/nylas/resources/bookings.rb index bb3f6d02..e357fc73 100644 --- a/lib/nylas/resources/bookings.rb +++ b/lib/nylas/resources/bookings.rb @@ -16,7 +16,7 @@ class Bookings < Resource # @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:) + def find(booking_id:, query_params: nil) get( path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}", query_params: query_params @@ -27,7 +27,7 @@ def find(booking_id:, query_params:) # @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:) + def create(request_body:, query_params: nil) post( path: "#{api_uri}/v3/scheduling/bookings", request_body: request_body, @@ -40,7 +40,7 @@ def create(request_body:, query_params:) # @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:) + def update(request_body:, booking_id:, query_params: nil) patch( path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}", request_body: request_body, @@ -53,7 +53,7 @@ def update(request_body:, booking_id:, query_params:) # @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:) + def confirm(booking_id:, request_body:, query_params: nil) put( path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}", request_body: request_body, @@ -65,7 +65,7 @@ def confirm_booking(booking_id:, request_body:, query_params:) # @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:) + def destroy(booking_id:, query_params: nil) _, request_id = delete( path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}", query_params: query_params diff --git a/spec/nylas/resources/bookings_spec.rb b/spec/nylas/resources/bookings_spec.rb index 6fcf3498..79311258 100644 --- a/spec/nylas/resources/bookings_spec.rb +++ b/spec/nylas/resources/bookings_spec.rb @@ -24,7 +24,20 @@ .with(path: path, query_params: nil) .and_return(response) - bookings_response = bookings.find(booking_id: booking_id, query_params: nil) + bookings_response = bookings.find(booking_id: booking_id) + + expect(bookings_response).to eq(response) + end + + it "calls the get method with the correct query params" do + booking_id = "booking-123" + query_params = { "foo": "bar" } + path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}" + allow(bookings).to receive(:get) + .with(path: path, query_params: query_params) + .and_return(response) + + bookings_response = bookings.find(booking_id: booking_id, query_params: query_params) expect(bookings_response).to eq(response) end @@ -50,7 +63,32 @@ .with(path: path, request_body: request_body, query_params: nil) .and_return(response) - bookings_response = bookings.create(request_body: request_body, query_params: nil) + bookings_response = bookings.create(request_body: request_body) + + expect(bookings_response).to eq(response) + end + + it "calls the post method with the correct query parameters" do + request_body = { + start_time: 1730194200, + end_time: 1730196000, + participants: [ + { + email: "scheduler-booking@nylas.com" + } + ], + guest: { + name: "TEST", + email: "test@nylas.com" + } + } + query_params = { "foo": "bar" } + path = "#{api_uri}/v3/scheduling/bookings" + allow(bookings).to receive(:post) + .with(path: path, request_body: request_body, query_params: query_params) + .and_return(response) + + bookings_response = bookings.create(request_body: request_body, query_params: query_params) expect(bookings_response).to eq(response) end @@ -68,17 +106,37 @@ .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 + ) + + expect(bookings_response).to eq(response) + end + + it "calls the patch method with the correct query parameters" do + booking_id = "booking-123" + query_params = { "foo": "bar" } + 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: query_params) + .and_return(response) + bookings_response = bookings.update( request_body: request_body, booking_id: booking_id, - query_params: nil + query_params: query_params ) expect(bookings_response).to eq(response) end end - describe "#confirm_booking" do + describe "#confirm" do it "calls the put method with the correct parameters" do booking_id = "booking-123" request_body = { @@ -90,10 +148,30 @@ .with(path: path, request_body: request_body, query_params: nil) .and_return(response) - bookings_response = bookings.confirm_booking( + bookings_response = bookings.confirm( + booking_id: booking_id, + request_body: request_body + ) + + expect(bookings_response).to eq(response) + end + + it "calls the put method with the correct query parameters" do + booking_id = "booking-123" + query_params = { "foo": "bar" } + 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: query_params) + .and_return(response) + + bookings_response = bookings.confirm( booking_id: booking_id, request_body: request_body, - query_params: nil + query_params: query_params ) expect(bookings_response).to eq(response) @@ -110,7 +188,19 @@ .with(path: path, query_params: nil) .and_return(delete_response) - bookings_response = bookings.destroy(booking_id: booking_id, query_params: nil) + bookings_response = bookings.destroy(booking_id: booking_id) + expect(bookings_response).to eq(delete_response) + end + + it "calls the delete method with the correct query parameters" do + booking_id = "booking-123" + query_params = { "foo": "bar" } + path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}" + allow(bookings).to receive(:delete) + .with(path: path, query_params: query_params) + .and_return(delete_response) + + bookings_response = bookings.destroy(booking_id: booking_id, query_params: query_params) expect(bookings_response).to eq(delete_response) end end