Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles json post data #3

Merged
merged 2 commits into from
Jun 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions tmhOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private function prepare_params() {
if (isset($this->request_settings['oauth1_params'])) {
$oauth1 = &$this->request_settings['oauth1_params'];
$doing_oauth1 = true;
$params = array_merge($oauth1, $this->request_settings['params']);
$params = array_merge($oauth1, (is_array($this->request_settings['params']) ? $this->request_settings['params'] : []));

// Remove oauth_signature if present
// Ref: Spec: 9.1.1 ("The oauth_signature parameter MUST be excluded.")
Expand Down Expand Up @@ -646,6 +646,23 @@ private function update_metrics() {
return $this->metrics;
}

/**
* Determines if the $string is json or not
*
* @param mixed $string
*
* @return bool
*/
private function isJson($string) {
if (!is_string($string)) {
return false;
}

json_decode($string);

return (json_last_error() == JSON_ERROR_NONE);
}

/**
* Utility function to create the request URL in the requested format.
* If a fully-qualified URI is provided, it will be returned.
Expand Down Expand Up @@ -781,7 +798,11 @@ private function curlit() {
$this->request_settings['url'] = $this->request_settings['url'] . '?' . $this->request_settings['querystring'];
} elseif ($this->request_settings['method'] == 'POST' || $this->request_settings['method'] == 'PUT') {
$postfields = array();
if (isset($this->request_settings['postfields']))

if ($this->isJson($this->request_settings['params'])) {
$postfields = $this->request_settings['params'];
$this->request_settings['headers']['Content-Type'] = 'application/json';
} elseif (isset($this->request_settings['postfields']))
$postfields = $this->request_settings['postfields'];

curl_setopt($c, CURLOPT_POSTFIELDS, $postfields);
Expand Down