Skip to content

Instantly share code, notes, and snippets.

@jazztpt
jazztpt / api.py
Created June 7, 2011 23:38
Valentunes wrap_view
def wrap_view(self, view):
@csrf_exempt
def wrapper(request, *args, **kwargs):
try:
...(bunch of standard stuff here)...
return response
except (BadRequest, ApiFieldError), e:
message = e.args[0]
@jazztpt
jazztpt / BaseViewController.m
Created June 7, 2011 23:43
Valentunes Xcode alert based on code
-(void) alertBasedOnCode:(int)errorCode message:(NSString*)message
{
if (errorCode == 3) {
[self showAlertViewWithTitle:@"Authentication" message:message];
LoginViewController* loginVC = [[[LoginViewController alloc]
initWithNibName:@"LoginViewController" bundle:nil] autorelease];
[self.navigationController presentModalViewController:loginVC animated:YES];
}
else if (errorCode == 12) {
@jazztpt
jazztpt / twitter_leaderboard.json
Created June 20, 2011 09:47
(valentunes) twitter leaderboard
[
{
"name":"jazztpt",
"days":
[
{
"date":"2011-06-20",
"tweets":"18",
"mentions":"4",
"pm":"2",
@jazztpt
jazztpt / POSTarticle.json
Created June 24, 2011 16:12
example of a post request (REST)
POST http://oursocialbloggingsite.com/api/article
{
"title":"Exciting Blog Post",
"text":"To make an exciting post, talk about explosions. It works for Hollywood!"
}
@jazztpt
jazztpt / GETfood_blog.json
Created June 24, 2011 16:36
GET the food blog (standard REST)
{
"title":"Food",
"articles":
[
"/articles/111",
"/articles/123"
]
}
@jazztpt
jazztpt / GETfood_blog_hierarchy.json
Created June 24, 2011 16:45
GET request returning hierarchy of data
{
"title":"Food",
"articles":
[
{
"url":"http://oursocialbloggingsite.com/api/articles/111",
"title":"Why Food Is Delicious",
"author":"Abe Adams"
},
{
@jazztpt
jazztpt / POSTarray.json
Created June 24, 2011 16:58
Accept arrays instead of single objects in POST requests
[
{
"title":"Exciting Blog Post",
"text":"To make an exciting post, talk about explosions. Works for Hollywood....",
"guid":"9876"
}
]
@jazztpt
jazztpt / POSTreturn_guid.json
Created June 24, 2011 17:02
POST return including original guid
[
{
"guid":"9876",
"url":"http://oursocialbloggingsite.com/api/articles/125"
}
]
@jazztpt
jazztpt / GETleaderboard_simple.json
Created June 24, 2011 17:13
GET request returning calculated user data
{
"users_by_total_hits":
[
{
"name":"Betty Black",
"total_hits":"1205"
},
{
"name":"Abe Adams",
"total_hits":"835"
@jazztpt
jazztpt / URLreturn.json
Created June 24, 2011 17:29
Returning a url to access the object
{
"url":"http://oursocialbloggingsite.com/api/articles/125"
}