Module: OpenID::Yadis::XRI
- Defined in:
- lib/openid/yadis/xri.rb,
lib/openid/yadis/xrires.rb
Defined Under Namespace
Classes: ProxyResolver, XRIHTTPError
Constant Summary collapse
- XRI_AUTHORITIES =
The ‘(’ is for cross-reference authorities, and hopefully has a matching ‘)’ somewhere.
["!", "=", "@", "+", "$", "("]
Class Method Summary collapse
- .append_args(url, args) ⇒ Object
-
.escape_for_iri(xri) ⇒ Object
Note this is not not idempotent, so do not apply this more than once.
- .identifier_scheme(identifier) ⇒ Object
-
.iri_to_uri(iri) ⇒ Object
RFC 3987 section 3.1.
- .make_xri(xri) ⇒ Object
- .provider_is_authoritative(provider_id, canonical_id) ⇒ Object
- .root_authority(xri) ⇒ Object
-
.to_iri_normal(xri) ⇒ Object
Transform an XRI reference to an IRI reference.
-
.to_uri_normal(xri) ⇒ Object
Transform an XRI reference to a URI reference.
- .urlencode(args) ⇒ Object
Class Method Details
.append_args(url, args) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/openid/yadis/xrires.rb', line 70 def self.append_args(url, args) return url if args.empty? # rstrip question marks rstripped = url.dup rstripped = rstripped[0...rstripped.length - 1] while rstripped[-1].chr == "?" sep = if rstripped.index("?") "&" else "?" end url + sep + XRI.urlencode(args) end |
.escape_for_iri(xri) ⇒ Object
Note this is not not idempotent, so do not apply this more than once. XRI Syntax section 2.3.2
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/openid/yadis/xri.rb', line 32 def self.escape_for_iri(xri) esc = xri.dup # encode all % esc.gsub!("%", "%25") esc.gsub!(/\((.*?)\)/) do |xref_match| xref_match.gsub(%r{[/?\#]}) do |char_match| CGI.escape(char_match) end end esc end |
.identifier_scheme(identifier) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/openid/yadis/xri.rb', line 10 def self.identifier_scheme(identifier) if !identifier.nil? and identifier.length > 0 and (identifier.match("^xri://") or XRI_AUTHORITIES.member?(identifier[0].chr)) :xri else :uri end end |
.iri_to_uri(iri) ⇒ Object
RFC 3987 section 3.1
52 53 54 55 56 |
# File 'lib/openid/yadis/xri.rb', line 52 def self.iri_to_uri(iri) iri.dup # for char in ucschar or iprivate # convert each char to %HH%HH%HH (as many %HH as octets) end |
.make_xri(xri) ⇒ Object
80 81 82 83 |
# File 'lib/openid/yadis/xri.rb', line 80 def self.make_xri(xri) xri = "xri://" + xri if xri.index("xri://") != 0 xri end |
.provider_is_authoritative(provider_id, canonical_id) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/openid/yadis/xri.rb', line 58 def self.(provider_id, canonical_id) lastbang = canonical_id.rindex("!") return false unless lastbang parent = canonical_id[0...lastbang] parent == provider_id end |
.root_authority(xri) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/openid/yadis/xri.rb', line 66 def self.(xri) xri = xri[6..-1] if xri.index("xri://") == 0 = xri.split("/", 2)[0] root = if [0].chr == "(" [0....index(")") + 1] elsif XRI_AUTHORITIES.member?([0].chr) [0].chr else .split(/[!*]/)[0] end make_xri(root) end |
.to_iri_normal(xri) ⇒ Object
Transform an XRI reference to an IRI reference. Note this is not not idempotent, so do not apply this to an identifier more than once. XRI Syntax section 2.3.1
24 25 26 27 28 |
# File 'lib/openid/yadis/xri.rb', line 24 def self.to_iri_normal(xri) iri = xri.dup iri.insert(0, "xri://") unless iri.match?("^xri://") escape_for_iri(iri) end |
.to_uri_normal(xri) ⇒ Object
Transform an XRI reference to a URI reference. Note this is not not idempotent, so do not apply this to an identifier more than once. XRI Syntax section 2.3.1
47 48 49 |
# File 'lib/openid/yadis/xri.rb', line 47 def self.to_uri_normal(xri) iri_to_uri(to_iri_normal(xri)) end |
.urlencode(args) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/openid/yadis/xrires.rb', line 62 def self.urlencode(args) a = [] args.each do |key, val| a << (CGI.escape(key) + "=" + CGI.escape(val)) end a.join("&") end |