Skip to content

Commit

Permalink
Renamed build_query on Auth instead of http_client
Browse files Browse the repository at this point in the history
  • Loading branch information
atejada committed Feb 28, 2024
1 parent 2bbb465 commit 7049bf5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/nylas/handler/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def throw_error(response, status_code)
def build_url(url, query = nil)
unless query.nil? || query.empty?
uri = URI.parse(url)
uri = build_http_query(uri, query)
uri = build_query(uri, query)
url = uri.to_s
end

Expand All @@ -222,7 +222,7 @@ def build_url(url, query = nil)
# @param uri [URI] URL to add the query to.
# @param query [Hash] The query params to include in the query.
# @return [URI] The URI object with the query parameters included.
def build_http_query(uri, query)
def build_query(uri, query)
query.each do |key, value|
case value
when Array
Expand Down
8 changes: 4 additions & 4 deletions lib/nylas/resources/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def detect_provider(params)
# @return [String] Updated list of parameters, including those specific to admin
# consent.
def build_query_with_admin_consent(config)
params = build_query(config)
params = build_http_query(config)

# Appends new params specific for admin consent.
params[:provider] = "microsoft"
Expand All @@ -135,7 +135,7 @@ def build_query_with_admin_consent(config)
# @return [String] Updated list of encoded parameters, including those specific
# to PKCE.
def build_query_with_pkce(config, secret_hash)
params = build_query(config)
params = build_http_query(config)

# Appends new PKCE specific params.
params[:code_challenge_method] = "s256"
Expand All @@ -151,7 +151,7 @@ def build_query_with_pkce(config, secret_hash)
def url_auth_builder(config)
builder = URI.parse(api_uri)
builder.path = "/v3/connect/auth"
builder.query = URI.encode_www_form(build_query(config)).gsub(/\+/, "%20")
builder.query = URI.encode_www_form(build_http_query(config)).gsub(/\+/, "%20")

builder
end
Expand All @@ -160,7 +160,7 @@ def url_auth_builder(config)
#
# @param config [Hash] Configuration for the query.
# @return [Hash] List of parameters to encode in the query.
def build_query(config)
def build_http_query(config)
params = {
client_id: config[:client_id],
redirect_uri: config[:redirect_uri],
Expand Down
4 changes: 2 additions & 2 deletions spec/nylas/handler/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class TestHttpClient
end
end

describe "#build_http_query" do
describe "#build_query" do
it "returns the correct query params" do
uri = URI.parse("https://test.api.nylas.com/foo")
params = {
Expand All @@ -190,7 +190,7 @@ class TestHttpClient
map: { key1: "value1", key2: "value2" }
}

final_uri = http_client.send(:build_http_query, uri, params)
final_uri = http_client.send(:build_query, uri, params)

expect(final_uri.to_s).to eq("https://test.api.nylas.com/foo?foo=bar&list=a&list=b&list=c&map=key1%3Avalue1&map=key2%3Avalue2")
end
Expand Down

0 comments on commit 7049bf5

Please sign in to comment.