-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
38 lines (31 loc) · 1.6 KB
/
api.py
File metadata and controls
38 lines (31 loc) · 1.6 KB
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
import endpoints
from google.appengine.ext import ndb
from models import MovieQuote
import protorpc
PARENT_KEY = ndb.Key("Entity", 'moviequotes_root')
@endpoints.api(name="moviequotes", version="v1", description="Movie Quotes API")
class MovieQuotesApi(protorpc.remote.Service):
""" API to use JSON messages to put MovieQuotes in the cloud from a client. """
@MovieQuote.method(path="moviequote/insert", name="moviequote.insert", http_method="POST")
def moviequote_insert(self, request):
""" Insert (i.e. create and update) a movie quote. """
if request.from_datastore:
my_quote = request
else:
my_quote = MovieQuote(parent=PARENT_KEY, quote=request.quote, movie=request.movie)
my_quote.put()
return my_quote
@MovieQuote.query_method(path="moviequote/list", http_method="GET", name="moviequote.list",
query_fields=("limit", "order", "pageToken"))
def moviequote_list(self, query):
""" Returns the query for movie quotes based on the limit, order, and pageToken given."""
return query
@MovieQuote.method(request_fields=("entityKey",), path="moviequote/delete/{entityKey}",
http_method="DELETE", name="moviequote.delete")
def moviequote_delete(self, request_movie_quote):
""" Deletes the quote. """
if not request_movie_quote.from_datastore:
raise endpoints.NotFoundException("Movie quote not found")
request_movie_quote.key.delete()
return MovieQuote(quote="deleted")
app = endpoints.api_server([MovieQuotesApi], restricted=False)