-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an API response effect; updated API handler to handle response …
…effects
- Loading branch information
Showing
6 changed files
with
90 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
from collections.abc import Mapping | ||
from typing import Any | ||
|
||
from canvas_generated.messages.effects_pb2 import EffectType | ||
from canvas_sdk.effects import Effect | ||
|
||
|
||
class SimpleAPIResponse: | ||
"""SimpleAPI response class.""" | ||
|
||
def __init__( | ||
self, content: Mapping[str, Any], status_code: int, headers: Mapping[str, Any] | None = None | ||
) -> None: | ||
self._content = content | ||
self._status_code = status_code | ||
self._headers = {**(headers or {}), "Content-Type": "application/json"} | ||
|
||
def apply(self) -> Effect: | ||
"""Convert the response into an effect.""" | ||
payload = { | ||
"body": self._content, | ||
"status_code": self._status_code, | ||
"headers": self._headers or {}, | ||
} | ||
|
||
return Effect(type=EffectType.SIMPLE_API_RESPONSE, payload=json.dumps(payload)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .api import Request, SimpleAPI | ||
from .api import SimpleAPI, SimpleAPIRequest | ||
|
||
__all__ = ["Request", "SimpleAPI"] | ||
__all__ = ["SimpleAPI", "SimpleAPIRequest"] |
Oops, something went wrong.