Skip to content

Commit

Permalink
Merge pull request #1195 from abraham/json
Browse files Browse the repository at this point in the history
Default v2 to JSON payload
  • Loading branch information
abraham committed Aug 8, 2023
2 parents 0e7c0b1 + 0c6e4f5 commit 20efddf
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/TwitterOAuth.php
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 20efddf

Please sign in to comment.