Module: XRI
- Defined in:
- lib/yadis/xri.rb,
lib/yadis/xrires.rb
Defined Under Namespace
Classes: ProxyResolver, XRIHTTPError
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.append_args(url, args) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/yadis/xrires.rb', line 71
def XRI.append_args(url, args)
return url if args.length == 0
rstripped = url.dup
while rstripped[-1].chr == '?'
rstripped = rstripped[0...rstripped.length-1]
end
if rstripped.index('?')
sep = '&'
else
sep = '?'
end
return 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
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/yadis/xri.rb', line 30
def XRI.escape_for_iri(xri)
esc = xri.dup
esc.gsub!(/%/, '%25')
esc.gsub!(/\((.*?)\)/) { |xref_match|
xref_match.gsub(/[\/\?\#]/) { |char_match|
CGI::escape(char_match)
}
}
return esc
end
|
.identifier_scheme(identifier) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/yadis/xri.rb', line 10
def XRI.identifier_scheme(identifier)
if identifier.match('^xri://') or XRI_AUTHORITIES.member?(identifier[0].chr)
return :xri
else
return :uri
end
end
|
.iri_to_uri(iri) ⇒ Object
51
52
53
54
55
56
|
# File 'lib/yadis/xri.rb', line 51
def XRI.iri_to_uri(iri)
uri = iri.dup
return uri
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
22
23
24
25
26
|
# File 'lib/yadis/xri.rb', line 22
def XRI.to_iri_normal(xri)
iri = xri.dup
iri.insert(0, 'xri://') if not iri.match('^xri://')
return 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
46
47
48
|
# File 'lib/yadis/xri.rb', line 46
def XRI.to_uri_normal(xri)
return iri_to_uri(to_iri_normal(xri))
end
|
.urlencode(args) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/yadis/xrires.rb', line 63
def XRI.urlencode(args)
a = []
args.each do |key, val|
a << (CGI::escape(key) + "=" + CGI::escape(val))
end
a.join("&")
end
|
Instance Method Details
#make_xri(xri) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/yadis/xri.rb', line 80
def make_xri(xri)
if xri.index('xri://') != 0
xri = 'xri://' + xri
end
return xri
end
|
#provider_is_authoritative(provider_id, canonical_id) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/yadis/xri.rb', line 58
def provider_is_authoritative(provider_id, canonical_id)
lastbang = canonical_id.rindex('!')
return false unless lastbang
parent = canonical_id[0...lastbang]
return parent == provider_id
end
|
#root_authority(xri) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/yadis/xri.rb', line 65
def root_authority(xri)
xri = xri[6..-1] if xri.index('xri://') == 0
authority = xri.split('/', 2)[0]
if authority[0].chr == '('
root = authority[0...authority.index(')')+1]
elsif XRI_AUTHORITIES.member?(authority[0].chr)
root = authority[0].chr
else
root = authority.split(/[!*]/)[0]
end
make_xri(root)
end
|