Skip to content

Commit

Permalink
release: 1.1.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyber-Root0 committed Feb 9, 2024
1 parent d5f8454 commit 221e138
Show file tree
Hide file tree
Showing 7 changed files with 886 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore

# Node artifact files
node_modules/
dist/
vendor/

# Compiled Java class files
*.class

# Compiled Python bytecode
*.py[cod]

# Log files
*.log

# Package files
*.jar

# Maven
target/
dist/

# JetBrains IDE
.idea/

# Unit test reports
TEST*.xml

# Generated by MacOS
.DS_Store

# Generated by Windows
Thumbs.db

# Applications
*.app
*.exe
*.war

# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv

136 changes: 136 additions & 0 deletions SDK/SDK.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php
namespace EvolutionSDK;

use EvolutionSDK\util\Config;
use EvolutionSDK\util\EndPoints;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
class SDK
{
protected Client $httpclient;
protected Config $config;
/**
* receive Config instance
*
* @param Config $config
* @return void
*/
public function __construct(Config $config)
{
$this->config = $config;
$this->httpclient = new Client(
[
'base_uri' => $config->getUrl(),
'timeout' => 10
]
);
}
/**
* create instance
*
* @param string $instance
* @param bool $qrcode
* @return \StdClass
*/
public function create(string $instance, $qrcode = false)
{
try {

$output = $this->httpclient->request(
'POST',
EndPoints::CREATE,
[
'headers' => $this->setConfigHeader(),
'json' => [
'instanceName' => $instance,
'qrcode' => $qrcode
]
]
);
return json_decode($output->getBody()->getContents());
} catch (ClientException $e) {
var_dump($e->getMessage());
}

}
/**
* sendMessage
*
* @param string $instance
* @param string $number
* @param string $message
* @param array $options
* @return \stdClass
*/
public function sendMessage(string $instance, string $number, string $message, array $options = [])
{
$number = $number . '@s.whatsapp.net';
try {
$output = $this->httpclient->request(
'POST',
EndPoints::SEND . $instance,
[
'headers' => $this->setConfigHeader(),
'json' => [
'number' => $number,
'textMessage' => [
'text' => $message
],
'options' => $options
]
]
);
return json_decode($output->getBody()->getContents());
} catch (ClientException $e) {
var_dump($e->getMessage());
}
}
/**
* connect qrcode from specif instance
*
* @param string $instance
* @return void
*/
public function connect(string $instance)
{
try {
$output = $this->httpclient->request(
'GET',
EndPoints::CONNECT . $instance,
[
'headers' => $this->setConfigHeader()
]
);
return json_decode($output->getBody()->getContents());
} catch (ClientException $e) {
var_dump($e->getMessage());
}
}
public function instanceStatus(string $instance)
{
try {
$output = $this->httpclient->request(
'GET',
EndPoints::STATUS . $instance,
[
'headers' => $this->setConfigHeader()
]
);
return json_decode($output->getBody()->getContents());
} catch (ClientException $e) {
var_dump($e->getMessage());
}
}
/* private methods */
/**
* get header with apikey
*
* @return array
*/
private function setConfigHeader(): array
{
return [
'apiKey' => $this->config->getApikey()
];
}
}
42 changes: 42 additions & 0 deletions SDK/util/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace EvolutionSDK\util;
class Config{

private string $url = '';
private string $apikey = '';
/**
* get url param
*
* @return string
*/
public function getUrl(){
return $this->url;
}
/**
* get apikey param
*
* @return string
*/
public function getApikey(){
return $this->apikey;
}
/**
* setUrl
*
* @param string $url
* @return void
*/
public function setUrl(string $url){
$this->url = $url;
}
/**
* set apikey param
*
* @param string $apikey
* @return void
*/
public function setApikey(string $apikey){
$this->apikey = $apikey;
}

}
8 changes: 8 additions & 0 deletions SDK/util/EndPoints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace EvolutionSDK\util;
class EndPoints{
public const CREATE = '/instance/create/';
public const CONNECT = '/instance/connect/';
public const SEND = '/message/sendText/';
public const STATUS = '/instance/connectionState/';
}
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "cyber-root0/evolution-sdk",
"type": "library",
"authors": [
{
"email": "[email protected]",
"name": "Bruno Alves",
"role": "Web Developer"
}
],
"version": "1.1.0",
"description": "SDK Para consumir API evolution do WhatsApp",
"autoload": {
"psr-4": {
"EvolutionSDK\\": "SDK/"
}
},
"require": {
"guzzlehttp/guzzle": "*"
}
}
Loading

0 comments on commit 221e138

Please sign in to comment.