From 0c6e4f5f89174f8f9c31b691eb16a6ead43949f7 Mon Sep 17 00:00:00 2001 From: Abraham Williams <4braham@gmail.com> Date: Mon, 7 Aug 2023 22:14:05 -0500 Subject: [PATCH] Default v2 to JSON payload --- src/TwitterOAuth.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/TwitterOAuth.php b/src/TwitterOAuth.php index 5a7d7979..6e3748f0 100644 --- a/src/TwitterOAuth.php +++ b/src/TwitterOAuth.php @@ -242,15 +242,19 @@ public function get(string $path, array $parameters = []) * * @param string $path * @param array $parameters - * @param bool $json + * @param ?bool $json * * @return array|object */ public function post( string $path, array $parameters = [], - bool $json = false, + ?bool $json = null, ) { + if (is_null($json)) { + $json = $this->useJsonBody(); + } + return $this->http('POST', self::API_HOST, $path, $parameters, $json); } @@ -272,15 +276,19 @@ public function delete(string $path, array $parameters = []) * * @param string $path * @param array $parameters - * @param bool $json + * @param ?bool $json * * @return array|object */ public function put( string $path, array $parameters = [], - bool $json = false, + ?bool $json = null, ) { + if (is_null($json)) { + $json = $this->useJsonBody(); + } + return $this->http('PUT', self::API_HOST, $path, $parameters, $json); } @@ -467,6 +475,19 @@ private function extension() ][$this->apiVersion]; } + /** + * Default content type for sending data. + * + * @return bool + */ + private function useJsonBody() + { + return [ + '1.1' => false, + '2' => true, + ][$this->apiVersion]; + } + /** * @param string $method * @param string $host