Skip to content

Commit

Permalink
Merge pull request #500 from nylas/TW-3536-ruby-fetching-a-folder-sho…
Browse files Browse the repository at this point in the history
…uld-support-select-field

Add query_params to folders find method
  • Loading branch information
SubashPradhan authored Nov 4, 2024
2 parents 03ec00b + e3d832e commit 25b9aad
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### Unreleased
* Added support for scheduler APIs
* Added `query_params` field to `Folders` & `Threads` find


### 6.2.0 / 2024-09-24
* Added query support for folders
* Added dependency on `ostruct` gem
Expand Down
6 changes: 4 additions & 2 deletions lib/nylas/resources/folders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ def list(identifier:, query_params: nil)
#
# @param identifier [String] Grant ID or email account to query.
# @param folder_id [String] The id of the folder to return.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The folder and API request ID.
def find(identifier:, folder_id:)
def find(identifier:, folder_id:, query_params: nil)
get(
path: "#{api_uri}/v3/grants/#{identifier}/folders/#{folder_id}"
path: "#{api_uri}/v3/grants/#{identifier}/folders/#{folder_id}",
query_params: query_params
)
end

Expand Down
6 changes: 4 additions & 2 deletions lib/nylas/resources/threads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ def list(identifier:, query_params: nil)
#
# @param identifier [String] Grant ID or email account to query.
# @param thread_id [String] The id of the thread to return.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The thread and API request ID.
def find(identifier:, thread_id:)
def find(identifier:, thread_id:, query_params: nil)
get(
path: "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}"
path: "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}",
query_params: query_params
)
end

Expand Down
23 changes: 22 additions & 1 deletion spec/nylas/resources/folders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,39 @@
end

describe "#find" do
let(:select_response) do
[{
id: "5d3qmne77v32r8l4phyuksl2x",
grant_id: "abc-123-grant-id"
}, "mock_request_id"]
end

it "calls the get method with the correct parameters" do
identifier = "abc-123-grant-id"
folder_id = "5d3qmne77v32r8l4phyuksl2x"
path = "#{api_uri}/v3/grants/#{identifier}/folders/#{folder_id}"
allow(folders).to receive(:get)
.with(path: path)
.with(path: path, query_params: nil)
.and_return(response)

folder_response = folders.find(identifier: identifier, folder_id: folder_id)

expect(folder_response).to eq(response)
end

it "calls the get method with the correct query parameters" do
identifier = "abc-123-grant-id"
folder_id = "5d3qmne77v32r8l4phyuksl2x"
query_params = { select: "id,grant_id" }
path = "#{api_uri}/v3/grants/#{identifier}/folders/#{folder_id}"
allow(folders).to receive(:get)
.with(path: path, query_params: query_params)
.and_return(select_response)

folder_response = folders.find(identifier: identifier, folder_id: folder_id, query_params: query_params)

expect(folder_response).to eq(select_response)
end
end

describe "#create" do
Expand Down
15 changes: 14 additions & 1 deletion spec/nylas/resources/threads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,26 @@
thread_id = "5d3qmne77v32r8l4phyuksl2x"
path = "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}"
allow(threads).to receive(:get)
.with(path: path)
.with(path: path, query_params: nil)
.and_return(response)

thread_response = threads.find(identifier: identifier, thread_id: thread_id)

expect(thread_response).to eq(response)
end

it "calls the get method with the correct query parameters" do
identifier = "abc-123-grant-id"
thread_id = "5d3qmne77v32r8l4phyuksl2x"
query_params = { foo: "bar" }
path = "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}"
allow(threads).to receive(:get)
.with(path: path, query_params: query_params)
.and_return(response)

thread_response = threads.find(identifier: identifier, thread_id: thread_id, query_params: query_params)
expect(thread_response).to eq(response)
end
end

describe "#update" do
Expand Down

0 comments on commit 25b9aad

Please sign in to comment.