Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

webfinger support for yql

  • Loading branch information...
commit 67443677edd519b30d1ffbe0eb6a30efa3e09b2e 1 parent ec5ad92
@spullara spullara authored
Showing with 67 additions and 0 deletions.
  1. +1 −0  alltables.env
  2. +66 −0 data/webfinger.xml
View
1  alltables.env
@@ -25,6 +25,7 @@ use 'http://www.datatables.org/bitly/bit.ly.shorten.xml' as bit.ly.shorten;
use 'http://www.datatables.org/craigslist/craigslist.search.xml' as craigslist.search;
use 'http://www.datatables.org/data/data.html.cssselect.xml' as data.html.cssselect;
use 'http://www.datatables.org/data/query.multi.xml' as query.multi;
+use 'http://www.datatables.org/data/webfinger.xml' as webfinger;
use 'http://www.datatables.org/delicious/delicious.feeds.popular.xml' as delicious.feeds.popular;
use 'http://www.datatables.org/delicious/delicious.feeds.xml' as delicious.feeds;
use 'http://www.datatables.org/dopplr/dopplr.auth.xml' as dopplr.auth;
View
66 data/webfinger.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <sampleQuery>select * from {table} where account='sam@sampullara.com'</sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML">
+ <urls>
+ <url>http://webfinger/</url>
+ </urls>
+ <inputs>
+ <key id='account' type='xs:string' paramType='variable' required='true'/>
+ </inputs>
+ <execute><![CDATA[
+// Remove the acct: if present
+account = account.replace(/^acct:/, "");
+// Get the domain, later we can support more types
+var split = account.split("@");
+if (split.length != 2) {
+ response.object = <error>must provide a valid account address</error>;
+ y.exit();
+}
+var id = split[0];
+var domain = split[1];
+// Check for the host-meta
+var hostmeta = y.rest("http://" + domain + "/.well-known/host-meta").contentType("application/xml").get();
+if (hostmeta.status != 200) {
+ response.object = <error>status: {hostmeta.status}</error>;
+ y.exit();
+}
+hostmeta = hostmeta.response;
+if (!(hostmeta.respo instanceof XML)) {
+ hostmeta = hostmeta.substring(hostmeta.indexOf("?>") + 2).replace("{", "<![CDATA[{]" + "]>");
+ hostmeta = eval("var a__ = " + hostmeta + ";a__;");
+}
+default xml namespace = 'http://host-meta.net/xrd/1.0';
+var host = hostmeta..Host;
+if (!host) {
+ response.object = <error><message>Host not found</message><hostmeta>{hostmeta.response}</hostmeta></error>;
+ y.exit();
+}
+if (host != domain) {
+ response.object = <error><message>Domain mismatch</message><hostmeta>{hostmeta.response}</hostmeta></error>;
+ y.exit();
+}
+default xml namespace = 'http://docs.oasis-open.org/ns/xri/xrd-1.0';
+var links = hostmeta.Link;
+for (var i in links) {
+ var link = links[i];
+ var rels = link.Rel;
+ for (var j in rels) {
+ var rel = rels[j];
+ if (rel.toLowerCase() == "http://webfinger.info/rel/service" || rel.toLowerCase() == "describedby") {
+ var url = link.URITemplate.toString().replace("{%id}", encodeURI(account));
+ url = url.replace("{%uri}", encodeURI("acct:" + account));
+ url = url.replace("{id}", account);
+ url = url.replace("{uri}", "acct:" + account);
+ response.object = y.rest(url).get().response;
+ y.exit();
+ }
+ }
+}
+ ]]></execute>
+ </select>
+ </bindings>
+</table>
Please sign in to comment.
Something went wrong with that request. Please try again.