Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / api.py
Created June 7, 2011 23:33
Valentunes api return only users cards
class CardResource(ModelResource):
track_set = fields.ToManyField(TrackResource, 'track_set', full=True)
def get_object_list(self, request, *args, **kwargs):
return Card.objects.filter(user=request.user)
@jazztpt
jazztpt / api.py
Created June 7, 2011 23:28
Valentunes api auth
class CardResource(ModelResource):
track_set = fields.ToManyField(TrackResource, 'track_set', full=True)
def get_object_list(self, request, *args, **kwargs):
return Card.objects.filter(user=request.user)
class Meta:
queryset = Card.objects.all()
resource_name = 'card'
authentication = BasicAuthentication()
@jazztpt
jazztpt / api.py
Created June 7, 2011 22:57
Valentunes CardResource full=True
class CardResource(ModelResource):
track_set = fields.ToManyField(TrackResource, 'track_set', full=True)
@jazztpt
jazztpt / api.py
Created June 7, 2011 22:54
Valentunes api post_list
def post_list(self, request, **kwargs):
"""
Creates a new resource/object with the provided data.
Calls get_tracks to get all track info from various apis.
"""
deserialized = self.deserialize(request, request.raw_post_data, format=request.META.get('CONTENT_TYPE', 'application/json'))
bundle = self.build_bundle(data=dict_strip_unicode_keys(deserialized))
self.is_valid(bundle, request)
updated_bundle = self.obj_create(bundle, request=request, user=request.user)
{
"create_date": "2011-06-06T06:41:31.454924",
"id": "1",
"interests": "dancing, coffee",
"intro_note": "",
"recipient_email": "",
"recipient_name": "Anna",
"recipient_phone": "",
"resource_uri": "/api/card/1/",
"track_set":
@jazztpt
jazztpt / one_card.json
Created June 7, 2011 22:25
Valentunes json one card no tracks
{
"create_date": "2011-06-06T06:41:31.454924",
"id": "1",
"interests": "dancing, coffee",
"intro_note": "",
"recipient_email": "",
"recipient_name": "Anna",
"recipient_phone": "",
"resource_uri": "/api/card/1/"
}
@jazztpt
jazztpt / gist:1013317
Created June 7, 2011 22:20 — forked from natea/gist:1013270
Valentunes POST with curl
$ curl -X POST -H 'Content-Type: application/json' -u nate:nate
--data '{"recipient_name" : "Anna",
"interests" : "dancing, coffee"}'
http://localhost:8000/api/card/