| @@ 149-168 (lines=20) @@ | ||
| 146 | * @param string $contentType |
|
| 147 | * @return array |
|
| 148 | */ |
|
| 149 | public function post($ressourceName, $ressourcePath =null, $ressourceId = null, |
|
| 150 | $bodyData = array(), $query = array(), $assoc = false, |
|
| 151 | $contentType = 'json') |
|
| 152 | { |
|
| 153 | if ($contentType !== 'json') { |
|
| 154 | throw new \Exception('Use only json to update or create'); |
|
| 155 | } |
|
| 156 | try { |
|
| 157 | $urlRessource = $this->builPathToCall($ressourceName, $ressourcePath, $ressourceId); |
|
| 158 | $response = $this->getClient()->post($urlRessource, |
|
| 159 | array( |
|
| 160 | 'headers' => ['Accept' => "application/$contentType"], |
|
| 161 | 'json' => $bodyData, |
|
| 162 | 'query' => $query |
|
| 163 | )); |
|
| 164 | } catch (ClientException $ex) { |
|
| 165 | $response = $ex->getResponse(); |
|
| 166 | } |
|
| 167 | return $this->makeCertainApiResponse($response, $contentType, $assoc); |
|
| 168 | } |
|
| 169 | ||
| 170 | /** |
|
| 171 | * Make "PUT" request with the client. |
|
| @@ 181-200 (lines=20) @@ | ||
| 178 | * @param string $contentType |
|
| 179 | * @return array |
|
| 180 | */ |
|
| 181 | public function put($ressourceName, $ressourcePath =null, $ressourceId = null, |
|
| 182 | $bodyData = array(), $query = array(), $assoc = false, |
|
| 183 | $contentType = 'json') |
|
| 184 | { |
|
| 185 | if ($contentType !== 'json') { |
|
| 186 | throw new \Exception('Use only json to update or create'); |
|
| 187 | } |
|
| 188 | try { |
|
| 189 | $urlRessource = $this->builPathToCall($ressourceName, $ressourcePath, $ressourceId); |
|
| 190 | $response = $this->getClient()->put($urlRessource, |
|
| 191 | array( |
|
| 192 | 'headers' => ['Accept' => "application/$contentType"], |
|
| 193 | 'json' => $bodyData, |
|
| 194 | 'query' => $query |
|
| 195 | )); |
|
| 196 | } catch (ClientException $ex) { |
|
| 197 | $response = $ex->getResponse(); |
|
| 198 | } |
|
| 199 | return $this->makeCertainApiResponse($response, $contentType, $assoc); |
|
| 200 | } |
|
| 201 | ||
| 202 | /** |
|
| 203 | * Make "DELETE" request with the client. |
|