Skip to content

Instantly share code, notes, and snippets.

@woodie
Created March 10, 2010 00:32
Show Gist options
  • Save woodie/327329 to your computer and use it in GitHub Desktop.
Save woodie/327329 to your computer and use it in GitHub Desktop.
OpenID Example
require 'openid'
require 'net/http'
require 'appengine-apis/urlfetch'
class MyFetcher < OpenID::StandardFetcher
def fetch(url, body=nil, headers=nil, redirect_limit=REDIRECT_LIMIT)
raise OpenID::FetchingError, "Blank URL: #{url}" if url.blank?
headers ||= {}
headers['User-agent'] ||= USER_AGENT
options = {
:follow_redirects => false,
:allow_truncated => false,
:headers => headers,
:follow_redirects => true,
:allow_truncated => false,
}
response = nil
if not body.nil?
query = Rack::Utils.build_query(body)
options[:method] = 'POST'
options[:headers]["Content-type"] ||= "application/x-www-form-urlencoded"
options[:payload] = query
else
options[:method] = 'GET'
end
begin
response = AppEngine::URLFetch.fetch(url, options)
rescue Exception => why
raise OpenID::FetchingError, "Error fetching #{url}: #{why}"
end
return OpenID::HTTPResponse._from_net_response(response, url)
end
end
OpenID.fetcher = MyFetcher.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment