def set_background_image(self, image: Union[str, BackgroundImage]):
     if isinstance(image, str):
         self._data["backgroundImage"] = image
     elif isinstance(image, BackgroundImage):
         self._data["backgroundImage"] = image.as_data()
     else:
         raise CardException("Invalid image type")
 def set_height(self, height: Union[str, BlockElementHeight]):
     if isinstance(height, BlockElementHeight):
         self._data["height"] = height
     elif isinstance(height, str):
         self._data["height"] = height
     else:
         raise CardException("Invalid height type")
 def set_fallback(self, fallback):
     if isinstance(fallback, FallbackOption):
         self._data["fallback"] = fallback
     elif isinstance(fallback, Column):
         self._data["fallback"] = fallback.as_data()
     else:
         raise CardException("Invalid fallback type")
 def set_width(self, width: Union[str, int, Width]):
     if isinstance(width, Width):
         self._data["width"] = width
     elif isinstance(width, (str, int)):
         self._data["width"] = width
     else:
         raise CardException("Invalid width type")
 def _check_choice(self, choice, choices):
     choice_value = choice._get_value()
     values_list = (c["value"] for c in choices)
     if choice_value in values_list:
         raise CardException(
             "Choice with this 'value' [{}] already added".format(
                 choice_value))
Beispiel #6
0
 def add_expected_actors(self, expected_actors: Union[str, List[str]]):
     self._payload.setdefault("expectedActors", [])
     if isinstance(expected_actors, (list, set, tuple)):
         self._payload["expectedActors"].extend(list(expected_actors))
     elif isinstance(expected_actors, str):
         self._payload["expectedActors"].append(expected_actors)
     else:
         raise CardException("Invalid expected_actors type")
 def __init__(self,
              method: str,
              url: str,
              title=None,
              headers: list = None,
              body=None,
              **kwargs):
     if method not in METHODS:
         raise CardException(
             "Invalid method. Available methods are: {}".format(METHODS))
     if method == "POST" and not body:
         raise CardException("If method is POST body must be provided")
     self._data = {"type": "Action.Http", "method": method, "url": url}
     super().__init__(**kwargs)
     if title is not None:
         self.set_title(title)
     if headers:
         self.add_headers(headers)
     if body is not None:
         self.set_body(body)
Beispiel #8
0
 def set_version(self, version: str):
     if version not in VERSIONS:
         raise CardException("Invalid version. Supported versions are: {}".format(VERSIONS))
     self._payload["version"] = version
 def _check_target(self, target: list, targets: list):
     os_type = target._get_os()
     os_list = (x["os"] for x in targets)
     if os_type in os_list:
         raise CardException("Target already set for '{}'".format(os_type))