Skip to content

Commit f5bacef

Browse files
Merge pull request #503 from nylas/TW-3564-ruby-sdk-add-support-for-private-configuration
Add booking support for Scheduler private configurations
2 parents 3677a0b + 1fbb5d2 commit f5bacef

3 files changed

Lines changed: 105 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
### Unreleased
4+
* Add support for private Scheduling configuration.
5+
36
### 6.2.1 / 2024-11-12
47
* Added support for scheduler APIs
58
* Added `query_params` field to `Folders` & `Threads` find

lib/nylas/resources/bookings.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Bookings < Resource
1616
# @param booking_id [String] The id of the booking to return.
1717
# @param query_params [Hash, nil] Query params to pass to the request.
1818
# @return [Array(Hash, String)] The booking and API request ID.
19-
def find(booking_id:, query_params:)
19+
def find(booking_id:, query_params: nil)
2020
get(
2121
path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}",
2222
query_params: query_params
@@ -27,7 +27,7 @@ def find(booking_id:, query_params:)
2727
# @param request_body [Hash] The values to create the booking with.
2828
# @param query_params [Hash, nil] Query params to pass to the request.
2929
# @return [Array(Hash, String)] The created booking and API Request ID.
30-
def create(request_body:, query_params:)
30+
def create(request_body:, query_params: nil)
3131
post(
3232
path: "#{api_uri}/v3/scheduling/bookings",
3333
request_body: request_body,
@@ -40,7 +40,7 @@ def create(request_body:, query_params:)
4040
# @param booking_id [String] The id of the booking to update.
4141
# @param query_params [Hash, nil] Query params to pass to the request.
4242
# @return [Array(Hash, String)] The created booking and API Request ID.
43-
def update(request_body:, booking_id:, query_params:)
43+
def update(request_body:, booking_id:, query_params: nil)
4444
patch(
4545
path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}",
4646
request_body: request_body,
@@ -53,7 +53,7 @@ def update(request_body:, booking_id:, query_params:)
5353
# @param request_body [Hash] The values to update the booking with
5454
# @param query_params [Hash, nil] Query params to pass to the request.
5555
# @return [Array(Hash, String)] The updated booking and API Request ID.
56-
def confirm_booking(booking_id:, request_body:, query_params:)
56+
def confirm(booking_id:, request_body:, query_params: nil)
5757
put(
5858
path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}",
5959
request_body: request_body,
@@ -65,7 +65,7 @@ def confirm_booking(booking_id:, request_body:, query_params:)
6565
# @param booking_id [String] The id of the booking to delete.
6666
# @param query_params [Hash, nil] Query params to pass to the request.
6767
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
68-
def destroy(booking_id:, query_params:)
68+
def destroy(booking_id:, query_params: nil)
6969
_, request_id = delete(
7070
path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}",
7171
query_params: query_params

spec/nylas/resources/bookings_spec.rb

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,20 @@
2424
.with(path: path, query_params: nil)
2525
.and_return(response)
2626

27-
bookings_response = bookings.find(booking_id: booking_id, query_params: nil)
27+
bookings_response = bookings.find(booking_id: booking_id)
28+
29+
expect(bookings_response).to eq(response)
30+
end
31+
32+
it "calls the get method with the correct query params" do
33+
booking_id = "booking-123"
34+
query_params = { "foo": "bar" }
35+
path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}"
36+
allow(bookings).to receive(:get)
37+
.with(path: path, query_params: query_params)
38+
.and_return(response)
39+
40+
bookings_response = bookings.find(booking_id: booking_id, query_params: query_params)
2841

2942
expect(bookings_response).to eq(response)
3043
end
@@ -50,7 +63,32 @@
5063
.with(path: path, request_body: request_body, query_params: nil)
5164
.and_return(response)
5265

53-
bookings_response = bookings.create(request_body: request_body, query_params: nil)
66+
bookings_response = bookings.create(request_body: request_body)
67+
68+
expect(bookings_response).to eq(response)
69+
end
70+
71+
it "calls the post method with the correct query parameters" do
72+
request_body = {
73+
start_time: 1730194200,
74+
end_time: 1730196000,
75+
participants: [
76+
{
77+
email: "scheduler-booking@nylas.com"
78+
}
79+
],
80+
guest: {
81+
name: "TEST",
82+
email: "test@nylas.com"
83+
}
84+
}
85+
query_params = { "foo": "bar" }
86+
path = "#{api_uri}/v3/scheduling/bookings"
87+
allow(bookings).to receive(:post)
88+
.with(path: path, request_body: request_body, query_params: query_params)
89+
.and_return(response)
90+
91+
bookings_response = bookings.create(request_body: request_body, query_params: query_params)
5492

5593
expect(bookings_response).to eq(response)
5694
end
@@ -68,17 +106,37 @@
68106
.with(path: path, request_body: request_body, query_params: nil)
69107
.and_return(response)
70108

109+
bookings_response = bookings.update(
110+
request_body: request_body,
111+
booking_id: booking_id
112+
)
113+
114+
expect(bookings_response).to eq(response)
115+
end
116+
117+
it "calls the patch method with the correct query parameters" do
118+
booking_id = "booking-123"
119+
query_params = { "foo": "bar" }
120+
request_body = {
121+
start_time: 1730194200,
122+
end_time: 1730196000
123+
}
124+
path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}"
125+
allow(bookings).to receive(:patch)
126+
.with(path: path, request_body: request_body, query_params: query_params)
127+
.and_return(response)
128+
71129
bookings_response = bookings.update(
72130
request_body: request_body,
73131
booking_id: booking_id,
74-
query_params: nil
132+
query_params: query_params
75133
)
76134

77135
expect(bookings_response).to eq(response)
78136
end
79137
end
80138

81-
describe "#confirm_booking" do
139+
describe "#confirm" do
82140
it "calls the put method with the correct parameters" do
83141
booking_id = "booking-123"
84142
request_body = {
@@ -90,10 +148,30 @@
90148
.with(path: path, request_body: request_body, query_params: nil)
91149
.and_return(response)
92150

93-
bookings_response = bookings.confirm_booking(
151+
bookings_response = bookings.confirm(
152+
booking_id: booking_id,
153+
request_body: request_body
154+
)
155+
156+
expect(bookings_response).to eq(response)
157+
end
158+
159+
it "calls the put method with the correct query parameters" do
160+
booking_id = "booking-123"
161+
query_params = { "foo": "bar" }
162+
request_body = {
163+
salt: "_salt",
164+
status: "cancelled"
165+
}
166+
path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}"
167+
allow(bookings).to receive(:put)
168+
.with(path: path, request_body: request_body, query_params: query_params)
169+
.and_return(response)
170+
171+
bookings_response = bookings.confirm(
94172
booking_id: booking_id,
95173
request_body: request_body,
96-
query_params: nil
174+
query_params: query_params
97175
)
98176

99177
expect(bookings_response).to eq(response)
@@ -110,7 +188,19 @@
110188
.with(path: path, query_params: nil)
111189
.and_return(delete_response)
112190

113-
bookings_response = bookings.destroy(booking_id: booking_id, query_params: nil)
191+
bookings_response = bookings.destroy(booking_id: booking_id)
192+
expect(bookings_response).to eq(delete_response)
193+
end
194+
195+
it "calls the delete method with the correct query parameters" do
196+
booking_id = "booking-123"
197+
query_params = { "foo": "bar" }
198+
path = "#{api_uri}/v3/scheduling/bookings/#{booking_id}"
199+
allow(bookings).to receive(:delete)
200+
.with(path: path, query_params: query_params)
201+
.and_return(delete_response)
202+
203+
bookings_response = bookings.destroy(booking_id: booking_id, query_params: query_params)
114204
expect(bookings_response).to eq(delete_response)
115205
end
116206
end

0 commit comments

Comments
 (0)