<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd" https="false">
<meta>
    <author>Sam Pullara (Assisted by TableSaw)</author>
    <description/>
    <documentationURL>http://help.simplegeo.com/faqs/api-documentation/endpoints</documentationURL>
    <sampleQuery>select * from {table} where ck=@ck and secret=@secret and lat='37.335088' and lon='-122.067204';</sampleQuery>
</meta>
<execute><![CDATA[
var document = {getElementsByTagName:function(value) { return null; }};
// Include the OAuth libraries from oauth.net
y.include("http://oauth.googlecode.com/svn/code/javascript/oauth.js");
y.include("http://oauth.googlecode.com/svn/code/javascript/sha1.js");

// Collect all the parameters
var encodedurl = request.url;
var accessor = { consumerSecret:secret, tokenSecret:""};
]]></execute>
<bindings>
    <select produces="JSON">
        <urls>
            <url>http://api.simplegeo.com/{version}/nearby/{geohash}.json</url>
        </urls>
        <inputs>
            <key id="version" type="xs:string" paramType="path" default='0.1'/>
			<key id="geohash" type="xs:string" paramType="path" required="true"/>
            <key id="ck" type="xs:string" paramType="variable" required="true"/>
            <key id="secret" type="xs:string" paramType="variable" required="true"/>
			<key id="radius" paramType="query"/>
			<key id="layers" paramType="query"/>
			<key id="types" paramType="query"/>
			<key id="start" paramType="query"/>
			<key id="end" paramType="query"/>
			<key id="limit" paramType="query"/>
        </inputs>
        <execute>
<![CDATA[
var message = { action: encodedurl, method: "GET", parameters: [["oauth_consumer_key",ck],["oauth_version","1.0"]]};
OAuth.setTimestampAndNonce(message);

// Sign the request
OAuth.SignatureMethod.sign(message, accessor);

try {
   // PUT the content to the service along with the OAuth header
   response.object = request
       .header("Authorization", OAuth.getAuthorizationHeader("api.simplegeo.com", message.parameters))
       .get().response;
} catch(err) {
   response.object = {'result':'failure', 'error': err};
}
            ]]>
        </execute>
    </select>
	    <select produces="JSON">
	        <urls>
	            <url>http://api.simplegeo.com/{version}/nearby/{lat},{lon}.json</url>
	        </urls>
	        <inputs>
	            <key id="version" type="xs:string" paramType="path" default='0.1'/>
				<key id="lat" type="xs:string" paramType="path" required="true"/>
				<key id="lon" type="xs:string" paramType="path" required="true"/>
	            <key id="ck" type="xs:string" paramType="variable" required="true"/>
	            <key id="secret" type="xs:string" paramType="variable" required="true"/>
				<key id="radius" paramType="query"/>
				<key id="layers" paramType="query"/>
				<key id="types" paramType="query"/>
				<key id="start" paramType="query"/>
				<key id="end" paramType="query"/>
				<key id="limit" paramType="query"/>
	        </inputs>
	        <execute>
	<![CDATA[
	var message = { action: encodedurl, method: "GET", parameters: [["oauth_consumer_key",ck],["oauth_version","1.0"]]};
	OAuth.setTimestampAndNonce(message);

	// Sign the request
	OAuth.SignatureMethod.sign(message, accessor);

	try {
	   // PUT the content to the service along with the OAuth header
	   response.object = request
	       .header("Authorization", OAuth.getAuthorizationHeader("api.simplegeo.com", message.parameters))
	       .get().response;
	} catch(err) {
	   response.object = {'result':'failure', 'error': err};
	}
	            ]]>
	        </execute>
	    </select>
</bindings>
</table>