Skip to content

Commit bbffd0b

Browse files
kraju3AaronDDM
andauthored
Add events import function to the RubySDK (#513)
* Add events import function to the RubySDK * PR comments resolve --------- Co-authored-by: Aaron de Mello <314152+AaronDDM@users.noreply.github.com>
1 parent fc9e262 commit bbffd0b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

lib/nylas/resources/events.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,19 @@ def send_rsvp(identifier:, event_id:, request_body:, query_params:)
9494
request_body: request_body
9595
)
9696
end
97+
98+
# Returns a list of recurring events, recurring event exceptions, and single events
99+
# from the specified calendar within a given time frame. This is useful when you
100+
# want to import, store, and synchronize events from the time frame to your application
101+
#
102+
# @param identifier [String] Grant ID or email account to import events from.
103+
# @param query_params [Hash] The query parameters to include in the request
104+
# @return [(Array(Hash), String, String)] The list of events, API Request ID, and next cursor.
105+
def list_import_events(identifier:, query_params:)
106+
get_list(
107+
path: "#{api_uri}/v3/grants/#{identifier}/events/import",
108+
query_params: query_params
109+
)
110+
end
97111
end
98112
end

spec/nylas/resources/events_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,38 @@
174174
query_params: query_params)
175175
end
176176
end
177+
178+
describe "#events_import" do
179+
let(:identifier) { "grant-123" }
180+
let(:query_params) { { calendar_id: "cal-123", start_time: 1234567890, end_time: 1234599999 } }
181+
182+
it "calls get_list with the correct parameters" do
183+
allow(events).to receive(:get_list)
184+
.with(
185+
path: "#{api_uri}/v3/grants/#{identifier}/events/import",
186+
query_params: query_params
187+
)
188+
.and_return([[], "request-id", "next-cursor"])
189+
190+
result = events.list_import_events(identifier: identifier, query_params: query_params)
191+
expect(result).to eq([[], "request-id", "next-cursor"])
192+
end
193+
194+
it "returns events, request_id and cursor" do
195+
expected_response = [
196+
[{ "id" => "event-123", "title" => "Test Event" }],
197+
"request-id-abc",
198+
"next-cursor-xyz"
199+
]
200+
201+
allow(events).to receive(:get_list).and_return(expected_response)
202+
203+
response = events.list_import_events(identifier: identifier, query_params: query_params)
204+
205+
expect(response).to eq(expected_response)
206+
expect(response[0]).to be_an(Array)
207+
expect(response[1]).to be_a(String)
208+
expect(response[2]).to be_a(String)
209+
end
210+
end
177211
end

0 commit comments

Comments
 (0)