Skip to content

Commit 4f4bf9f

Browse files
feat(api): webhooks and stream
1 parent c726781 commit 4f4bf9f

19 files changed

Lines changed: 1989 additions & 7 deletions

‎.stats.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 27
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api/moderation-api-6644e98b7909ae773e2140200f43feaf75382b94fd18918e1ea0f630419839c9.yml
1+
configured_endpoints: 34
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/moderation-api/moderation-api-407f949d64421d5454ec0f4b518a19c14daa41312b6efa370eac631e495ca44a.yml
33
openapi_spec_hash: 7bcba0df8e8cb1c5a2d02efc3d6c0fa5
4-
config_hash: 827ffbc2bec8c435226c9080d32e6833
4+
config_hash: 6e090a71f4d354167d93b4534a0e7f05

‎api.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ from moderation_api.types import ContentSubmitResponse
9292

9393
Methods:
9494

95+
- <code title="get /stream">client.content.<a href="./src/moderation_api/resources/content.py">stream</a>() -> None</code>
9596
- <code title="post /moderate">client.content.<a href="./src/moderation_api/resources/content.py">submit</a>(\*\*<a href="src/moderation_api/types/content_submit_params.py">params</a>) -> <a href="./src/moderation_api/types/content_submit_response.py">ContentSubmitResponse</a></code>
9697

9798
# Account
@@ -151,3 +152,37 @@ Methods:
151152

152153
- <code title="post /wordlist/{id}/words">client.wordlist.words.<a href="./src/moderation_api/resources/wordlist/words.py">add</a>(id, \*\*<a href="src/moderation_api/types/wordlist/word_add_params.py">params</a>) -> <a href="./src/moderation_api/types/wordlist/word_add_response.py">WordAddResponse</a></code>
153154
- <code title="delete /wordlist/{id}/words">client.wordlist.words.<a href="./src/moderation_api/resources/wordlist/words.py">remove</a>(id, \*\*<a href="src/moderation_api/types/wordlist/word_remove_params.py">params</a>) -> <a href="./src/moderation_api/types/wordlist/word_remove_response.py">WordRemoveResponse</a></code>
155+
156+
# Webhooks
157+
158+
Types:
159+
160+
```python
161+
from moderation_api.types import (
162+
WebhookCreateResponse,
163+
WebhookRetrieveResponse,
164+
WebhookUpdateResponse,
165+
WebhookListResponse,
166+
WebhookDeleteResponse,
167+
)
168+
```
169+
170+
Methods:
171+
172+
- <code title="post /webhooks">client.webhooks.<a href="./src/moderation_api/resources/webhooks.py">create</a>(\*\*<a href="src/moderation_api/types/webhook_create_params.py">params</a>) -> <a href="./src/moderation_api/types/webhook_create_response.py">WebhookCreateResponse</a></code>
173+
- <code title="get /webhooks/{id}">client.webhooks.<a href="./src/moderation_api/resources/webhooks.py">retrieve</a>(id) -> <a href="./src/moderation_api/types/webhook_retrieve_response.py">WebhookRetrieveResponse</a></code>
174+
- <code title="put /webhooks/{id}">client.webhooks.<a href="./src/moderation_api/resources/webhooks.py">update</a>(id, \*\*<a href="src/moderation_api/types/webhook_update_params.py">params</a>) -> <a href="./src/moderation_api/types/webhook_update_response.py">WebhookUpdateResponse</a></code>
175+
- <code title="get /webhooks">client.webhooks.<a href="./src/moderation_api/resources/webhooks.py">list</a>() -> <a href="./src/moderation_api/types/webhook_list_response.py">WebhookListResponse</a></code>
176+
- <code title="delete /webhooks/{id}">client.webhooks.<a href="./src/moderation_api/resources/webhooks.py">delete</a>(id) -> <a href="./src/moderation_api/types/webhook_delete_response.py">WebhookDeleteResponse</a></code>
177+
178+
# WebhookSecret
179+
180+
Types:
181+
182+
```python
183+
from moderation_api.types import WebhookSecretRetrieveResponse
184+
```
185+
186+
Methods:
187+
188+
- <code title="get /webhook-secret">client.webhook_secret.<a href="./src/moderation_api/resources/webhook_secret.py">retrieve</a>() -> <a href="./src/moderation_api/types/webhook_secret_retrieve_response.py">WebhookSecretRetrieveResponse</a></code>

‎src/moderation_api/_client.py‎

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
)
3636

3737
if TYPE_CHECKING:
38-
from .resources import auth, queue, account, actions, authors, content, wordlist
38+
from .resources import auth, queue, account, actions, authors, content, webhooks, wordlist, webhook_secret
3939
from .resources.auth import AuthResource, AsyncAuthResource
4040
from .resources.account import AccountResource, AsyncAccountResource
4141
from .resources.authors import AuthorsResource, AsyncAuthorsResource
4242
from .resources.content import ContentResource, AsyncContentResource
43+
from .resources.webhooks import WebhooksResource, AsyncWebhooksResource
4344
from .resources.queue.queue import QueueResource, AsyncQueueResource
45+
from .resources.webhook_secret import WebhookSecretResource, AsyncWebhookSecretResource
4446
from .resources.actions.actions import ActionsResource, AsyncActionsResource
4547
from .resources.wordlist.wordlist import WordlistResource, AsyncWordlistResource
4648

@@ -97,6 +99,7 @@ def __init__(
9799

98100
if base_url is None:
99101
base_url = os.environ.get("MODERATION_API_BASE_URL")
102+
self._base_url_overridden = base_url is not None
100103
if base_url is None:
101104
base_url = f"https://api.moderationapi.com/v1"
102105

@@ -162,6 +165,18 @@ def wordlist(self) -> WordlistResource:
162165

163166
return WordlistResource(self)
164167

168+
@cached_property
169+
def webhooks(self) -> WebhooksResource:
170+
from .resources.webhooks import WebhooksResource
171+
172+
return WebhooksResource(self)
173+
174+
@cached_property
175+
def webhook_secret(self) -> WebhookSecretResource:
176+
from .resources.webhook_secret import WebhookSecretResource
177+
178+
return WebhookSecretResource(self)
179+
165180
@cached_property
166181
def with_raw_response(self) -> ModerationAPIWithRawResponse:
167182
return ModerationAPIWithRawResponse(self)
@@ -226,7 +241,7 @@ def copy(
226241
params = set_default_query
227242

228243
http_client = http_client or self._client
229-
return self.__class__(
244+
client = self.__class__(
230245
secret_key=secret_key or self.secret_key,
231246
base_url=base_url or self.base_url,
232247
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
@@ -236,6 +251,8 @@ def copy(
236251
default_query=params,
237252
**_extra_kwargs,
238253
)
254+
client._base_url_overridden = self._base_url_overridden or base_url is not None
255+
return client
239256

240257
# Alias for `copy` for nicer inline usage, e.g.
241258
# client.with_options(timeout=10).foo.create(...)
@@ -316,6 +333,7 @@ def __init__(
316333

317334
if base_url is None:
318335
base_url = os.environ.get("MODERATION_API_BASE_URL")
336+
self._base_url_overridden = base_url is not None
319337
if base_url is None:
320338
base_url = f"https://api.moderationapi.com/v1"
321339

@@ -381,6 +399,18 @@ def wordlist(self) -> AsyncWordlistResource:
381399

382400
return AsyncWordlistResource(self)
383401

402+
@cached_property
403+
def webhooks(self) -> AsyncWebhooksResource:
404+
from .resources.webhooks import AsyncWebhooksResource
405+
406+
return AsyncWebhooksResource(self)
407+
408+
@cached_property
409+
def webhook_secret(self) -> AsyncWebhookSecretResource:
410+
from .resources.webhook_secret import AsyncWebhookSecretResource
411+
412+
return AsyncWebhookSecretResource(self)
413+
384414
@cached_property
385415
def with_raw_response(self) -> AsyncModerationAPIWithRawResponse:
386416
return AsyncModerationAPIWithRawResponse(self)
@@ -445,7 +475,7 @@ def copy(
445475
params = set_default_query
446476

447477
http_client = http_client or self._client
448-
return self.__class__(
478+
client = self.__class__(
449479
secret_key=secret_key or self.secret_key,
450480
base_url=base_url or self.base_url,
451481
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
@@ -455,6 +485,8 @@ def copy(
455485
default_query=params,
456486
**_extra_kwargs,
457487
)
488+
client._base_url_overridden = self._base_url_overridden or base_url is not None
489+
return client
458490

459491
# Alias for `copy` for nicer inline usage, e.g.
460492
# client.with_options(timeout=10).foo.create(...)
@@ -542,6 +574,18 @@ def wordlist(self) -> wordlist.WordlistResourceWithRawResponse:
542574

543575
return WordlistResourceWithRawResponse(self._client.wordlist)
544576

577+
@cached_property
578+
def webhooks(self) -> webhooks.WebhooksResourceWithRawResponse:
579+
from .resources.webhooks import WebhooksResourceWithRawResponse
580+
581+
return WebhooksResourceWithRawResponse(self._client.webhooks)
582+
583+
@cached_property
584+
def webhook_secret(self) -> webhook_secret.WebhookSecretResourceWithRawResponse:
585+
from .resources.webhook_secret import WebhookSecretResourceWithRawResponse
586+
587+
return WebhookSecretResourceWithRawResponse(self._client.webhook_secret)
588+
545589

546590
class AsyncModerationAPIWithRawResponse:
547591
_client: AsyncModerationAPI
@@ -591,6 +635,18 @@ def wordlist(self) -> wordlist.AsyncWordlistResourceWithRawResponse:
591635

592636
return AsyncWordlistResourceWithRawResponse(self._client.wordlist)
593637

638+
@cached_property
639+
def webhooks(self) -> webhooks.AsyncWebhooksResourceWithRawResponse:
640+
from .resources.webhooks import AsyncWebhooksResourceWithRawResponse
641+
642+
return AsyncWebhooksResourceWithRawResponse(self._client.webhooks)
643+
644+
@cached_property
645+
def webhook_secret(self) -> webhook_secret.AsyncWebhookSecretResourceWithRawResponse:
646+
from .resources.webhook_secret import AsyncWebhookSecretResourceWithRawResponse
647+
648+
return AsyncWebhookSecretResourceWithRawResponse(self._client.webhook_secret)
649+
594650

595651
class ModerationAPIWithStreamedResponse:
596652
_client: ModerationAPI
@@ -640,6 +696,18 @@ def wordlist(self) -> wordlist.WordlistResourceWithStreamingResponse:
640696

641697
return WordlistResourceWithStreamingResponse(self._client.wordlist)
642698

699+
@cached_property
700+
def webhooks(self) -> webhooks.WebhooksResourceWithStreamingResponse:
701+
from .resources.webhooks import WebhooksResourceWithStreamingResponse
702+
703+
return WebhooksResourceWithStreamingResponse(self._client.webhooks)
704+
705+
@cached_property
706+
def webhook_secret(self) -> webhook_secret.WebhookSecretResourceWithStreamingResponse:
707+
from .resources.webhook_secret import WebhookSecretResourceWithStreamingResponse
708+
709+
return WebhookSecretResourceWithStreamingResponse(self._client.webhook_secret)
710+
643711

644712
class AsyncModerationAPIWithStreamedResponse:
645713
_client: AsyncModerationAPI
@@ -689,6 +757,18 @@ def wordlist(self) -> wordlist.AsyncWordlistResourceWithStreamingResponse:
689757

690758
return AsyncWordlistResourceWithStreamingResponse(self._client.wordlist)
691759

760+
@cached_property
761+
def webhooks(self) -> webhooks.AsyncWebhooksResourceWithStreamingResponse:
762+
from .resources.webhooks import AsyncWebhooksResourceWithStreamingResponse
763+
764+
return AsyncWebhooksResourceWithStreamingResponse(self._client.webhooks)
765+
766+
@cached_property
767+
def webhook_secret(self) -> webhook_secret.AsyncWebhookSecretResourceWithStreamingResponse:
768+
from .resources.webhook_secret import AsyncWebhookSecretResourceWithStreamingResponse
769+
770+
return AsyncWebhookSecretResourceWithStreamingResponse(self._client.webhook_secret)
771+
692772

693773
Client = ModerationAPI
694774

‎src/moderation_api/resources/__init__.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
ContentResourceWithStreamingResponse,
4949
AsyncContentResourceWithStreamingResponse,
5050
)
51+
from .webhooks import (
52+
WebhooksResource,
53+
AsyncWebhooksResource,
54+
WebhooksResourceWithRawResponse,
55+
AsyncWebhooksResourceWithRawResponse,
56+
WebhooksResourceWithStreamingResponse,
57+
AsyncWebhooksResourceWithStreamingResponse,
58+
)
5159
from .wordlist import (
5260
WordlistResource,
5361
AsyncWordlistResource,
@@ -56,6 +64,14 @@
5664
WordlistResourceWithStreamingResponse,
5765
AsyncWordlistResourceWithStreamingResponse,
5866
)
67+
from .webhook_secret import (
68+
WebhookSecretResource,
69+
AsyncWebhookSecretResource,
70+
WebhookSecretResourceWithRawResponse,
71+
AsyncWebhookSecretResourceWithRawResponse,
72+
WebhookSecretResourceWithStreamingResponse,
73+
AsyncWebhookSecretResourceWithStreamingResponse,
74+
)
5975

6076
__all__ = [
6177
"AuthorsResource",
@@ -100,4 +116,16 @@
100116
"AsyncWordlistResourceWithRawResponse",
101117
"WordlistResourceWithStreamingResponse",
102118
"AsyncWordlistResourceWithStreamingResponse",
119+
"WebhooksResource",
120+
"AsyncWebhooksResource",
121+
"WebhooksResourceWithRawResponse",
122+
"AsyncWebhooksResourceWithRawResponse",
123+
"WebhooksResourceWithStreamingResponse",
124+
"AsyncWebhooksResourceWithStreamingResponse",
125+
"WebhookSecretResource",
126+
"AsyncWebhookSecretResource",
127+
"WebhookSecretResourceWithRawResponse",
128+
"AsyncWebhookSecretResourceWithRawResponse",
129+
"WebhookSecretResourceWithStreamingResponse",
130+
"AsyncWebhookSecretResourceWithStreamingResponse",
103131
]

0 commit comments

Comments
 (0)