Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
84 lines (71 sloc) 3.41 KB
<html>
<head>
<title>OAuthSimple test document</title>
</head>
<body>
<h1>test document</h1>
<ol>
<li><a id="sample1">First Link</a>
<li><a id="sample2">Second Link</a>
<li><a id="sample3">Third Link</a>
</ol>
<div id="hasConsole" style="display:none">Psst! Open your console for the output objects.</div>
<a href="OAuthSimple.js">The javascript file</a>
<script src="OAuthSimple.js" ></script>
<script>
// To get results in all their magnificent glory (rather than some error)
// fill these out with your own magical Netflix API keys.
// Don't have a magical Netflix API key yet?
// http://developer.netflix.com
//
// Some easy defines
var apiKey = "nO-woRk";
var sharedSecret = "ExAMple01";
var accessToken = "This-Will-NOT.wOrk.EIthEr";
var tokenSecret = "N0sOuP4U";
var path="http://api.netflix.com/catalog/titles"
var argumentsAsString = "term=rat&expand=format,synopsis&max_results=1";
var argumentsAsObject = {
term:'rat',
expand:'formats,synopsis',
max_results: '1'
};
if (apiKey == "nO-woRk")
alert('Remember, the key/values defined here need to be changed to valid values before the API calls will work. Currently, these links are only for demonstration purposes.');
// Test 1 ===== The hard way...
var oauth = OAuthSimple(apiKey,sharedSecret);
oauth.setParameters(argumentsAsString);
oauth.setPath(path);
var sample1Results = oauth.sign();
try {
console.debug('Sample 1',sample1Results);
} catch(e) {};
// Test 2 ===== the semi-easy way.
OAuthSimple().reset();
var oauth2 = OAuthSimple(apiKey,sharedSecret);
var sample2Results = oauth2.sign({action:'GET',
path:path,
method:'HMAC-SHA1',
parameters:argumentsAsObject});
try {
console.debug('Sample 2',sample2Results);
} catch (e) {};
// Test 3 ===== the totally easy way.
OAuthSimple().reset();
var sample3Results = (new OAuthSimple()).sign({path:path,
parameters:argumentsAsString,
signatures:{
'consumer_key':apiKey, 'shared_secret': sharedSecret,
'access_token':accessToken,'access_secret':tokenSecret}});
try {
console.debug('Sample 3',sample3Results);
} catch (e) {};
// Now fill out the samples with our handiwork:
document.getElementById('sample1').href = sample1Results.signed_url;
document.getElementById('sample2').href = sample2Results.signed_url;
document.getElementById('sample3').href = sample3Results.signed_url;
if (window.console != null)
document.getElementById('hasConsole').style.display='block';
</script>
</body>
</html>