@@ -532,7 +532,7 @@ async def get_object_async(self, path, *path_args, params=None):
532
532
response = await self .get_async (path , * path_args , params = params )
533
533
return await self ._response_to_object (response )
534
534
535
- def patch (self , path , * path_args , data = None ):
535
+ def patch (self , path , * path_args , data = None , json_data = None ):
536
536
"""Sends a PATCH request to a given API endpoint.
537
537
538
538
This is a low-level function that returns a raw HTTP response, no error
@@ -543,18 +543,20 @@ def patch(self, path, *path_args, data=None):
543
543
:param path_args: A variable number of arguments that are put into any
544
544
placeholders used in path.
545
545
:param data: Data sent in the request body.
546
+ :param json_data: dict containing data to send in the request body as JSON.
546
547
:type path: str
547
548
:type data: A string or bytes
549
+ :type json_data: dict
548
550
:returns: An instance of :class:`ClientResponse`.
549
551
"""
550
- return make_sync (self .patch_async (path , * path_args , data ))
552
+ return make_sync (self .patch_async (path , * path_args , data , json_data ))
551
553
552
- async def patch_async (self , path , * path_args , data = None ):
554
+ async def patch_async (self , path , * path_args , data = None , json_data = None ):
553
555
"""Like :func:`patch` but returns a coroutine."""
554
556
return ClientResponse (
555
557
await self ._get_session ().patch (
556
558
self ._full_url (path , * path_args ),
557
- data = data , proxy = self ._proxy ))
559
+ data = data , json = json_data , proxy = self ._proxy ))
558
560
559
561
def patch_object (self , path , * path_args , obj ):
560
562
"""Sends a PATCH request for modifying an object.
@@ -575,16 +577,12 @@ def patch_object(self, path, *path_args, obj):
575
577
576
578
async def patch_object_async (self , path , * path_args , obj ):
577
579
"""Like :func:`patch_object` but returns a coroutine."""
578
- data = json . dumps ( {'data' : obj .to_dict (modified_attributes_only = True )})
580
+ data = {'data' : obj .to_dict (modified_attributes_only = True )}
579
581
580
- if self ._user_headers is None :
581
- self ._user_headers = {}
582
- self ._user_headers ['Content-Type' ] = 'application/json'
583
-
584
- response = await self .patch_async (path , * path_args , data = data )
582
+ response = await self .patch_async (path , * path_args , json_data = data )
585
583
return await self ._response_to_object (response )
586
584
587
- def post (self , path , * path_args , data = None ):
585
+ def post (self , path , * path_args , data = None , json_data = None ):
588
586
"""Sends a POST request to a given API endpoint.
589
587
590
588
This is a low-level function that returns a raw HTTP response, no error
@@ -595,18 +593,21 @@ def post(self, path, *path_args, data=None):
595
593
:param path_args: A variable number of arguments that are put into any
596
594
placeholders used in path.
597
595
:param data: Data sent in the request body.
596
+ :param json_data: dict containing data to send in the request body as JSON.
598
597
:type path: str
599
598
:type data: A string or bytes
599
+ :type json_data: dict
600
600
:returns: An instance of :class:`ClientResponse`.
601
601
"""
602
- return make_sync (self .post_async (path , * path_args , data = data ))
602
+ return make_sync (
603
+ self .post_async (path , * path_args , data = data , json_data = json_data ))
603
604
604
- async def post_async (self , path , * path_args , data = None ):
605
+ async def post_async (self , path , * path_args , data = None , json_data = None ):
605
606
"""Like :func:`post` but returns a coroutine."""
606
607
return ClientResponse (
607
608
await self ._get_session ().post (
608
609
self ._full_url (path , * path_args ),
609
- data = data , proxy = self ._proxy ))
610
+ data = data , json = json_data , proxy = self ._proxy ))
610
611
611
612
def post_object (self , path , * path_args , obj ):
612
613
"""Sends a POST request for creating an object.
@@ -627,13 +628,9 @@ def post_object(self, path, *path_args, obj):
627
628
628
629
async def post_object_async (self , path , * path_args , obj ):
629
630
"""Like :func:`post_object` but returns a coroutine."""
630
- data = json .dumps ({'data' : obj .to_dict ()})
631
-
632
- if self ._user_headers is None :
633
- self ._user_headers = {}
634
- self ._user_headers ['Content-Type' ] = 'application/json'
631
+ data = {'data' : obj .to_dict ()}
635
632
636
- response = await self .post_async (path , * path_args , data = data )
633
+ response = await self .post_async (path , * path_args , json_data = data )
637
634
return await self ._response_to_object (response )
638
635
639
636
def iterator (self , path , * path_args , params = None , cursor = None ,
0 commit comments