Skip to content

Commit

Permalink
Tasks: Support JSON via PushTask
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacarpet committed Sep 13, 2024
1 parent a388bf3 commit 6a7e956
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,21 @@ public function __construct($url_path, $query_data = [], $options = [])
}
}

$this->pushTask->setBody(http_build_query($query_data));
$this->pushTask->setHeaders([
'Content-Type' => 'application/x-www-form-urlencoded',
]);
if ($options['json'] ?? false) {
$this->pushTask->setBody(
json_encode($query_data, JSON_PRETTY_PRINT),
);
$this->pushTask->setHeaders([
'Content-Type' => 'application/json',
]);
} else {
$this->pushTask->setBody(
http_build_query($query_data),
);
$this->pushTask->setHeaders([
'Content-Type' => 'application/x-www-form-urlencoded',
]);
}

if (!empty($options['method'])) {
$this->pushTask->setHttpMethod(
Expand Down

0 comments on commit 6a7e956

Please sign in to comment.