Method: Kentico::Kontent::Delivery::Tests::FakeResponder.get_response

Defined in:
lib/delivery/tests/fake_responder.rb

.get_response(query, url, headers) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/delivery/tests/fake_responder.rb', line 18

def get_response(query, url, headers)
  @query = query
  if IS_SECURE && !(
    headers['Authorization'] == "Bearer #{SECURE_KEY}" ||
    headers['Authorization'] == "Bearer #{PREVIEW_KEY}"
  )
    return respond_401
  end

  url =
    if @query.should_preview
      url[PREVIEW_URL.length...url.length]
    else
      url[BASE_URL.length...url.length]
    end

  qs = url.contains('?') ? url.split('?')[1] : nil
  return respond_filtering qs unless qs.nil? # e.g. /items/about_us?skip=0&limit=5

  respond_generic url # Didn't match other clauses, so response should be located in corresponding filepath
end