1 | <?php |
||
2 | |||
3 | require '../vendor/autoload.php'; |
||
4 | require 'ClientAbstract.php'; |
||
5 | require 'RequestAbstract.php'; |
||
6 | require 'ResponseAbstract.php'; |
||
7 | require 'ConfigAbstract.php'; |
||
8 | require 'func.php'; |
||
9 | |||
10 | use carono\turbotext\codegen\ClientAbstract; |
||
11 | use GuzzleHttp\Client; |
||
12 | |||
13 | clearFolder('config'); |
||
14 | clearFolder('request'); |
||
15 | clearFolder('response'); |
||
16 | |||
17 | $sections = [ |
||
18 | 'api1' => 'order', |
||
19 | 'api2' => 'user', |
||
20 | 'api3' => 'microTask', |
||
21 | 'api4' => 'message', |
||
22 | ]; |
||
23 | $apidoc = 'apidoc.html'; |
||
24 | if (file_exists($apidoc)) { |
||
25 | $content = file_get_contents($apidoc); |
||
26 | } else { |
||
27 | $content = (new Client())->get('https://www.turbotext.ru/api-info/')->getBody()->getContents(); |
||
28 | file_put_contents($apidoc, $content); |
||
29 | } |
||
30 | $query = \phpQuery::newDocumentHTML($content); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
31 | $data = []; |
||
32 | $i = 1; |
||
33 | foreach ($desc = $query->find('.api_descr') as $desc) { |
||
34 | $h3 = pq($desc)->prev('h3')->text(); |
||
35 | $item = [ |
||
36 | 'name' => $sections['api' . $i++], |
||
37 | 'description' => $h3, |
||
38 | 'methods' => [] |
||
39 | ]; |
||
40 | foreach (pq($desc)->find('table tr') as $tr) { |
||
41 | $tr = pq($tr); |
||
42 | if (!$name = trim($tr->find('td')->eq(0)->text())) { |
||
43 | continue; |
||
44 | } |
||
45 | $params = parseParamsFromQuery($tr->find('td')->eq(2)->find('li')); |
||
46 | |||
47 | $returns = parseReturns($uls = $tr->find('td')->eq(3)->htmlOuter()); |
||
48 | $method = [ |
||
49 | 'name' => $name, |
||
50 | 'description' => $tr->find('td')->eq(1)->text(), |
||
51 | 'params' => $params, |
||
52 | 'returns' => $returns |
||
53 | ]; |
||
54 | $item['methods'][] = $method; |
||
55 | } |
||
56 | $data[] = $item; |
||
57 | } |
||
58 | file_put_contents('data.json', json_encode($data)); |
||
59 | $abstractClient = new ClientAbstract(); |
||
60 | $abstractClient->renderToFile($data); |