Пример #1
0
class AuthApi(lightbus.Api):
    user_registered = lightbus.Event(parameters=("username", "email"))

    class Meta:
        name = "auth"

    def check_password(self, username, password):
        return username == "admin" and password == "secret"
Пример #2
0
class ApiA(lightbus.Api):
    event_a = lightbus.Event()

    class Meta:
        name = "api_a"

    def rpc_a(self):
        return "A"
Пример #3
0
class ApiB(lightbus.Api):
    event_b = lightbus.Event()

    class Meta:
        name = "api_b"

    def rpc_b(self):
        return "b"
Пример #4
0
class BenchmarkApi(lightbus.Api):
    fire_me = lightbus.Event()

    class Meta:
        name = "benchmark"

    def call_me(self):
        return True
Пример #5
0
class AuthApi(lightbus.Api):
    user_registered = lightbus.Event(parameters=(
        lightbus.Parameter("username", str),
        lightbus.Parameter("email", str),
        lightbus.Parameter("is_admin", bool, default=False),
    ))

    class Meta:
        name = "auth"

    def check_password(self, username: str, password: str) -> bool:
        return username == "admin" and password == "secret"
Пример #6
0
class AnalyticsApi(lightbus.Api):
    page_view = lightbus.Event(
        parameters=(
            lightbus.Parameter("pk", int),
            lightbus.Parameter("viewed_at", datetime),
            lightbus.Parameter("url", str),
            lightbus.Parameter("user_agent", str),
        )
    )

    @uses_django_db
    def get_total(self, url: str) -> int:
        from lightbus_examples.ex06_django.example_app.models import PageView

        return PageView.objects.filter(url=url).count()

    class Meta:
        name = "analytics"
Пример #7
0
    class ApiWithVersion(lightbus.Api):
        my_event = lightbus.Event()

        class Meta:
            name = "versioned_api"
            version = 5
Пример #8
0
class StoreApi(lightbus.Api):
    page_view = lightbus.Event(parameters=("url",))

    class Meta:
        name = "store"
Пример #9
0
    class MyApi(lightbus.Api):
        my_event = lightbus.Event()

        class Meta:
            name = "my_api"