Skip to content

Commit

Permalink
Added an API response effect; updated API handler to handle response …
Browse files Browse the repository at this point in the history
…effects
  • Loading branch information
csande committed Feb 4, 2025
1 parent eb0475f commit 195074c
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 13 deletions.
4 changes: 2 additions & 2 deletions canvas_generated/messages/effects_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions canvas_generated/messages/effects_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class EffectType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
PATIENT_PORTAL__APPOINTMENTS__FORM_PROVIDERS__PRE_SEARCH_RESULTS: _ClassVar[EffectType]
PATIENT_PORTAL__APPOINTMENTS__FORM_PROVIDERS__POST_SEARCH_RESULTS: _ClassVar[EffectType]
LAUNCH_MODAL: _ClassVar[EffectType]
SIMPLE_API_RESPONSE: _ClassVar[EffectType]
UNKNOWN_EFFECT: EffectType
LOG: EffectType
ADD_PLAN_COMMAND: EffectType
Expand Down Expand Up @@ -339,6 +340,7 @@ PATIENT_PORTAL__APPOINTMENTS__FORM_LOCATIONS__POST_SEARCH_RESULTS: EffectType
PATIENT_PORTAL__APPOINTMENTS__FORM_PROVIDERS__PRE_SEARCH_RESULTS: EffectType
PATIENT_PORTAL__APPOINTMENTS__FORM_PROVIDERS__POST_SEARCH_RESULTS: EffectType
LAUNCH_MODAL: EffectType
SIMPLE_API_RESPONSE: EffectType

class Effect(_message.Message):
__slots__ = ("type", "payload", "plugin_name", "classname")
Expand Down
27 changes: 27 additions & 0 deletions canvas_sdk/effects/simple_api.py
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))
4 changes: 2 additions & 2 deletions canvas_sdk/handlers/simple_api/__init__.py
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"]
Loading

0 comments on commit 195074c

Please sign in to comment.