Skip to content

Instantly share code, notes, and snippets.

@jazztpt
jazztpt / # urls.py
Created June 7, 2011 21:30
Valentunes urls.py with basic api
from django.conf.urls.defaults import *
from tastypie.api import Api
from myapp.api import EntryResource, UserResource
v1_api = Api(api_name = 'v1')
v1_api.register(CardResource())
v1_api.register(TrackResource())
mobile_api = Api(api_name='mobile')
mobile_api.register(CardResource())
@jazztpt
jazztpt / gist:1013315
Created June 7, 2011 22:19 — forked from natea/gist:1013270
Valentunes POST with curl
$ curl -X POST -H 'Content-Type: application/json' -u nate:nate
--data '{"recipient_name" : "Anna",
"track_set" : "",
"interests" : "hamburgers, skating"}'
http://localhost:8000/api/card/
@jazztpt
jazztpt / gist:1013316
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",
"track_set" : "",
"interests" : "hamburgers, skating"}'
http://localhost:8000/api/card/
@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/
@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/"
}
{
"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 / 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)
@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 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 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)