Sha256: de93979b060fa90b6899fd1cadf3b7cfb8eb49a5522bf29e5231c69306428afd
Contents?: true
Size: 809 Bytes
Versions: 16
Compression:
Stored size: 809 Bytes
Contents
require 'json' require 'sinatra/base' module Wework class MockApi < Sinatra::Base get '/cgi-bin/media/get' do send_file mock_file_path('files/zhiren.png'), :type => :jpg end get '/cgi-bin/*' do |api| json_response "#{api}.json" end %i(get post).each do |http_method| send http_method, '/cgi-bin/*/*' do |category, api| json_response "#{category}/#{api}.json" end end private def json_response file_name content_type :json status 200 file_path = mock_file_path(file_name) file_path = mock_file_path('success.json') unless File.exist?(file_path) File.open(file_path, 'rb').read end def mock_file_path path File.join(File.expand_path('../../../mock_responses/', __FILE__), path) end end end
Version data entries
16 entries across 16 versions & 2 rubygems