Skip to content

Commit

Permalink
Add support for sending remaining options with query (#592)
Browse files Browse the repository at this point in the history
+ Append all non-standard options to the query url
+ Rely on Faraday's query string encoding

Some endpoints (like invoice) require additional parameters on the query URL to get additional attributes (like include=invoiceLink).
danielwestendorf authored Jun 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 6d6422d commit 5c19c7e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/quickbooks/service/base_service.rb
Original file line number Diff line number Diff line change
@@ -83,7 +83,11 @@ def url_for_query(query = nil, start_position = 1, max_results = 20, options = {
query ||= default_model_query
query = "#{query} STARTPOSITION #{start_position} MAXRESULTS #{max_results}"

"#{url_for_base}/query?query=#{CGI.escape(query)}"
URI("#{url_for_base}/query").tap do |uri|
params = Faraday::Utils::ParamsHash.new
params.update(options.merge(query: query))
uri.query = params.to_query
end.to_s
end

private
@@ -116,7 +120,7 @@ def fetch_collection(query, model, options = {})
start_position = ((page - 1) * per_page) + 1 # page=2, per_page=10 then we want to start at 11
max_results = per_page

response = do_http_get(url_for_query(query, start_position, max_results))
response = do_http_get(url_for_query(query, start_position, max_results, options.except(:page, :per_page)))

parse_collection(response, model)
end

0 comments on commit 5c19c7e

Please sign in to comment.