Skip to content

Commit

Permalink
Default v2 to JSON payload
Browse files Browse the repository at this point in the history
  • Loading branch information
abraham committed Aug 8, 2023
1 parent 0e7c0b1 commit 311d701
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/TwitterOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,21 @@ public function get(string $path, array $parameters = [])
/**
* Make POST requests to the API.
*
* @param string $path
* @param array $parameters
* @param bool $json
* @param string $path
* @param array $parameters
* @param bool|null $json
*
* @return array|object
*/
public function post(
string $path,
array $parameters = [],
bool $json = false,
array $parameters = [],x
bool $json = null,
) {
if (is_null($json)) {
$json = $this->useJsonBody();
}

return $this->http('POST', self::API_HOST, $path, $parameters, $json);
}

Expand All @@ -270,17 +274,21 @@ public function delete(string $path, array $parameters = [])
/**
* Make PUT requests to the API.
*
* @param string $path
* @param array $parameters
* @param bool $json
* @param string $path
* @param array $parameters
* @param bool|null $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 311d701

Please sign in to comment.