<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd" https="true">
  <meta>
  <author>Dustin Whittle (dustin@yahoo-inc.com)</author>
  <description>SimpleGeo API</description>
  <documentationURL>http://help.simplegeo.com/faqs/api-documentation/endpoints</documentationURL>
    <sampleQuery>select * from {table} where location='soma, san francisco, ca' and radius='1' and limit='50' and layers='com.simplegeo.global.twitter' and oauth_consumer_key=@key and oauth_consumer_secret=@secret;</sampleQuery>
  </meta>
  <bindings>
    <select itemPath="" produces="JSON">
     <urls>  
       <url>http://api.simplegeo.com/{version}/nearby</url>  
     </urls>  
      <inputs>
        <key id="version" type="xs:string" paramType="path" default="0.1" />

        <key id="oauth_consumer_key" type="xs:string" paramType="variable" required="true" />
        <key id="oauth_consumer_secret" type="xs:string" paramType="variable" required="true" />

        <key id="location" type="xs:string" paramType="variable" required="true" />
        <key id="latitude" type="xs:string" paramType="variable" required="false" />
        <key id="longitude" type="xs:string" paramType="variable" required="false" />
        
        <key id="layers" type="xs:string" paramType="query" default="com.simplegeo.global.brightkite,com.simplegeo.global.flickr,com.simplegeo.global.foursquare,com.simplegeo.global.fwix,com.simplegeo.global.geonames,com.simplegeo.global.twitter,com.simplegeo.us.weather,com.simplegeo.us.zip" />
        <key id="radius" type="xs:string" paramType="query" default="1" />

        <key id="type" type="xs:string" paramType="query" required="false" />
        <key id="limit" type="xs:string" paramType="query" default="10" />
        <key id="start" type="xs:string" paramType="query" required="false" />
        <key id="end" type="xs:string" paramType="query" required="false" />
      </inputs>
      <execute>
      <![CDATA[

        default xml namespace = "http://where.yahooapis.com/v1/schema.rng";

        var location = y.query('select * from geo.places(1) where text="' + location + '"');
        if(location.results && location.results.place) {

          latitude = location.results.place.centroid.latitude;
          longitude = location.results.place.centroid.longitude;
          
          request.path(latitude + ',' + longitude + '.json');
          
          y.include("http://www.datatables.org/oauth/oauth.utils.js");

          response.object = sendRequest({ action: request.url, method: "GET", accessor: { consumerKey: oauth_consumer_key, consumerSecret: oauth_consumer_secret, realm: request.url } });
          
        }
      
      ]]>
      </execute>
    </select>
  </bindings>
</table>
