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

Added ability to pass raw data to post, get, put and delete so we can encode data as we want #315

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Added ability to manually set Content-Type header in Request calls, s…
…o we can manually encode JSON with custom flags
HugoDiag committed Dec 19, 2024
commit dacac500787ed6d443ce2f395d9fc4e55c0339b6
20 changes: 10 additions & 10 deletions src/Mailjet/Client.php
Original file line number Diff line number Diff line change
@@ -90,13 +90,13 @@ public function __construct(string $key, ?string $secret = null, bool $call = tr
* @param array $options
* @return Response
*/
public function post(array $resource, array $args = [], array $options = []): Response
public function post(array $resource, array $args = [], array $options = [], string $contentType = 'application/json'): Response
{
if (!empty($options)) {
$this->setOptions($options, $resource);
}

$result = $this->_call('POST', $resource[0], $resource[1], $args);
$result = $this->_call('POST', $resource[0], $resource[1], $args, $contentType);

if (!empty($this->changed)) {
$this->setSettings();
@@ -113,13 +113,13 @@ public function post(array $resource, array $args = [], array $options = []): Re
* @param array $options
* @return Response
*/
public function get(array $resource, array $args = [], array $options = []): Response
public function get(array $resource, array $args = [], array $options = [], string $contentType = 'application/json'): Response
{
if (!empty($options)) {
$this->setOptions($options, $resource);
}

$result = $this->_call('GET', $resource[0], $resource[1], $args);
$result = $this->_call('GET', $resource[0], $resource[1], $args, $contentType);

if (isset($resource['normalizer']) && class_exists($resource['normalizer'])) {
/**
@@ -146,13 +146,13 @@ public function get(array $resource, array $args = [], array $options = []): Res
* @param array $options
* @return Response
*/
public function put(array $resource, array $args = [], array $options = []): Response
public function put(array $resource, array $args = [], array $options = [], string $contentType = 'application/json'): Response
{
if (!empty($options)) {
$this->setOptions($options, $resource);
}

$result = $this->_call('PUT', $resource[0], $resource[1], $args);
$result = $this->_call('PUT', $resource[0], $resource[1], $args, $contentType);

if (!empty($this->changed)) {
$this->setSettings();
@@ -169,13 +169,13 @@ public function put(array $resource, array $args = [], array $options = []): Res
* @param array $options
* @return Response
*/
public function delete(array $resource, array $args = [], array $options = []): Response
public function delete(array $resource, array $args = [], array $options = [], string $contentType = 'application/json'): Response
{
if (!empty($options)) {
$this->setOptions($options, $resource);
}

$result = $this->_call('DELETE', $resource[0], $resource[1], $args);
$result = $this->_call('DELETE', $resource[0], $resource[1], $args, $contentType);

if (!empty($this->changed)) {
$this->setSettings();
@@ -306,9 +306,10 @@ public function setAuthentication(string $key, ?string $secret, bool $call, arra
* @param string $resource mailjet resource
* @param string $action mailjet resource action
* @param array $args Request arguments
* @param string $contentType Request Content-type
* @return Response server response
*/
private function _call(string $method, string $resource, string $action, array $args): Response
private function _call(string $method, string $resource, string $action, array $args, string $contentType = 'application/json'): Response
{
$args = array_merge([
'id' => '',
@@ -319,7 +320,6 @@ private function _call(string $method, string $resource, string $action, array $

$url = $this->buildURL($resource, $action, (string)$args['id'], $args['actionid']);

$contentType = 'application/json';
if ('csvdata/text:plain' === $action) {
$contentType = 'text/plain';
} elseif ('csverror/text:csv' === $action) {