Skip to content

Commit 7b52a49

Browse files
tiwarishubham635manisha1997sbanslatwilio-dx
committed
* feat: json content type (#737)
* feat: add application/json support for client * feat: add application/json support for client * feat: add application/json support for client * feat: add application/json support for client * feat: add application/json support for client * chore: updated changelogs for rc-branch * chore: add domain detail (#739) * feat: add domain detail to twilio python * feat: add domain detail to twilio python * feat: add domain detail to twilio python * feat: add domain detail to twilio python * corrected rc version * Update setup.py * Update setup.py * chore: corrected cluster test * chore: disables cluster test (#765) * chore: disables cluster test * chore: added make prettier to workflow * feat!: MVR release preparation (#766) * feat!: MVR release preparation * fix: added test for json data in http client --------- Co-authored-by: Manisha Singh <[email protected]> Co-authored-by: sbansla <[email protected]> Co-authored-by: Twilio <[email protected]>
1 parent 69441eb commit 7b52a49

File tree

22 files changed

+1089
-230
lines changed

22 files changed

+1089
-230
lines changed

UPGRADE.md

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
_`MAJOR` version bumps will have upgrade notes
44
posted here._
55

6+
## [2024-02-20] 8.x.x to 9.x.x
7+
### Overview
8+
9+
##### Twilio Python Helper Library’s major version 9.0.0 is now available. We ensured that you can upgrade to Python helper Library 9.0.0 version without any breaking changes of existing apis
10+
11+
Behind the scenes Python Helper is now auto-generated via OpenAPI with this release. This enables us to rapidly add new features and enhance consistency across versions and languages.
12+
We're pleased to inform you that version 9.0.0 adds support for the application/json content type in the request body.
13+
14+
615
## [2023-04-05] 7.x.x to 8.x.x
716

817
- **Supported Python versions updated**

tests/unit/http/test_http_client.py

+26
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,32 @@ def test_last_request_last_response_exist(self):
145145
"testing-unicode: Ω≈ç√, 💩", self.client._test_only_last_response.text
146146
)
147147

148+
def test_request_with_json(self):
149+
self.request_mock.url = "https://api.twilio.com/"
150+
self.request_mock.headers = {"Host": "other.twilio.com"}
151+
152+
self.client.request(
153+
"doesnt-matter-method",
154+
"doesnt-matter-url",
155+
{"params-value": "params-key"},
156+
{"json-key": "json-value"},
157+
{"Content-Type": "application/json"},
158+
)
159+
160+
self.assertIsNotNone(self.client._test_only_last_request)
161+
self.assertEqual(
162+
{"Content-Type": "application/json"},
163+
self.client._test_only_last_request.headers,
164+
)
165+
166+
self.assertIsNotNone(self.client._test_only_last_response)
167+
168+
if self.client._test_only_last_response is not None:
169+
self.assertEqual(200, self.client._test_only_last_response.status_code)
170+
self.assertEqual(
171+
"testing-unicode: Ω≈ç√, 💩", self.client._test_only_last_response.text
172+
)
173+
148174
def test_last_response_empty_on_error(self):
149175
self.session_mock.send.side_effect = Exception("voltron")
150176

twilio/http/http_client.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ def __init__(
2727
):
2828
"""
2929
Constructor for the TwilioHttpClient
30-
3130
:param pool_connections
3231
:param request_hooks
3332
:param timeout: Timeout for the requests.
34-
Timeout should never be zero (0) or less.
33+
Timeout should never be zero (0) or less
3534
:param logger
3635
:param proxy: Http proxy for the requests session
3736
:param max_retries: Maximum number of retries each request should attempt
@@ -65,10 +64,10 @@ def request(
6564
:param headers: HTTP Headers to send with the request
6665
:param auth: Basic Auth arguments
6766
:param timeout: Socket/Read timeout for the request
68-
:param allow_redirects: Whether or not to allow redirects
67+
:param allow_redirects: Whether to allow redirects
6968
See the requests documentation for explanation of all these parameters
7069
71-
:return: An http response
70+
:return: An HTTP response
7271
"""
7372
if timeout is None:
7473
timeout = self.timeout
@@ -79,12 +78,14 @@ def request(
7978
"method": method.upper(),
8079
"url": url,
8180
"params": params,
82-
"data": data,
8381
"headers": headers,
8482
"auth": auth,
8583
"hooks": self.request_hooks,
8684
}
87-
85+
if headers and headers.get("Content-Type") == "application/json":
86+
kwargs["json"] = data
87+
else:
88+
kwargs["data"] = data
8889
self.log_request(kwargs)
8990

9091
self._test_only_last_response = None

twilio/rest/__init__.py

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from twilio.rest.ip_messaging import IpMessaging
2929
from twilio.rest.lookups import Lookups
3030
from twilio.rest.media import Media
31+
from twilio.rest.preview_messaging import PreviewMessaging
3132
from twilio.rest.messaging import Messaging
3233
from twilio.rest.microvisor import Microvisor
3334
from twilio.rest.monitor import Monitor
@@ -135,6 +136,7 @@ def __init__(
135136
self._ip_messaging: Optional["IpMessaging"] = None
136137
self._lookups: Optional["Lookups"] = None
137138
self._media: Optional["Media"] = None
139+
self._preview_messaging: Optional["PreviewMessaging"] = None
138140
self._messaging: Optional["Messaging"] = None
139141
self._microvisor: Optional["Microvisor"] = None
140142
self._monitor: Optional["Monitor"] = None
@@ -338,6 +340,19 @@ def media(self) -> "Media":
338340
self._media = Media(self)
339341
return self._media
340342

343+
@property
344+
def preview_messaging(self) -> "PreviewMessaging":
345+
"""
346+
Access the PreviewMessaging Twilio Domain
347+
348+
:returns: PreviewMessaging Twilio Domain
349+
"""
350+
if self._preview_messaging is None:
351+
from twilio.rest.preview_messaging import PreviewMessaging
352+
353+
self._preview_messaging = PreviewMessaging(self)
354+
return self._preview_messaging
355+
341356
@property
342357
def messaging(self) -> "Messaging":
343358
"""

0 commit comments

Comments
 (0)