<?xml version="1.0" encoding="UTF-8"?>
<Module>
	<ModulePrefs title="Signed request test Gadget" summary="" description="" author="" author_email="" thumbnail="" screenshot="" height="260">
		<Require feature="opensocial-0.7" />
		<Require feature="dynamic-height" />
	</ModulePrefs>
	<Content type="html">
		<![CDATA[
		<style>
		html body {
			padding:15px;
			}
		#maindiv {
			font-size: 9pt;
			}
		#oauthtextarea {
			width:100%;
		}
		</style>
		<p>This test gadget performs a signed io.makeRequest();</p>
		<script type="text/javascript">		
		function initgadget() {
			makeSignedRequest();
		}

		function makeSignedRequest() {
			var params = {};
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
			var url = "http://www.apikooien.nl/examples/opensocial/signedrequest/TestOAuthService.php";
			gadgets.io.makeRequest(url, response, params);
		};
		
		function response(ret) {
			var html = [ ret.data.validated, "<br />",
				"oauth_consumer_key: ", ret.data.query.oauth_consumer_key, "<br />",
				"oauth_nonce: ", ret.data.query.oauth_nonce, "<br />",
				"oauth_signature: <br><textarea id='oauthtextarea'>", ret.data.query.oauth_signature, "</textarea><br />",
				"oauth_signature_method: ", ret.data.query.oauth_signature_method, "<br />",
				"oauth_timestamp: ", ret.data.query.oauth_timestamp, "<br />",
				"oauth_token: ", ret.data.query.oauth_token, "<br />",
				"opensocial_app_id: ", ret.data.query.opensocial_app_id, "<br />",
				"opensocial_owner_id: ", ret.data.query.opensocial_owner_id, "<br />",
				"opensocial_viewer_id: ", ret.data.query.opensocial_viewer_id, "<br />",
				"xoauth_signature_publickey: ", ret.data.query.xoauth_signature_publickey ].join("");
		    html = html+"<br><br>";
			output(html);
			loadOwner();			
		};

		function loadOwner() {
			var req = opensocial.newDataRequest();
			req.add(req.newFetchPersonRequest('OWNER'), 'owner');
			req.send(onLoadOwner);
		};

		function onLoadOwner(data) {
			var owner = data.get('owner').getData();
			output("<br><br><strong>owner_id from newFetchPersonRequest</strong>: " + owner.getId() + " (compare this to opensocial_owner_id)<br>");
		};
		
		function output(value) {
			document.getElementById("maindiv").innerHTML += value;
			gadgets.window.adjustHeight();
		}

		gadgets.util.registerOnLoadHandler(initgadget);
		</script>
		<div id="maindiv"><strong>Reponse from the server:</strong><br/></div>
		]]>
		
	</Content>
</Module>