1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ViniciusRBezerra\Autentique; |
4
|
|
|
|
5
|
|
|
use stdClass; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Source |
9
|
|
|
*/ |
10
|
|
|
abstract class Autentique |
11
|
|
|
{ |
12
|
|
|
/** @var string */ |
13
|
|
|
private string $url = "https://api.autentique.com.br/v2/graphql"; |
14
|
|
|
|
15
|
|
|
/** @var string */ |
16
|
|
|
private string $token; |
17
|
|
|
|
18
|
|
|
/** @var bool */ |
19
|
|
|
protected bool $devMode; |
20
|
|
|
|
21
|
|
|
/** @var object */ |
22
|
|
|
private object $callback; |
23
|
|
|
|
24
|
|
|
/** @var object */ |
25
|
|
|
protected object $data; |
26
|
|
|
|
27
|
|
|
/** @var array */ |
28
|
|
|
protected array $header = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Source constructor. |
32
|
|
|
*/ |
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
$dotenv = \Dotenv\Dotenv::createImmutable(dirname(__DIR__)); |
36
|
|
|
$dotenv->load(); |
37
|
|
|
|
38
|
|
|
$this->token = $_ENV['AUTENTIQUE_TOKEN']; |
39
|
|
|
$this->devMode = $_ENV['AUTENTIQUE_DEV_MODE']; |
40
|
|
|
|
41
|
|
|
$this->data = new stdClass(); |
42
|
|
|
$this->header[] = "Authorization: Bearer {$this->token}"; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $documentId |
47
|
|
|
* @param string $folderId |
48
|
|
|
* @return $this |
49
|
|
|
*/ |
50
|
|
|
public function moveDocumentToFolder(string $documentId, string $folderId): Autentique |
51
|
|
|
{ |
52
|
|
|
$this->data->query = "mutation { moveDocumentToFolder(document_id: \"{$documentId}\", folder_id: \"{$folderId}\") }"; |
53
|
|
|
$this->execute(); |
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** @return object */ |
58
|
|
|
public function callback(): object |
59
|
|
|
{ |
60
|
|
|
return isset($this->callback->data) ? $this->callback->data : $this->callback; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param bool|null $json |
65
|
|
|
*/ |
66
|
|
|
protected function execute(?bool $json = true) |
67
|
|
|
{ |
68
|
|
|
$this->header[] = $json ? "Content-Type: application/json" : "Content-Type: multipart/form-data"; |
69
|
|
|
|
70
|
|
|
$curl = curl_init($this->url); |
71
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
72
|
|
|
curl_setopt($curl, CURLOPT_ENCODING, ''); |
73
|
|
|
curl_setopt($curl, CURLOPT_MAXREDIRS, 10); |
74
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, 0); |
75
|
|
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); |
76
|
|
|
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
77
|
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); |
78
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, ($json ? json_encode((array)$this->data) : (array) $this->data)); |
79
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->header); |
80
|
|
|
$this->callback = json_decode(curl_exec($curl)); |
|
|
|
|
81
|
|
|
curl_close($curl); |
82
|
|
|
} |
83
|
|
|
} |