Moved /streams/now -> /now

Response is now JSON object of the form:
```json
{
    "epoch_time": 1629572206
}
```

It is not authenticated.
pull/105/head
Neeraj Kashyap 2021-08-21 11:55:59 -07:00
rodzic 036d1c169d
commit 6443ad3da5
3 zmienionych plików z 14 dodań i 6 usunięć

Wyświetl plik

@ -2,6 +2,7 @@
The Moonstream HTTP API The Moonstream HTTP API
""" """
import logging import logging
import time
from fastapi import FastAPI, Form from fastapi import FastAPI, Form
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
@ -39,6 +40,11 @@ async def version_handler() -> data.VersionResponse:
return data.VersionResponse(version=MOONSTREAM_VERSION) return data.VersionResponse(version=MOONSTREAM_VERSION)
@app.get("/now", tags=["time"])
async def now_handler() -> int:
return data.NowResponse(epoch_time=int(time.time()))
app.mount("/subscriptions", subscriptions_api) app.mount("/subscriptions", subscriptions_api)
app.mount("/users", users_api) app.mount("/users", users_api)
app.mount("/streams", streams_api) app.mount("/streams", streams_api)

Wyświetl plik

@ -52,6 +52,14 @@ class VersionResponse(BaseModel):
version: str version: str
class NowResponse(BaseModel):
"""
Schema for responses on /now endpoint
"""
epoch_time: int
class SubscriptionUpdate(BaseModel): class SubscriptionUpdate(BaseModel):
update: Dict[str, Any] update: Dict[str, Any]
drop_keys: List[str] = Field(default_factory=list) drop_keys: List[str] = Field(default_factory=list)

Wyświetl plik

@ -2,7 +2,6 @@
The Moonstream subscriptions HTTP API The Moonstream subscriptions HTTP API
""" """
import logging import logging
import time
from typing import Dict, List, Optional from typing import Dict, List, Optional
from bugout.data import BugoutResource from bugout.data import BugoutResource
@ -88,11 +87,6 @@ def get_user_subscriptions(token: str) -> Dict[str, List[BugoutResource]]:
return user_subscriptions return user_subscriptions
@app.get("/now", tags=["streams"])
async def now_handler() -> int:
return int(time.time())
@app.get("/", tags=["streams"], response_model=data.GetEventsResponse) @app.get("/", tags=["streams"], response_model=data.GetEventsResponse)
async def stream_handler( async def stream_handler(
request: Request, request: Request,