Class: OpenID::Yadis::XRI::ProxyResolver
- Inherits:
-
Object
- Object
- OpenID::Yadis::XRI::ProxyResolver
- Defined in:
- lib/openid/yadis/xrires.rb
Constant Summary collapse
- DEFAULT_PROXY =
"http://proxy.xri.net/"
Instance Method Summary collapse
-
#initialize(proxy_url = nil) ⇒ ProxyResolver
constructor
A new instance of ProxyResolver.
- #query(xri) ⇒ Object
- #query_url(xri, service_type = nil) ⇒ Object
Constructor Details
#initialize(proxy_url = nil) ⇒ ProxyResolver
Returns a new instance of ProxyResolver.
17 18 19 20 21 |
# File 'lib/openid/yadis/xrires.rb', line 17 def initialize(proxy_url = nil) @proxy_url = proxy_url || DEFAULT_PROXY @proxy_url += "/" unless @proxy_url.match?("/$") end |
Instance Method Details
#query(xri) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/openid/yadis/xrires.rb', line 40 def query(xri) # these can be query args or http headers, needn't be both. # headers = {'Accept' => 'application/xrds+xml;sep=true'} url = query_url(xri) begin response = OpenID.fetch(url) rescue StandardError raise XRIHTTPError, "Could not fetch #{xri}, #{$!}" end raise XRIHTTPError, "Could not fetch #{xri}" if response.nil? xrds = Yadis.parseXRDS(response.body) canonical_id = Yadis.get_canonical_id(xri, xrds) [canonical_id, Yadis.services(xrds)] # TODO: # * If we do get hits for multiple service_types, we're almost # certainly going to have duplicated service entries and # broken priority ordering. end |
#query_url(xri, service_type = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/openid/yadis/xrires.rb', line 23 def query_url(xri, service_type = nil) # URI normal form has a leading xri://, but we need to strip # that off again for the QXRI. This is under discussion for # XRI Resolution WD 11. qxri = XRI.to_uri_normal(xri)[6..-1] hxri = @proxy_url + qxri args = {"_xrd_r" => "application/xrds+xml"} if service_type args["_xrd_t"] = service_type else # don't perform service endpoint selection args["_xrd_r"] += ";sep=false" end XRI.append_args(hxri, args) end |