Skip to content

Commit 5c655ad

Browse files
feat(api): manual updates
1 parent 04af9da commit 5c655ad

3 files changed

Lines changed: 69 additions & 49 deletions

File tree

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 19
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/sent%2Fsent-dm-0fb2b782f3dce1a18dea4f67716279aa820eb326bb218ad7d71d46d4440e9933.yml
33
openapi_spec_hash: 9a292964e73307d88c8cc119c9151f16
4-
config_hash: a738646adecab6cc88420c3369fdb298
4+
config_hash: 93ac5bcbec6dc5214082e25c6677f77b

README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ client = SentDm(
3636
sender_id=os.environ.get("SENT_DM_SENDER_ID"), # This is the default and can be omitted
3737
)
3838

39-
client.templates.delete(
40-
"REPLACE_ME",
39+
client.messages.send_to_phone(
40+
phone_number="+1234567890",
41+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
4142
)
4243
```
4344

@@ -62,8 +63,9 @@ client = AsyncSentDm(
6263

6364

6465
async def main() -> None:
65-
await client.templates.delete(
66-
"REPLACE_ME",
66+
await client.messages.send_to_phone(
67+
phone_number="+1234567890",
68+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
6769
)
6870

6971

@@ -98,8 +100,9 @@ async def main() -> None:
98100
sender_id=os.environ.get("SENT_DM_SENDER_ID"), # This is the default and can be omitted
99101
http_client=DefaultAioHttpClient(),
100102
) as client:
101-
await client.templates.delete(
102-
"REPLACE_ME",
103+
await client.messages.send_to_phone(
104+
phone_number="+1234567890",
105+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
103106
)
104107

105108

@@ -197,8 +200,9 @@ from sent_dm import SentDm
197200
client = SentDm()
198201

199202
try:
200-
client.templates.delete(
201-
"REPLACE_ME",
203+
client.messages.send_to_phone(
204+
phone_number="+1234567890",
205+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
202206
)
203207
except sent_dm.APIConnectionError as e:
204208
print("The server could not be reached")
@@ -242,8 +246,9 @@ client = SentDm(
242246
)
243247

244248
# Or, configure per-request:
245-
client.with_options(max_retries=5).templates.delete(
246-
"REPLACE_ME",
249+
client.with_options(max_retries=5).messages.send_to_phone(
250+
phone_number="+1234567890",
251+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
247252
)
248253
```
249254

@@ -267,8 +272,9 @@ client = SentDm(
267272
)
268273

269274
# Override per-request:
270-
client.with_options(timeout=5.0).templates.delete(
271-
"REPLACE_ME",
275+
client.with_options(timeout=5.0).messages.send_to_phone(
276+
phone_number="+1234567890",
277+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
272278
)
273279
```
274280

@@ -310,13 +316,14 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
310316
from sent_dm import SentDm
311317

312318
client = SentDm()
313-
response = client.templates.with_raw_response.delete(
314-
"REPLACE_ME",
319+
response = client.messages.with_raw_response.send_to_phone(
320+
phone_number="+1234567890",
321+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
315322
)
316323
print(response.headers.get('X-My-Header'))
317324

318-
template = response.parse() # get the object that `templates.delete()` would have returned
319-
print(template)
325+
message = response.parse() # get the object that `messages.send_to_phone()` would have returned
326+
print(message)
320327
```
321328

322329
These methods return an [`APIResponse`](https://github.com/stainless-sdks/sent-dm-python/tree/main/src/sent_dm/_response.py) object.
@@ -330,8 +337,9 @@ The above interface eagerly reads the full response body when you make the reque
330337
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
331338

332339
```python
333-
with client.templates.with_streaming_response.delete(
334-
"REPLACE_ME",
340+
with client.messages.with_streaming_response.send_to_phone(
341+
phone_number="+1234567890",
342+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
335343
) as response:
336344
print(response.headers.get("X-My-Header"))
337345

tests/test_client.py

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -931,22 +931,24 @@ def test_parse_retry_after_header(
931931
@mock.patch("sent_dm._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
932932
@pytest.mark.respx(base_url=base_url)
933933
def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, client: SentDm) -> None:
934-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(
935-
side_effect=httpx.TimeoutException("Test timeout error")
936-
)
934+
respx_mock.post("/v2/messages/phone").mock(side_effect=httpx.TimeoutException("Test timeout error"))
937935

938936
with pytest.raises(APITimeoutError):
939-
client.templates.with_streaming_response.delete("7ba7b820-9dad-11d1-80b4-00c04fd430c8").__enter__()
937+
client.messages.with_streaming_response.send_to_phone(
938+
phone_number="+1234567890", template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8"
939+
).__enter__()
940940

941941
assert _get_open_connections(client) == 0
942942

943943
@mock.patch("sent_dm._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
944944
@pytest.mark.respx(base_url=base_url)
945945
def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, client: SentDm) -> None:
946-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(return_value=httpx.Response(500))
946+
respx_mock.post("/v2/messages/phone").mock(return_value=httpx.Response(500))
947947

948948
with pytest.raises(APIStatusError):
949-
client.templates.with_streaming_response.delete("7ba7b820-9dad-11d1-80b4-00c04fd430c8").__enter__()
949+
client.messages.with_streaming_response.send_to_phone(
950+
phone_number="+1234567890", template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8"
951+
).__enter__()
950952
assert _get_open_connections(client) == 0
951953

952954
@pytest.mark.parametrize("failures_before_success", [0, 2, 4])
@@ -973,9 +975,11 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
973975
return httpx.Response(500)
974976
return httpx.Response(200)
975977

976-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(side_effect=retry_handler)
978+
respx_mock.post("/v2/messages/phone").mock(side_effect=retry_handler)
977979

978-
response = client.templates.with_raw_response.delete("7ba7b820-9dad-11d1-80b4-00c04fd430c8")
980+
response = client.messages.with_raw_response.send_to_phone(
981+
phone_number="+1234567890", template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8"
982+
)
979983

980984
assert response.retries_taken == failures_before_success
981985
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
@@ -997,10 +1001,12 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
9971001
return httpx.Response(500)
9981002
return httpx.Response(200)
9991003

1000-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(side_effect=retry_handler)
1004+
respx_mock.post("/v2/messages/phone").mock(side_effect=retry_handler)
10011005

1002-
response = client.templates.with_raw_response.delete(
1003-
"7ba7b820-9dad-11d1-80b4-00c04fd430c8", extra_headers={"x-stainless-retry-count": Omit()}
1006+
response = client.messages.with_raw_response.send_to_phone(
1007+
phone_number="+1234567890",
1008+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
1009+
extra_headers={"x-stainless-retry-count": Omit()},
10041010
)
10051011

10061012
assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0
@@ -1022,10 +1028,12 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
10221028
return httpx.Response(500)
10231029
return httpx.Response(200)
10241030

1025-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(side_effect=retry_handler)
1031+
respx_mock.post("/v2/messages/phone").mock(side_effect=retry_handler)
10261032

1027-
response = client.templates.with_raw_response.delete(
1028-
"7ba7b820-9dad-11d1-80b4-00c04fd430c8", extra_headers={"x-stainless-retry-count": "42"}
1033+
response = client.messages.with_raw_response.send_to_phone(
1034+
phone_number="+1234567890",
1035+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
1036+
extra_headers={"x-stainless-retry-count": "42"},
10291037
)
10301038

10311039
assert response.http_request.headers.get("x-stainless-retry-count") == "42"
@@ -1908,25 +1916,23 @@ async def test_parse_retry_after_header(
19081916
@mock.patch("sent_dm._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
19091917
@pytest.mark.respx(base_url=base_url)
19101918
async def test_retrying_timeout_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncSentDm) -> None:
1911-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(
1912-
side_effect=httpx.TimeoutException("Test timeout error")
1913-
)
1919+
respx_mock.post("/v2/messages/phone").mock(side_effect=httpx.TimeoutException("Test timeout error"))
19141920

19151921
with pytest.raises(APITimeoutError):
1916-
await async_client.templates.with_streaming_response.delete(
1917-
"7ba7b820-9dad-11d1-80b4-00c04fd430c8"
1922+
await async_client.messages.with_streaming_response.send_to_phone(
1923+
phone_number="+1234567890", template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8"
19181924
).__aenter__()
19191925

19201926
assert _get_open_connections(async_client) == 0
19211927

19221928
@mock.patch("sent_dm._base_client.BaseClient._calculate_retry_timeout", _low_retry_timeout)
19231929
@pytest.mark.respx(base_url=base_url)
19241930
async def test_retrying_status_errors_doesnt_leak(self, respx_mock: MockRouter, async_client: AsyncSentDm) -> None:
1925-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(return_value=httpx.Response(500))
1931+
respx_mock.post("/v2/messages/phone").mock(return_value=httpx.Response(500))
19261932

19271933
with pytest.raises(APIStatusError):
1928-
await async_client.templates.with_streaming_response.delete(
1929-
"7ba7b820-9dad-11d1-80b4-00c04fd430c8"
1934+
await async_client.messages.with_streaming_response.send_to_phone(
1935+
phone_number="+1234567890", template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8"
19301936
).__aenter__()
19311937
assert _get_open_connections(async_client) == 0
19321938

@@ -1954,9 +1960,11 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
19541960
return httpx.Response(500)
19551961
return httpx.Response(200)
19561962

1957-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(side_effect=retry_handler)
1963+
respx_mock.post("/v2/messages/phone").mock(side_effect=retry_handler)
19581964

1959-
response = await client.templates.with_raw_response.delete("7ba7b820-9dad-11d1-80b4-00c04fd430c8")
1965+
response = await client.messages.with_raw_response.send_to_phone(
1966+
phone_number="+1234567890", template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8"
1967+
)
19601968

19611969
assert response.retries_taken == failures_before_success
19621970
assert int(response.http_request.headers.get("x-stainless-retry-count")) == failures_before_success
@@ -1978,10 +1986,12 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
19781986
return httpx.Response(500)
19791987
return httpx.Response(200)
19801988

1981-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(side_effect=retry_handler)
1989+
respx_mock.post("/v2/messages/phone").mock(side_effect=retry_handler)
19821990

1983-
response = await client.templates.with_raw_response.delete(
1984-
"7ba7b820-9dad-11d1-80b4-00c04fd430c8", extra_headers={"x-stainless-retry-count": Omit()}
1991+
response = await client.messages.with_raw_response.send_to_phone(
1992+
phone_number="+1234567890",
1993+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
1994+
extra_headers={"x-stainless-retry-count": Omit()},
19851995
)
19861996

19871997
assert len(response.http_request.headers.get_list("x-stainless-retry-count")) == 0
@@ -2003,10 +2013,12 @@ def retry_handler(_request: httpx.Request) -> httpx.Response:
20032013
return httpx.Response(500)
20042014
return httpx.Response(200)
20052015

2006-
respx_mock.delete("/v2/templates/7ba7b820-9dad-11d1-80b4-00c04fd430c8").mock(side_effect=retry_handler)
2016+
respx_mock.post("/v2/messages/phone").mock(side_effect=retry_handler)
20072017

2008-
response = await client.templates.with_raw_response.delete(
2009-
"7ba7b820-9dad-11d1-80b4-00c04fd430c8", extra_headers={"x-stainless-retry-count": "42"}
2018+
response = await client.messages.with_raw_response.send_to_phone(
2019+
phone_number="+1234567890",
2020+
template_id="7ba7b820-9dad-11d1-80b4-00c04fd430c8",
2021+
extra_headers={"x-stainless-retry-count": "42"},
20102022
)
20112023

20122024
assert response.http_request.headers.get("x-stainless-retry-count") == "42"

0 commit comments

Comments
 (0)