Skip to content

Commit

Permalink
Add thirdparties method and fix request query data
Browse files Browse the repository at this point in the history
  • Loading branch information
dantepiazza committed Apr 1, 2024
1 parent ace7c25 commit 5e4fc75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Dolibarr.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ public function __get($property){

public function exec(string $method, string $path, array $query = []){
$headers = ['DOLAPIKEY: '.$this -> token];
$method = strtoupper($method);
$query = count($query) > 0 ? sprintf("%s?%s", $url, http_build_query($query)) : '';
$method = strtoupper($method);
$query = count($query) > 0 ? sprintf("?%s", http_build_query($query)) : '';
$url = $this -> url.$path.$query;

$curl = curl_init();

Expand All @@ -91,15 +92,15 @@ public function exec(string $method, string $path, array $query = []){
// curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// curl_setopt($curl, CURLOPT_USERPWD, "username:password");

curl_setopt($curl, CURLOPT_URL, $this -> url.$path);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$response = json_decode(curl_exec($curl), true);

$this -> response = new Response();
$this -> response -> status = isset($response['error']) ? false : true;
$this -> response -> data = isset($response['error']) ? array_merge($response['error'], ['path' => $path, 'payload' => $this -> payload]) : $response;
$this -> response -> data = isset($response['error']) ? array_merge($response['error'], ['url' => $url, 'payload' => $this -> payload]) : $response;
$this -> response -> code = curl_getinfo($curl, CURLINFO_HTTP_CODE);

curl_close($curl);
Expand Down
13 changes: 13 additions & 0 deletions src/Endpoints/Thirdparties.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,18 @@ public function Create(array $options) {

return $this -> adapter -> exec('post', 'thirdparties') -> response;
}

/**
* List thirdparties
*
* @since 1.0
*
* @param array $options
*
* @return Dolibarr\Adapter\Response
**/
public function All(array $options = []) {
return $this -> adapter -> exec('get', 'thirdparties', $options) -> response;
}
}

0 comments on commit 5e4fc75

Please sign in to comment.