Created
September 24, 2016 16:42
-
-
Save anonymous/9f166e81120c4e07e1d6c10151f65814 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "sinatra" | |
require "json" | |
require_relative "pactools" | |
get "/" do | |
"Hello, world!" | |
end | |
post "/api/:browser/:format/" do | |
if not ["firefox", "chrome", "safari", "ie", "edge", "opera", "all"].include? params[:browser] | |
"#{params[:browser]} is not a recognized browser" | |
end | |
result = evaluate_pac params[:browser], params[:script] | |
if params[:format] == "json" | |
"#{result}" | |
elsif params[:format] == "txt" or params[:format] == "text" | |
"#{JSON.parse(result)['result']}" | |
else | |
"#{params[:format]} is not a recognized format." | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spooky@spookypac:/var/www$ curl -sLF 'script=test' 'http://spookypac.com/api/firefox/text/' && echo | |
PROXY proxy.example.com:8080 | |
spooky@spookypac:/var/www$ curl -sLF 'script=test' 'http://spookypac.com/api/firefox/txt/' && echo | |
PROXY proxy.example.com:8080 | |
spooky@spookypac:/var/www$ curl -sLF 'script=test' 'http://spookypac.com/api/firefox/json/' && echo | |
{"browser": "firefox", "script": "test", "result": "PROXY proxy.example.com:8080"} | |
spooky@spookypac:/var/www$ curl -sLF 'script=test' 'http://spookypac.com/api/notabrowser/json/' && echo | |
{"browser": "notabrowser", "script": "test", "result": "PROXY proxy.example.com:8080"} | |
spooky@spookypac:/var/www$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment