Update the widget. Returns the updated widget. Parameters differ based on the type of widget. See `Reddit documentation `_ or the document of the particular type of widget. :returns: The updated :class:`.Wid
(self, **kwargs: Any)
| 1803 | self._reddit.delete(path) |
| 1804 | |
| 1805 | def update(self, **kwargs: Any) -> Widget: |
| 1806 | """Update the widget. Returns the updated widget. |
| 1807 | |
| 1808 | Parameters differ based on the type of widget. See `Reddit documentation |
| 1809 | <https://www.reddit.com/dev/api#PUT_api_widget_{widget_id}>`_ or the document of |
| 1810 | the particular type of widget. |
| 1811 | |
| 1812 | :returns: The updated :class:`.Widget`. |
| 1813 | |
| 1814 | For example, update a text widget like so: |
| 1815 | |
| 1816 | .. code-block:: python |
| 1817 | |
| 1818 | text_widget.mod.update(shortName="New text area", text="Hello!") |
| 1819 | |
| 1820 | .. note:: |
| 1821 | |
| 1822 | Most parameters follow the ``lowerCamelCase`` convention. When in doubt, |
| 1823 | check the Reddit documentation linked above. |
| 1824 | |
| 1825 | """ |
| 1826 | path = API_PATH["widget_modify"].format(subreddit=self._subreddit, widget_id=self.widget.id) |
| 1827 | payload = {key: value for key, value in vars(self.widget).items() if not key.startswith("_")} |
| 1828 | del payload["subreddit"] # not JSON serializable |
| 1829 | payload.pop("mod", None) |
| 1830 | payload.update(kwargs) |
| 1831 | widget = self._reddit.put(path, data={"json": dumps(payload, cls=WidgetEncoder)}) |
| 1832 | widget.subreddit = self._subreddit |
| 1833 | return widget |
no test coverage detected