Skip to content

Commit

Permalink
update Evolution method delete
Browse files Browse the repository at this point in the history
  • Loading branch information
luannsr12 committed Oct 16, 2024
1 parent b5c10fb commit 09ca252
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## SDK PHP Evolution 2
## SDK PHP Evolution Api Whatsapp

Api Evolution: [Evolution-api](https://doc.evolution-api.com/v2/)

<hr>

SDK version: 2.0.2 <br />
SDK version: 2.0.3 <br />
PHP Version: >= 8.2

## Funções disponíveis
Expand Down
68 changes: 68 additions & 0 deletions src/Api/Evolution/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,74 @@ public static function logout()
}
}

public static function delete()
{

try {

if (ExceptionError::$error) {
return NULL;
}


$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => rtrim(self::$endpoint, '/') . '/instance/delete/' . trim(self::$name_instance),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => array(
'apikey: ' . trim(self::$instance)
),
)
);

$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

try {

if ($httpCode != 200) {
ExceptionError::setError($httpCode, json_encode(['type' => 'Api response', 'class' => 'Api\Evolution\Device', 'method' => 'delete', 'message' => $response]));
return NULL;
}

if (!json_decode($response)) {
ExceptionError::setError(500, json_encode(['type' => 'Api response', 'class' => 'Api\Evolution\Device', 'method' => 'delete', 'message' => $response]));
return NULL;
}

$json = json_decode($response);

if (isset($json->status)) {
if ($json->status == 'SUCCESS') {
return true;
} else {
ExceptionError::setError($json->code, json_encode(['type' => 'Api response', 'class' => 'Api\Evolution\Device', 'method' => 'delete', 'message' => $json->error]));
return false;
}
} else {
ExceptionError::setError(500, json_encode(['type' => 'Api response', 'class' => 'Api\Evolution\Device', 'method' => 'delete', 'message' => $response]));
}

} catch (\Exception $e) {
ExceptionError::setError(500, json_encode(['type' => 'Exception', 'class' => 'Api\Evolution\Device', 'method' => 'delete', 'message' => $e->getMessage()]));
return false;
}

} catch (\Exception $e) {
ExceptionError::setError(500, json_encode(['type' => 'Exception', 'class' => 'Api\Evolution\Device', 'method' => 'delete', 'message' => $e->getMessage()]));
return false;
}
}


public static function list()
{
try {
Expand Down

0 comments on commit 09ca252

Please sign in to comment.