|
6 | 6 | use stdClass; |
7 | 7 |
|
8 | 8 | class Account { |
9 | | - private $greenApi; |
10 | | - |
11 | | - /** |
12 | | - * @param GreenApiClient $greenApi |
13 | | - */ |
14 | | - public function __construct( GreenApiClient $greenApi ) { |
15 | | - $this->greenApi = $greenApi; |
16 | | - } |
17 | | - |
18 | | - /** |
19 | | - * The method is aimed for getting the current account settings. |
20 | | - * |
21 | | - * @return stdClass |
22 | | - * @link https://green-api.com/en/docs/api/account/GetSettings/ |
23 | | - */ |
24 | | - public function getSettings(): stdClass { |
25 | | - |
26 | | - return $this->greenApi->request( 'GET', |
27 | | - '{{host}}/waInstance{{idInstance}}/GetSettings/{{apiTokenInstance}}' ); |
28 | | - } |
29 | | - |
30 | | - /** |
31 | | - * The method is aimed for getting the current account settings. |
32 | | - * |
33 | | - * @return stdClass |
34 | | - * @link https://green-api.com/en/docs/api/account/GetWaSettings/ |
35 | | - */ |
36 | | - |
37 | | - public function getWaSettings(): stdClass { |
38 | | - |
39 | | - return $this->greenApi->request( 'GET', |
40 | | - '{{host}}/waInstance{{idInstance}}/getWaSettings/{{apiTokenInstance}}' ); |
41 | | - } |
42 | | - |
43 | | - /** |
44 | | - * The method is aimed for getting the account state. |
45 | | - * |
46 | | - * @return stdClass |
47 | | - * @link https://green-api.com/en/docs/api/account/GetStateInstance/ |
48 | | - */ |
49 | | - public function getStateInstance(): stdClass { |
50 | | - |
51 | | - return $this->greenApi->request( 'GET', |
52 | | - '{{host}}/waInstance{{idInstance}}/GetStateInstance/{{apiTokenInstance}}' ); |
53 | | - } |
54 | | - |
55 | | - /** |
56 | | - * The method is aimed for getting the status of the account instance socket connection with WhatsApp. |
57 | | - * |
58 | | - * @return stdClass |
59 | | - * @link https://green-api.com/en/docs/api/account/GetStatusInstance/ |
60 | | - */ |
61 | | - public function getStatusInstance(): stdClass { |
62 | | - |
63 | | - return $this->greenApi->request( 'GET', |
64 | | - '{{host}}/waInstance{{idInstance}}/GetStatusInstance/{{apiTokenInstance}}' ); |
65 | | - } |
66 | | - |
67 | | - /** |
68 | | - * The method is aimed for logging out an account. |
69 | | - * |
70 | | - * @return stdClass |
71 | | - * @link https://green-api.com/en/docs/api/account/Logout/ |
72 | | - */ |
73 | | - public function logout(): stdClass { |
74 | | - |
75 | | - return $this->greenApi->request( 'GET', |
76 | | - '{{host}}/waInstance{{idInstance}}/Logout/{{apiTokenInstance}}' ); |
77 | | - } |
78 | | - |
79 | | - /** |
80 | | - * The method is aimed for getting QR code. To authorize your account, you have to scan a QR code from |
81 | | - * application WhatsApp Business on your phone. You can also get a QR code and authorize your account in your profile. |
82 | | - * |
83 | | - * @return stdClass |
84 | | - * @link https://green-api.com/en/docs/api/account/QR/ |
85 | | - */ |
86 | | - public function qr(): stdClass { |
87 | | - |
88 | | - return $this->greenApi->request( 'GET', |
89 | | - '{{host}}/waInstance{{idInstance}}/QR/{{apiTokenInstance}}' ); |
90 | | - } |
91 | | - |
92 | | - /** |
93 | | - * The method is aimed for rebooting an account. |
94 | | - * |
95 | | - * @return stdClass |
96 | | - * @link https://green-api.com/en/docs/api/account/Reboot/ |
97 | | - */ |
98 | | - public function reboot(): stdClass { |
99 | | - |
100 | | - return $this->greenApi->request( 'GET', |
101 | | - '{{host}}/waInstance{{idInstance}}/Reboot/{{apiTokenInstance}}' ); |
102 | | - } |
103 | | - |
104 | | - |
105 | | - /** |
106 | | - * The method is aimed for setting an account picture. |
107 | | - * |
108 | | - * @param string $path |
109 | | - * |
110 | | - * @return stdClass |
111 | | - * @link https://green-api.com/en/docs/api/account/SetProfilePicture/ |
112 | | - */ |
113 | | - public function setProfilePicture( string $path ): stdClass { |
114 | | - |
115 | | - $requestBody = [ |
116 | | - 'file' => curl_file_create( $path ), |
117 | | - ]; |
118 | | - $requestBody['file']->mime = 'image/jpeg'; |
119 | | - |
120 | | - return $this->greenApi->request( 'POST', |
121 | | - '{{host}}/waInstance{{idInstance}}/SetProfilePicture/{{apiTokenInstance}}', $requestBody, true ); |
122 | | - } |
123 | | - |
124 | | - /** |
125 | | - * The method is aimed for setting account settings. When this method is requested, the account is rebooted. |
126 | | - * |
127 | | - * @param array $requestBody |
128 | | - * |
129 | | - * @return stdClass |
130 | | - * @link https://green-api.com/en/docs/api/account/SetSettings/ |
131 | | - */ |
132 | | - public function setSettings( array $requestBody ): stdClass { |
133 | | - |
134 | | - return $this->greenApi->request( 'POST', |
135 | | - '{{host}}/waInstance{{idInstance}}/SetSettings/{{apiTokenInstance}}', $requestBody ); |
136 | | - } |
| 9 | + private $greenApi; |
| 10 | + |
| 11 | + /** |
| 12 | + * @param GreenApiClient $greenApi |
| 13 | + */ |
| 14 | + public function __construct(GreenApiClient $greenApi) { |
| 15 | + $this->greenApi = $greenApi; |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * The method is aimed for getting the current account settings. |
| 20 | + * |
| 21 | + * @return stdClass |
| 22 | + * @link https://green-api.com/en/docs/api/account/GetSettings/ |
| 23 | + */ |
| 24 | + public function getSettings(): stdClass { |
| 25 | + return $this->greenApi->request('GET', |
| 26 | + '{{host}}/waInstance{{idInstance}}/GetSettings/{{apiTokenInstance}}'); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * The method is aimed for getting the current WhatsApp account settings. |
| 31 | + * |
| 32 | + * @return stdClass |
| 33 | + * @link https://green-api.com/en/docs/api/account/GetWaSettings/ |
| 34 | + */ |
| 35 | + public function getWaSettings(): stdClass { |
| 36 | + return $this->greenApi->request('GET', |
| 37 | + '{{host}}/waInstance{{idInstance}}/getWaSettings/{{apiTokenInstance}}'); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * The method is aimed for getting the account state. |
| 42 | + * |
| 43 | + * @return stdClass |
| 44 | + * @link https://green-api.com/en/docs/api/account/GetStateInstance/ |
| 45 | + */ |
| 46 | + public function getStateInstance(): stdClass { |
| 47 | + return $this->greenApi->request('GET', |
| 48 | + '{{host}}/waInstance{{idInstance}}/GetStateInstance/{{apiTokenInstance}}'); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * The method is aimed for getting the status of the account instance socket connection with WhatsApp. |
| 53 | + * |
| 54 | + * @return stdClass |
| 55 | + * @link https://green-api.com/en/docs/api/account/GetStatusInstance/ |
| 56 | + */ |
| 57 | + public function getStatusInstance(): stdClass { |
| 58 | + return $this->greenApi->request('GET', |
| 59 | + '{{host}}/waInstance{{idInstance}}/GetStatusInstance/{{apiTokenInstance}}'); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * The method is aimed for logging out an account. |
| 64 | + * |
| 65 | + * @return stdClass |
| 66 | + * @link https://green-api.com/en/docs/api/account/Logout/ |
| 67 | + */ |
| 68 | + public function logout(): stdClass { |
| 69 | + return $this->greenApi->request('GET', |
| 70 | + '{{host}}/waInstance{{idInstance}}/Logout/{{apiTokenInstance}}'); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * The method is aimed for getting QR code. |
| 75 | + * |
| 76 | + * @return stdClass |
| 77 | + * @link https://green-api.com/en/docs/api/account/QR/ |
| 78 | + */ |
| 79 | + public function qr(): stdClass { |
| 80 | + return $this->greenApi->request('GET', |
| 81 | + '{{host}}/waInstance{{idInstance}}/QR/{{apiTokenInstance}}'); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * The method is aimed for rebooting an account. |
| 86 | + * |
| 87 | + * @return stdClass |
| 88 | + * @link https://green-api.com/en/docs/api/account/Reboot/ |
| 89 | + */ |
| 90 | + public function reboot(): stdClass { |
| 91 | + return $this->greenApi->request('GET', |
| 92 | + '{{host}}/waInstance{{idInstance}}/Reboot/{{apiTokenInstance}}'); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * The method is aimed for setting an account picture. |
| 97 | + * |
| 98 | + * @param string $path |
| 99 | + * |
| 100 | + * @return stdClass |
| 101 | + * @link https://green-api.com/en/docs/api/account/SetProfilePicture/ |
| 102 | + */ |
| 103 | + public function setProfilePicture(string $path): stdClass { |
| 104 | + $requestBody = [ |
| 105 | + 'file' => curl_file_create($path), |
| 106 | + ]; |
| 107 | + $requestBody['file']->mime = 'image/jpeg'; |
| 108 | + |
| 109 | + return $this->greenApi->request('POST', |
| 110 | + '{{host}}/waInstance{{idInstance}}/SetProfilePicture/{{apiTokenInstance}}', $requestBody, true); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * The method is aimed for setting account settings. |
| 115 | + * |
| 116 | + * @param array $requestBody |
| 117 | + * |
| 118 | + * @return stdClass |
| 119 | + * @link https://green-api.com/en/docs/api/account/SetSettings/ |
| 120 | + */ |
| 121 | + public function setSettings(array $requestBody): stdClass { |
| 122 | + return $this->greenApi->request('POST', |
| 123 | + '{{host}}/waInstance{{idInstance}}/SetSettings/{{apiTokenInstance}}', $requestBody); |
| 124 | + } |
| 125 | +} |
0 commit comments