#require File.join(File.dirname(__FILE__), '..','..','vendor','gems', 'environment') require 'sinatra/base' require 'akamai' module AkamaiBookmarklet class Application < Sinatra::Base set :views, File.join(File.dirname(__FILE__),'views') helpers do def publicize_cms_uri(uri) if uri =~ /cms.audi.com/i path = /^https\:\/\/cms\.audi\.com\/author\/(.*)\?(.*)$/i.match(uri)[1] "http://www.audiusa.com/#{path}" else uri end end end get '/bookmarklet' do halt 401 unless session[:cas_user] erb :'bookmarklet.html' end get '/purge.js' do uri = publicize_cms_uri(URI.decode(params[:uri])) puts "Purging #{uri}" @result = Akamai.new.purge(uri) erb :'purge.js' end end end