-
Notifications
You must be signed in to change notification settings - Fork 3
/
helloworld_api.py
43 lines (28 loc) · 1.07 KB
/
helloworld_api.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
import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote
from auth.endpoints import get_current_user
package = 'Hello'
class Greeting(messages.Message):
"""Greeting that stores a message."""
message = messages.StringField(1)
class GreetingCollection(messages.Message):
"""Collection of Greetings."""
items = messages.MessageField(Greeting, 1, repeated=True)
STORED_GREETINGS = GreetingCollection(items=[
Greeting(message='hello world!'),
Greeting(message='goodbye world!'),
])
@endpoints.api(name='helloworld', version='v1')
class HelloWorldApi(remote.Service):
"""Helloworld API v1."""
@endpoints.method(message_types.VoidMessage, GreetingCollection,
path='hellogreeting', http_method='GET',
name='greetings.listGreeting')
def greetings_list(self, *args):
user = get_current_user()
if not user:
raise endpoints.UnauthorizedException()
return STORED_GREETINGS
APPLICATION = endpoints.api_server([HelloWorldApi])