Skip to content

Instantly share code, notes, and snippets.

@bethsecor
Created April 14, 2016 02:17
Show Gist options
  • Save bethsecor/4797039b6226ef368afe68617d9ee5e6 to your computer and use it in GitHub Desktop.
Save bethsecor/4797039b6226ef368afe68617d9ee5e6 to your computer and use it in GitHub Desktop.
require 'sinatra/base'
class FakeSuperCool < Sinatra::Base
get "/api/" do
if params[:keywords] == 'ruby'
json_response 200, 'super_cool_ruby_response.json'
elsif params[:keywords] == 'rubular'
json_response 200, 'super_cool_no_results_response.json'
elsif params[:api_key] == '123'
json_response 200, 'super_cool_bad_api_key_response.json'
end
end
private
def json_response(response_code, file_name)
status response_code
File.open(File.dirname(__FILE__) + '/fixtures/' + file_name, 'rb').read
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment