class Kentico::Kontent::Delivery::Tests::FakeResponder
Constants
- BASE_URL
- IS_SECURE
- PREVIEW_KEY
- PREVIEW_URL
- PROJECT_ID
- SECURE_KEY
Public Class Methods
get_response(query, url, headers)
click to toggle source
# 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
respond_401()
click to toggle source
# File lib/delivery/tests/fake_responder.rb, line 58 def respond_401 path = Pathname.new(File.dirname(__FILE__) + '/401.json') Kentico::Kontent::Delivery::Responses::ResponseBase.new 401, '', path.read if path.exist? end
respond_filtering(query)
click to toggle source
# File lib/delivery/tests/fake_responder.rb, line 45 def respond_filtering(query) path = case CGI.unescape query when 'skip=0&limit=5' Pathname.new(File.dirname(__FILE__) + '/filtering/pagination_about_us.json') when 'elements.price[gt]=20' Pathname.new(File.dirname(__FILE__) + '/filtering/items_gt.json') when 'elements.price[gt]=20&system.type=grinder' Pathname.new(File.dirname(__FILE__) + '/filtering/multiple.json') end path.read unless path.nil? && !path.exist? end
respond_generic(url)
click to toggle source
# File lib/delivery/tests/fake_responder.rb, line 40 def respond_generic(url) path = Pathname.new(File.dirname(__FILE__) + "/generic#{url}.json") path.read if path.exist? end