<commit_before>__author__ = 'Lyndon'


import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote


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, unused_request):
        return STORED_GREETINGS

    ID_RESOURCE = endpoints.ResourceContainer(
            message_types.VoidMessage,
            id=messages.IntegerField(1, variant=messages.Variant.INT32))

    @endpoints.method(ID_RESOURCE, Greeting,
                      path='hellogreeting/{id}', http_method='GET',
                      name='greetings.getGreeting')
    def greeting_get(self, request):
        try:
            return STORED_GREETINGS.items[request.id]
        except (IndexError, TypeError):
            raise endpoints.NotFoundException('Greeting %s not found.' %
                                              (request.id,))


APPLICATION = endpoints.api_server([HelloWorldApi])<commit_msg>added native query and persist new entity<commit_after>__author__ = 'Lyndon'

import endpoints
from hello.models import Greeting
from protorpc import messages
from protorpc import message_types
from protorpc import remote
from google.appengine.ext import db


package = 'Hello'


class GreetingRequest(messages.Message):
    """Greeting that stores a message."""
    message = messages.StringField(1)


class GreetingCollection(messages.Message):
    """Collection of Greetings."""
    items = messages.MessageField(GreetingRequest, 1, repeated=True)


class GreetingResponse(messages.Message):
    greetingId = messages.StringField(1)

STORED_GREETINGS = GreetingCollection(items=[
    GreetingRequest(message='hello world!'),
    GreetingRequest(message='goodbye world!'),
])


@endpoints.api(name='helloworld', version='v1')
class HelloWorldApi(remote.Service):
    """Helloworld API v1."""

    ID_RESOURCE = endpoints.ResourceContainer(
        message_types.VoidMessage, id=messages.IntegerField(1, variant=messages.Variant.INT32))

    @endpoints.method(message_types.VoidMessage, GreetingCollection,
                      path='hellogreeting', http_method='GET',
                      name='greetings.listGreeting')
    def greetings_list(self, unused_request):
        all_greetings = db.GqlQuery('SELECT * FROM Greeting')

        my_list = []
        for g in all_greetings:
            my_list.append(GreetingRequest(message=g.content))

        return GreetingCollection(items=my_list)

    @endpoints.method(GreetingRequest, GreetingResponse,
                      path='greet', http_method='POST',
                      name='greetings.createGreeting')
    def create_greeting(self, request):
        g = Greeting(content=request.message)
        g.put()

        return GreetingResponse(greetingId=str(g.key()))


    @endpoints.method(ID_RESOURCE, GreetingRequest,
                      path='hellogreeting/{id}', http_method='GET',
                      name='greetings.getGreeting')
    def greeting_get(self, request):
        try:
            return STORED_GREETINGS.items[request.id]
        except (IndexError, TypeError):
            raise endpoints.NotFoundException('Greeting %s not found.' %
                                              (request.id,))


APPLICATION = endpoints.api_server([HelloWorldApi])
{'fraction_non_alphanumeric': 0.10563737938039613, 'fraction_numerical': 0.003809040121889284, 'mean_word_length': 3.159450897571278, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5317385', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1112, 'n_words': 212}