Skip to content

Commit 20efddf

Browse files
authored
Merge pull request #1195 from abraham/json
Default v2 to JSON payload
2 parents 0e7c0b1 + 0c6e4f5 commit 20efddf

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/TwitterOAuth.php

+25-4
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,19 @@ public function get(string $path, array $parameters = [])
242242
*
243243
* @param string $path
244244
* @param array $parameters
245-
* @param bool $json
245+
* @param ?bool $json
246246
*
247247
* @return array|object
248248
*/
249249
public function post(
250250
string $path,
251251
array $parameters = [],
252-
bool $json = false,
252+
?bool $json = null,
253253
) {
254+
if (is_null($json)) {
255+
$json = $this->useJsonBody();
256+
}
257+
254258
return $this->http('POST', self::API_HOST, $path, $parameters, $json);
255259
}
256260

@@ -272,15 +276,19 @@ public function delete(string $path, array $parameters = [])
272276
*
273277
* @param string $path
274278
* @param array $parameters
275-
* @param bool $json
279+
* @param ?bool $json
276280
*
277281
* @return array|object
278282
*/
279283
public function put(
280284
string $path,
281285
array $parameters = [],
282-
bool $json = false,
286+
?bool $json = null,
283287
) {
288+
if (is_null($json)) {
289+
$json = $this->useJsonBody();
290+
}
291+
284292
return $this->http('PUT', self::API_HOST, $path, $parameters, $json);
285293
}
286294

@@ -467,6 +475,19 @@ private function extension()
467475
][$this->apiVersion];
468476
}
469477

478+
/**
479+
* Default content type for sending data.
480+
*
481+
* @return bool
482+
*/
483+
private function useJsonBody()
484+
{
485+
return [
486+
'1.1' => false,
487+
'2' => true,
488+
][$this->apiVersion];
489+
}
490+
470491
/**
471492
* @param string $method
472493
* @param string $host

0 commit comments

Comments
 (0)