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

Ability to send payload #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions tmhOAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ private function prepare_params() {
$this->request_settings['basestring_params'] = implode('&', $prepared_pairs_with_oauth);
}

$has_payload = isset($this->request_settings['payload']) && $this->request_settings['payload'] !== null;

if ($has_payload) {
$this->request_settings['postfields'] = $this->request_settings['payload'];
}

// setup params for GET/POST/PUT method handling
if (!empty($prepared)) {
$content = implode('&', $prepared_pairs);
Expand All @@ -399,6 +405,9 @@ private function prepare_params() {
case 'PUT':
// fall through to POST as PUT should be treated the same
case 'POST':
if ($has_payload) {
throw new RuntimeException("You can't use 'payload' settings together with request parameters for POST or PUT");
}
$this->request_settings['postfields'] = $this->request_settings['multipart'] ? $prepared : $content;
break;
default:
Expand Down Expand Up @@ -509,16 +518,18 @@ public function bearer_token_credentials() {
* @param string $useauth whether to use authentication when making the request. Default true
* @param string $multipart whether this request contains multipart data. Default false
* @param array $headers any custom headers to send with the request. Default empty array
* @param string|null $payload payload to send in request
* @return int the http response code for the request. 0 is returned if a connection could not be made
*/
public function request($method, $url, $params=array(), $useauth=true, $multipart=false, $headers=array()) {
public function request($method, $url, $params=array(), $useauth=true, $multipart=false, $headers=array(), $payload=null) {
$options = array(
'method' => $method,
'url' => $url,
'params' => $params,
'with_user' => true,
'multipart' => $multipart,
'headers' => $headers
'headers' => $headers,
'payload' => $payload
);
$options = array_merge($this->default_options(), $options);

Expand Down