Skip to content

Commit

Permalink
* feat: json content type (#737)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people committed Feb 23, 2024
1 parent 69441eb commit 7b52a49
Show file tree
Hide file tree
Showing 22 changed files with 1,089 additions and 230 deletions.
9 changes: 9 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
_`MAJOR` version bumps will have upgrade notes
posted here._

## [2024-02-20] 8.x.x to 9.x.x
### Overview

##### 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

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.
We're pleased to inform you that version 9.0.0 adds support for the application/json content type in the request body.


## [2023-04-05] 7.x.x to 8.x.x

- **Supported Python versions updated**
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/http/test_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,32 @@ def test_last_request_last_response_exist(self):
"testing-unicode: Ω≈ç√, 💩", self.client._test_only_last_response.text
)

def test_request_with_json(self):
self.request_mock.url = "https://api.twilio.com/"
self.request_mock.headers = {"Host": "other.twilio.com"}

self.client.request(
"doesnt-matter-method",
"doesnt-matter-url",
{"params-value": "params-key"},
{"json-key": "json-value"},
{"Content-Type": "application/json"},
)

self.assertIsNotNone(self.client._test_only_last_request)
self.assertEqual(
{"Content-Type": "application/json"},
self.client._test_only_last_request.headers,
)

self.assertIsNotNone(self.client._test_only_last_response)

if self.client._test_only_last_response is not None:
self.assertEqual(200, self.client._test_only_last_response.status_code)
self.assertEqual(
"testing-unicode: Ω≈ç√, 💩", self.client._test_only_last_response.text
)

def test_last_response_empty_on_error(self):
self.session_mock.send.side_effect = Exception("voltron")

Expand Down
13 changes: 7 additions & 6 deletions twilio/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ def __init__(
):
"""
Constructor for the TwilioHttpClient
:param pool_connections
:param request_hooks
:param timeout: Timeout for the requests.
Timeout should never be zero (0) or less.
Timeout should never be zero (0) or less
:param logger
:param proxy: Http proxy for the requests session
:param max_retries: Maximum number of retries each request should attempt
Expand Down Expand Up @@ -65,10 +64,10 @@ def request(
:param headers: HTTP Headers to send with the request
:param auth: Basic Auth arguments
:param timeout: Socket/Read timeout for the request
:param allow_redirects: Whether or not to allow redirects
:param allow_redirects: Whether to allow redirects
See the requests documentation for explanation of all these parameters
:return: An http response
:return: An HTTP response
"""
if timeout is None:
timeout = self.timeout
Expand All @@ -79,12 +78,14 @@ def request(
"method": method.upper(),
"url": url,
"params": params,
"data": data,
"headers": headers,
"auth": auth,
"hooks": self.request_hooks,
}

if headers and headers.get("Content-Type") == "application/json":
kwargs["json"] = data
else:
kwargs["data"] = data
self.log_request(kwargs)

self._test_only_last_response = None
Expand Down
15 changes: 15 additions & 0 deletions twilio/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from twilio.rest.ip_messaging import IpMessaging
from twilio.rest.lookups import Lookups
from twilio.rest.media import Media
from twilio.rest.preview_messaging import PreviewMessaging
from twilio.rest.messaging import Messaging
from twilio.rest.microvisor import Microvisor
from twilio.rest.monitor import Monitor
Expand Down Expand Up @@ -135,6 +136,7 @@ def __init__(
self._ip_messaging: Optional["IpMessaging"] = None
self._lookups: Optional["Lookups"] = None
self._media: Optional["Media"] = None
self._preview_messaging: Optional["PreviewMessaging"] = None
self._messaging: Optional["Messaging"] = None
self._microvisor: Optional["Microvisor"] = None
self._monitor: Optional["Monitor"] = None
Expand Down Expand Up @@ -338,6 +340,19 @@ def media(self) -> "Media":
self._media = Media(self)
return self._media

@property
def preview_messaging(self) -> "PreviewMessaging":
"""
Access the PreviewMessaging Twilio Domain
:returns: PreviewMessaging Twilio Domain
"""
if self._preview_messaging is None:
from twilio.rest.preview_messaging import PreviewMessaging

self._preview_messaging = PreviewMessaging(self)
return self._preview_messaging

@property
def messaging(self) -> "Messaging":
"""
Expand Down
Loading

0 comments on commit 7b52a49

Please sign in to comment.