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"
class ApiA(lightbus.Api): event_a = lightbus.Event() class Meta: name = "api_a" def rpc_a(self): return "A"
class ApiB(lightbus.Api): event_b = lightbus.Event() class Meta: name = "api_b" def rpc_b(self): return "b"
class BenchmarkApi(lightbus.Api): fire_me = lightbus.Event() class Meta: name = "benchmark" def call_me(self): return True
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"
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"
class ApiWithVersion(lightbus.Api): my_event = lightbus.Event() class Meta: name = "versioned_api" version = 5
class StoreApi(lightbus.Api): page_view = lightbus.Event(parameters=("url",)) class Meta: name = "store"
class MyApi(lightbus.Api): my_event = lightbus.Event() class Meta: name = "my_api"