Skip to content

Commit

Permalink
Adding support for query_params for messages endpoint (#480)
Browse files Browse the repository at this point in the history
Adding support for query_params to retrieve headers for messages along with field selection. select API parameter.
  • Loading branch information
kraju3 committed Jul 25, 2024
1 parent 8490435 commit 9e74efb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 8 additions & 4 deletions lib/nylas/resources/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def list(identifier:, query_params: nil)
#
# @param identifier [String] Grant ID or email account to query.
# @param message_id [String] The id of the message to return.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The message and API request ID.
def find(identifier:, message_id:)
def find(identifier:, message_id:, query_params: nil)
get(
path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}"
path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}",
query_params: query_params
)
end

Expand All @@ -50,11 +52,13 @@ def find(identifier:, message_id:)
# @param identifier [String] Grant ID or email account in which to update an object.
# @param message_id [String] The id of the message to update.
# @param request_body [Hash] The values to update the message with
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The updated message and API Request ID.
def update(identifier:, message_id:, request_body:)
def update(identifier:, message_id:, request_body:, query_params: nil)
put(
path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}",
request_body: request_body
request_body: request_body,
query_params: query_params
)
end

Expand Down
11 changes: 7 additions & 4 deletions spec/nylas/resources/messages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@
it "calls the get method with the correct parameters" do
identifier = "abc-123-grant-id"
message_id = "5d3qmne77v32r8l4phyuksl2x"
query_params = { fields: "include_headers" }
path = "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}"
allow(messages).to receive(:get)
.with(path: path)
.with(path: path, query_params: query_params)
.and_return(response)

message_response = messages.find(identifier: identifier, message_id: message_id)
message_response = messages.find(identifier: identifier, message_id: message_id,
query_params: query_params)

expect(message_response).to eq(response)
end
Expand All @@ -87,13 +89,14 @@
folders: ["folder-123"],
metadata: { foo: "bar" }
}
query_params = { fields: "include_headers" }
path = "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}"
allow(messages).to receive(:put)
.with(path: path, request_body: request_body)
.with(path: path, request_body: request_body, query_params: query_params)
.and_return(response)

message_response = messages.update(identifier: identifier, message_id: message_id,
request_body: request_body)
request_body: request_body, query_params: query_params)

expect(message_response).to eq(response)
end
Expand Down

0 comments on commit 9e74efb

Please sign in to comment.