Last active
October 14, 2015 05:37
-
-
Save dangerouse/1623391 to your computer and use it in GitHub Desktop.
Cloudsponge Proxy Reference - Ruby
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
require 'cloudsponge' | |
def cloudsponge_proxy | |
url = Cloudsponge::URL_BASE + 'auth?' + request.query_string | |
response = Cloudsponge::Utility::get_url(url) | |
if response.is_a?(Net::HTTPRedirection) | |
redirect_to response["location"] | |
else | |
render :text => response.try(:body) | |
end | |
end |
I believe line 15 should be
if response.is_a?(Net::HTTPRedirection)
It's somewhat unclear what framework this bit of code fits into, but in case you're using Rails 4 (or Rack?), some edits are needed. Particularly, request.request_method
returns a String, so the symbol comparisons aren't very friendly.
In Rails, it's probably better to use request.post?
and request.get?
instead.
Here's my revision for Rails, FWIW.
class CloudspongeController < ApplicationController
def auth_proxy
url = "#{Cloudsponge::URL_BASE}auth?#{request.query_string}"
proxy_response =
if request.get?
Cloudsponge::Utility::get_url(url)
else
Cloudsponge::Utility::post_url(url, request.parameters)
end
if proxy_response.is_a?(Net::HTTPRedirection)
redirect_to proxy_response['location']
else
render text: proxy_response.try(:body)
end
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe line 15 should read: