Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add booking support for Scheduler private configurations #503

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/nylas/resources/bookings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
104 changes: 97 additions & 7 deletions spec/nylas/resources/bookings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: "[email protected]"
}
],
guest: {
name: "TEST",
email: "[email protected]"
}
}
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
Expand All @@ -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 = {
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading