Created
April 3, 2012 09:25
-
-
Save iantearle/2290637 to your computer and use it in GitHub Desktop.
Cocoafish login then create a place...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | |
<title>Cocoafish test</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> | |
<script type="text/javascript" src="http://sdk.cocoafish.com/js/cocoafish-1.1.min.js"></script> | |
<script type="text/javascript"> | |
jQuery(document).ready(function() { | |
var sdk = new Cocoafish('API'); // app key | |
var data = { | |
login: 'username', | |
password: 'password' | |
}; | |
sdk.sendRequest('users/login.json', 'POST', data, false, loginCallback); | |
function loginCallback(data) { | |
if(data) { | |
if(data.meta) { | |
var meta = data.meta; | |
if(meta.status == 'ok' && meta.code == 200 && meta.method_name == 'loginUser') { | |
$('#status').append('<p>Logged in</p>'); | |
} | |
} | |
} | |
} | |
$('#cocoafish').click(function(){ | |
var data = { | |
name: 'Name', | |
address: 'Address', | |
state: 'State', | |
postal_code: 'Post Code', | |
latitude: '52.0000', | |
longitude: '-1.0000', | |
website: 'http://website.com', | |
twitter: '@twitter', | |
phone_number: '1234567890' | |
}; | |
sdk.sendRequest('places/create.json', 'POST', data, false, callback); | |
function callback(data) { | |
if(data) { | |
if(data.meta) { | |
var meta = data.meta; | |
if(meta.status == 'ok' && meta.code == 200 && meta.method_name == 'createPlace') { | |
alert('ok'); | |
} else { | |
alert('fail'); | |
} | |
} | |
} | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="status"></div> | |
<a href="#" id="cocoafish">Add a place</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment