examples/api_proxy.rb in goliath-0.9.4 vs examples/api_proxy.rb in goliath-1.0.0.beta.1

- old
+ new

@@ -2,12 +2,12 @@ # Rewrites and proxies requests to a third-party API, with HTTP basic authentication. require 'goliath' require 'em-synchrony/em-http' - -class TwilioResponse < Goliath::API + +class Twilio < Goliath::API use Goliath::Rack::Params use Goliath::Rack::JSONP HEADERS = { authorization: ENV.values_at("TWILIO_SID","TWILIO_AUTH_TOKEN") } BASE_URL = "https://api.twilio.com/2010-04-01/Accounts/#{ENV['TWILIO_SID']}/AvailablePhoneNumbers/US" @@ -16,13 +16,9 @@ url = "#{BASE_URL}#{env['REQUEST_PATH']}?#{env['QUERY_STRING']}" logger.debug "Proxying #{url}" http = EM::HttpRequest.new(url).get head: HEADERS logger.debug "Received #{http.response_header.status} from Twilio" - + [200, {'X-Goliath' => 'Proxy','Content-Type' => 'application/javascript'}, http.response] end -end - -class Twilio < Goliath::API - get %r{^/(Local|TollFree)}, TwilioResponse end