Ejemplo n.º 1
0
 def greeting_authed(self, request):
     # Get the HTTP Authorization header.
     auth_header = self.request_state.headers.get('authorization')
     if not auth_header:
         logging.info("No authorization header.")
     else:
         auth_token = auth_header.split(' ')[1].split('.')
         encoded_payload = json.loads(base64.b64decode(auth_token[1]))
         message = encoded_payload["message"]
         name = encoded_payload["name"]
         new_greeting = GreetingModel(text=message, author=name)
     new_greeting.put()
     greeting_message = Greeting(text=new_greeting.text, date=new_greeting.date.strftime(DATE_FORMAT), author=new_greeting.author)
     return greeting_message
Ejemplo n.º 2
0
 def greeting_get(self, request):
     try:
         greeting_model = GreetingModel.get_by_id(request.id)
         return Greeting(text=greeting_model.text, date=m.date, author=m.author)
     except (IndexError, TypeError):
         raise endpoints.NotFoundException('Greeting %s not found.' %
                                           (request.id,))
Ejemplo n.º 3
0
 def greetings_list(self, unused_request):
     messages = [Greeting(text=m.text, date=m.date.strftime(DATE_FORMAT), author=m.author)
                 for m in GreetingModel.all()]
     greetings = GreetingCollection(items=messages)
     return greetings