-
Notifications
You must be signed in to change notification settings - Fork 2
/
toy.py
107 lines (67 loc) · 1.72 KB
/
toy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
import resources
from resources import Interface
# built in verbs
#
api = Interface()
@api.collection('bookmarks')
class Bookmarks(object):
"""Haystack's Bookmarks Resource."""
# __bookmarks = {'test': 'hi'}
__bookmarks = {}
# get(*args, **kwargs) <-- automatic
# ri = resource identifier
def element_head(self, ri):
return ri in self.__bookmarks
def element_get(self, ri):
return self.__bookmarks.get(ri)
def element_put(self, ri, data):
pass
def element_patch(self, ri, data):
pass
def element_post(self, ri, data):
pass
def element_delete(self, ri):
pass
def collection_get(self, **options):
return self.__bookmarks.values()
def collection_put(self, ri, data):
pass
def collection_patch(self, ri, data):
pass
def collection_post(self, ri, data):
pass
def collection_delete(self, ri):
pass
def __from_json(ri):
pass
# api.map('bookmarks', Bookmarks)
# @api.when.bookmarks.post
def test(x):
print 'hi'
#api.before_get
#api.before_put
#api.before_post
#api.before_delete
#api.before_patch
#api.after_get
#api.after_put
#api.after_post
#api.after_delete
#api.after_patch
# print api
print api.bookmarks
# print api.resources
print api.bookmarks.get()
# print api.bookmarks.get(id='0')
# api.bookmarks.get()
# print api.bookmarks['test2']
# >>> print api.bookmarks[00001]
# <element <bookmarks:00001>
# You'll be able to use this as a reference in other objects
# >>> print api.bookmarks[00001].get()
# <bookmark 000001>
# >>> api.bookmarks[00001].content('json').get()
# <bookmark 000001>
# print test('x')
# print api.resources