Skip to content

Commit 9a422bb

Browse files
authored
Merge pull request #543 from zendesk/fvilela/red-1821
[RED-1820] Do not attempt CBP requests on specific endpoints
2 parents 3989b52 + 051bac1 commit 9a422bb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/zendesk_api/collection.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,15 @@ def intentional_obp_request?
356356
Helpers.present?(@options["page"]) && !cbp_request?
357357
end
358358

359+
def should_try_cbp?(path_query_link)
360+
not_supported_endpoints = %w[show_many]
361+
not_supported_endpoints.none? { |endpoint| path_query_link.end_with?(endpoint) }
362+
end
363+
359364
def get_resources(path_query_link)
360365
if intentional_obp_request?
361366
warn "Offset Based Pagination will be deprecated soon"
362-
elsif @next_page.nil?
367+
elsif @next_page.nil? && should_try_cbp?(path_query_link)
363368
@options_per_page_was = @options.delete("per_page")
364369
# Default to CBP by using the page param as a map
365370
@options.page = { size: (@options_per_page_was || DEFAULT_PAGE_SIZE) }

spec/core/collection_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,17 @@ def to_proc
10041004
double("response", body: cbp_response)
10051005
end
10061006

1007+
context "when we know for sure that the endpoint does not support CBP" do
1008+
before do
1009+
stub_json_request(:get, %r{test_resources\/show_many}, json(:test_resources => [{ :id => 1 }]))
1010+
end
1011+
1012+
it "does not try to default to CBP" do
1013+
subject.show_many.fetch
1014+
expect(subject.instance_variable_get(:@options)["page"]).to be_nil
1015+
end
1016+
end
1017+
10071018
context "when fetching a collection" do
10081019
before do
10091020
expect(subject).to receive(:get_response).with("test_resources").and_return(cbp_success_response)

0 commit comments

Comments
 (0)