Skip to content

Commit

Permalink
Merge pull request #44 from ops-itop/master
Browse files Browse the repository at this point in the history
add a method setPatchType in Client to support different patch type
  • Loading branch information
maclof authored Jan 10, 2019
2 parents aadb636 + 300b5fe commit 87554bf
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ class Client
*/
protected $classInstances = [];

/**
* header for patch.
*
* @var array
*/
protected $patchHeader = ['Content-Type' => 'application/strategic-merge-patch+json'];

/**
* The constructor.
*
Expand Down Expand Up @@ -235,6 +242,21 @@ public function setNamespace($namespace)
$this->namespace = $namespace;
}

/**
* Set patch header
*
* @param patch type
*/
public function setPatchType($patchType = "strategic") {
if ($patchType == "merge") {
$this->patchHeader = ['Content-Type' => 'application/merge-patch+json'];
} elseif ($patchType == "json") {
$this->patchHeader = ['Content-Type' => 'application/json-patch+json'];
} else {
$this->patchHeader = ['Content-Type' => 'application/strategic-merge-patch+json'];
}
}

/**
* Check if we're using guzzle 6.
*
Expand Down Expand Up @@ -335,7 +357,7 @@ public function sendRequest($method, $uri, $query = [], $body = [], $namespace =
}

if ($method === 'PATCH') {
$requestOptions['headers'] = ['Content-Type' => 'application/strategic-merge-patch+json'];
$requestOptions['headers'] = $this->patchHeader;
}

if (!$this->isUsingGuzzle6()) {
Expand Down

0 comments on commit 87554bf

Please sign in to comment.