@@ -76,7 +76,7 @@ |
||
76 | 76 | 'action' => 'create_order' |
77 | 77 | ]; |
78 | 78 | foreach (($config instanceof \carono\turbotext\ConfigAbstract ? $config->toArray() : $config) as $key => $value) { |
79 | - $params[$key] = $value; |
|
79 | + $params[$key] = $value; |
|
80 | 80 | } |
81 | 81 | return $this->getClient()->getContent('api', $params, 'carono\turbotext\response\OrderResponse'); |
82 | 82 | } |
@@ -63,7 +63,7 @@ |
||
63 | 63 | 'action' => 'create_microtask' |
64 | 64 | ]; |
65 | 65 | foreach (($config instanceof \carono\turbotext\ConfigAbstract ? $config->toArray() : $config) as $key => $value) { |
66 | - $params[$key] = $value; |
|
66 | + $params[$key] = $value; |
|
67 | 67 | } |
68 | 68 | return $this->getClient()->getContent('api', $params, 'carono\turbotext\response\MicrotaskResponse'); |
69 | 69 | } |
@@ -6,63 +6,63 @@ |
||
6 | 6 | |
7 | 7 | class Client extends ClientAbstract |
8 | 8 | { |
9 | - public $apiKey; |
|
10 | - public $url = 'www.turbotext.ru'; |
|
11 | - public $protocol = 'http'; |
|
12 | - public $method = 'POST'; |
|
13 | - public $type = self::TYPE_FORM; |
|
14 | - public $output_type = self::TYPE_JSON; |
|
9 | + public $apiKey; |
|
10 | + public $url = 'www.turbotext.ru'; |
|
11 | + public $protocol = 'http'; |
|
12 | + public $method = 'POST'; |
|
13 | + public $type = self::TYPE_FORM; |
|
14 | + public $output_type = self::TYPE_JSON; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @param array $data |
|
18 | - * @return array|string |
|
19 | - */ |
|
20 | - public function prepareData(array $data) |
|
21 | - { |
|
22 | - $data = parent::prepareData($data); |
|
23 | - $data['api_key'] = $this->apiKey; |
|
24 | - return $data; |
|
25 | - } |
|
16 | + /** |
|
17 | + * @param array $data |
|
18 | + * @return array|string |
|
19 | + */ |
|
20 | + public function prepareData(array $data) |
|
21 | + { |
|
22 | + $data = parent::prepareData($data); |
|
23 | + $data['api_key'] = $this->apiKey; |
|
24 | + return $data; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param $urlRequest |
|
29 | - * @param array $data |
|
30 | - * @param string $responseClass |
|
31 | - * @return mixed |
|
32 | - */ |
|
33 | - public function getContent($urlRequest, $data = [], $responseClass = '\carono\turbotext\Response') |
|
34 | - { |
|
35 | - try { |
|
36 | - $content = parent::getContent($urlRequest, $data); |
|
37 | - return self::stdClassToResponse($content, $responseClass); |
|
38 | - } catch (\Exception $e) { |
|
39 | - $response = new Response(); |
|
40 | - $response->success = false; |
|
41 | - $response->errors = $e->getMessage(); |
|
42 | - return $response; |
|
43 | - } |
|
44 | - } |
|
27 | + /** |
|
28 | + * @param $urlRequest |
|
29 | + * @param array $data |
|
30 | + * @param string $responseClass |
|
31 | + * @return mixed |
|
32 | + */ |
|
33 | + public function getContent($urlRequest, $data = [], $responseClass = '\carono\turbotext\Response') |
|
34 | + { |
|
35 | + try { |
|
36 | + $content = parent::getContent($urlRequest, $data); |
|
37 | + return self::stdClassToResponse($content, $responseClass); |
|
38 | + } catch (\Exception $e) { |
|
39 | + $response = new Response(); |
|
40 | + $response->success = false; |
|
41 | + $response->errors = $e->getMessage(); |
|
42 | + return $response; |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param $stdClass |
|
48 | - * @param $responseClass |
|
49 | - * @return ResponseAbstract |
|
50 | - */ |
|
51 | - protected static function stdClassToResponse($stdClass, $responseClass) |
|
52 | - { |
|
53 | - /** |
|
54 | - * @var ResponseAbstract $response |
|
55 | - */ |
|
56 | - $response = new $responseClass(); |
|
57 | - foreach ($stdClass as $key => $value) { |
|
58 | - if (method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key)) && is_array($value)) { |
|
59 | - foreach ($value as $item) { |
|
60 | - $response->{$key}[] = self::stdClassToResponse($item, $class); |
|
61 | - } |
|
62 | - } else { |
|
63 | - $response->$key = $value; |
|
64 | - } |
|
65 | - } |
|
66 | - return $response; |
|
67 | - } |
|
46 | + /** |
|
47 | + * @param $stdClass |
|
48 | + * @param $responseClass |
|
49 | + * @return ResponseAbstract |
|
50 | + */ |
|
51 | + protected static function stdClassToResponse($stdClass, $responseClass) |
|
52 | + { |
|
53 | + /** |
|
54 | + * @var ResponseAbstract $response |
|
55 | + */ |
|
56 | + $response = new $responseClass(); |
|
57 | + foreach ($stdClass as $key => $value) { |
|
58 | + if (method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key)) && is_array($value)) { |
|
59 | + foreach ($value as $item) { |
|
60 | + $response->{$key}[] = self::stdClassToResponse($item, $class); |
|
61 | + } |
|
62 | + } else { |
|
63 | + $response->$key = $value; |
|
64 | + } |
|
65 | + } |
|
66 | + return $response; |
|
67 | + } |
|
68 | 68 | } |
69 | 69 | \ No newline at end of file |
@@ -6,22 +6,22 @@ |
||
6 | 6 | |
7 | 7 | abstract class ResponseAbstract extends ArrayObject |
8 | 8 | { |
9 | - /** |
|
10 | - * @var boolean |
|
11 | - */ |
|
12 | - public $success; |
|
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - public $errors; |
|
9 | + /** |
|
10 | + * @var boolean |
|
11 | + */ |
|
12 | + public $success; |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + public $errors; |
|
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @param $property |
|
21 | - * @return mixed|null |
|
22 | - */ |
|
23 | - public function getResponseClass($property) |
|
24 | - { |
|
25 | - return isset($this->_responseClasses[$property]) ? $this->_responseClasses[$property] : null; |
|
26 | - } |
|
19 | + /** |
|
20 | + * @param $property |
|
21 | + * @return mixed|null |
|
22 | + */ |
|
23 | + public function getResponseClass($property) |
|
24 | + { |
|
25 | + return isset($this->_responseClasses[$property]) ? $this->_responseClasses[$property] : null; |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -6,23 +6,23 @@ |
||
6 | 6 | |
7 | 7 | abstract class RequestAbstract |
8 | 8 | { |
9 | - protected $_client; |
|
9 | + protected $_client; |
|
10 | 10 | |
11 | - /** |
|
12 | - * RequestAbstract constructor. |
|
13 | - * |
|
14 | - * @param Client|ClientAbstract $client |
|
15 | - */ |
|
16 | - public function __construct($client) |
|
17 | - { |
|
18 | - $this->_client = $client; |
|
19 | - } |
|
11 | + /** |
|
12 | + * RequestAbstract constructor. |
|
13 | + * |
|
14 | + * @param Client|ClientAbstract $client |
|
15 | + */ |
|
16 | + public function __construct($client) |
|
17 | + { |
|
18 | + $this->_client = $client; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @return Client |
|
23 | - */ |
|
24 | - public function getClient() |
|
25 | - { |
|
26 | - return $this->_client; |
|
27 | - } |
|
21 | + /** |
|
22 | + * @return Client |
|
23 | + */ |
|
24 | + public function getClient() |
|
25 | + { |
|
26 | + return $this->_client; |
|
27 | + } |
|
28 | 28 | } |
29 | 29 | \ No newline at end of file |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class ArrayObject extends \ArrayObject |
8 | 8 | { |
9 | - /** |
|
10 | - * ResponseAbstract constructor. |
|
11 | - * |
|
12 | - * @param array $input |
|
13 | - */ |
|
14 | - public function __construct($input = []) |
|
15 | - { |
|
16 | - parent::__construct($input, self::ARRAY_AS_PROPS, "ArrayIterator"); |
|
17 | - } |
|
9 | + /** |
|
10 | + * ResponseAbstract constructor. |
|
11 | + * |
|
12 | + * @param array $input |
|
13 | + */ |
|
14 | + public function __construct($input = []) |
|
15 | + { |
|
16 | + parent::__construct($input, self::ARRAY_AS_PROPS, "ArrayIterator"); |
|
17 | + } |
|
18 | 18 | |
19 | - public function toArray() |
|
20 | - { |
|
21 | - $result = []; |
|
22 | - foreach ($this as $key => $value) { |
|
23 | - $result[$key] = $value; |
|
24 | - } |
|
25 | - foreach ((new \ReflectionClass($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { |
|
26 | - $result[$property->name] = $this->{$property->name}; |
|
27 | - } |
|
28 | - return $result; |
|
29 | - } |
|
19 | + public function toArray() |
|
20 | + { |
|
21 | + $result = []; |
|
22 | + foreach ($this as $key => $value) { |
|
23 | + $result[$key] = $value; |
|
24 | + } |
|
25 | + foreach ((new \ReflectionClass($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { |
|
26 | + $result[$property->name] = $this->{$property->name}; |
|
27 | + } |
|
28 | + return $result; |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -6,42 +6,42 @@ |
||
6 | 6 | |
7 | 7 | class ClientAbstract extends ClassGenerator |
8 | 8 | { |
9 | - protected function formExtends() |
|
10 | - { |
|
11 | - return 'carono\rest\Client'; |
|
12 | - } |
|
9 | + protected function formExtends() |
|
10 | + { |
|
11 | + return 'carono\rest\Client'; |
|
12 | + } |
|
13 | 13 | |
14 | - protected function formClassName() |
|
15 | - { |
|
16 | - return 'ClientAbstract'; |
|
17 | - } |
|
14 | + protected function formClassName() |
|
15 | + { |
|
16 | + return 'ClientAbstract'; |
|
17 | + } |
|
18 | 18 | |
19 | - protected function formClassNamespace() |
|
20 | - { |
|
21 | - return 'carono\turbotext'; |
|
22 | - } |
|
19 | + protected function formClassNamespace() |
|
20 | + { |
|
21 | + return 'carono\turbotext'; |
|
22 | + } |
|
23 | 23 | |
24 | - protected function formOutputPath() |
|
25 | - { |
|
26 | - return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; |
|
27 | - } |
|
24 | + protected function formOutputPath() |
|
25 | + { |
|
26 | + return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; |
|
27 | + } |
|
28 | 28 | |
29 | - public function methods() |
|
30 | - { |
|
31 | - $this->phpClass->setAbstract(true); |
|
32 | - foreach ($this->params as $section) { |
|
33 | - $sectionRequest = new RequestAbstract(); |
|
34 | - $sectionRequest->renderToFile($section); |
|
35 | - $className = "\\" . $sectionRequest->formClassNamespace() . "\\" . $sectionRequest->formClassName(); |
|
36 | - $method = $this->phpClass->addMethod($section['name']); |
|
37 | - $body = <<<PHP |
|
29 | + public function methods() |
|
30 | + { |
|
31 | + $this->phpClass->setAbstract(true); |
|
32 | + foreach ($this->params as $section) { |
|
33 | + $sectionRequest = new RequestAbstract(); |
|
34 | + $sectionRequest->renderToFile($section); |
|
35 | + $className = "\\" . $sectionRequest->formClassNamespace() . "\\" . $sectionRequest->formClassName(); |
|
36 | + $method = $this->phpClass->addMethod($section['name']); |
|
37 | + $body = <<<PHP |
|
38 | 38 | return (new $className(\$this)); |
39 | 39 | PHP; |
40 | - $method->addBody($body); |
|
41 | - $method->addComment($section['description']); |
|
42 | - $method->addComment(""); |
|
43 | - $method->addComment("@return $className"); |
|
44 | - } |
|
45 | - return false; |
|
46 | - } |
|
40 | + $method->addBody($body); |
|
41 | + $method->addComment($section['description']); |
|
42 | + $method->addComment(""); |
|
43 | + $method->addComment("@return $className"); |
|
44 | + } |
|
45 | + return false; |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | \ No newline at end of file |
@@ -12,49 +12,49 @@ |
||
12 | 12 | |
13 | 13 | |
14 | 14 | $sections = [ |
15 | - 'api1' => 'order', |
|
16 | - 'api2' => 'user', |
|
17 | - 'api3' => 'microTask', |
|
18 | - 'api4' => 'message', |
|
15 | + 'api1' => 'order', |
|
16 | + 'api2' => 'user', |
|
17 | + 'api3' => 'microTask', |
|
18 | + 'api4' => 'message', |
|
19 | 19 | ]; |
20 | 20 | $apidoc = 'apidoc.html'; |
21 | 21 | if (file_exists($apidoc)) { |
22 | - $content = file_get_contents($apidoc); |
|
22 | + $content = file_get_contents($apidoc); |
|
23 | 23 | } else { |
24 | - $content = (new Client())->get('https://www.turbotext.ru/api-info/')->getBody()->getContents(); |
|
25 | - file_put_contents($apidoc, $content); |
|
24 | + $content = (new Client())->get('https://www.turbotext.ru/api-info/')->getBody()->getContents(); |
|
25 | + file_put_contents($apidoc, $content); |
|
26 | 26 | } |
27 | 27 | $query = \phpQuery::newDocumentHTML($content); |
28 | 28 | $data = []; |
29 | 29 | $i = 1; |
30 | 30 | foreach ($desc = $query->find('.api_descr') as $desc) { |
31 | - $h3 = pq($desc)->prev('h3')->text(); |
|
32 | - $item = [ |
|
33 | - 'name' => $sections['api' . $i++], |
|
34 | - 'description' => $h3, |
|
35 | - 'methods' => [] |
|
36 | - ]; |
|
37 | - foreach (pq($desc)->find('table tr') as $tr) { |
|
38 | - $tr = pq($tr); |
|
39 | - if (!$name = trim($tr->find('td')->eq(0)->text())) { |
|
40 | - continue; |
|
41 | - } |
|
42 | - $params = []; |
|
43 | - foreach ($tr->find('td')->eq(2)->find('li') as $param) { |
|
44 | - if ($parsedParam = parseParams(pq($param)->text())) { |
|
45 | - $params[] = $parsedParam; |
|
46 | - } |
|
47 | - } |
|
48 | - $returns = parseReturns($uls = $tr->find('td')->eq(3)->htmlOuter()); |
|
49 | - $method = [ |
|
50 | - 'name' => $name, |
|
51 | - 'description' => $tr->find('td')->eq(1)->text(), |
|
52 | - 'params' => $params, |
|
53 | - 'returns' => $returns |
|
54 | - ]; |
|
55 | - $item['methods'][] = $method; |
|
56 | - } |
|
57 | - $data[] = $item; |
|
31 | + $h3 = pq($desc)->prev('h3')->text(); |
|
32 | + $item = [ |
|
33 | + 'name' => $sections['api' . $i++], |
|
34 | + 'description' => $h3, |
|
35 | + 'methods' => [] |
|
36 | + ]; |
|
37 | + foreach (pq($desc)->find('table tr') as $tr) { |
|
38 | + $tr = pq($tr); |
|
39 | + if (!$name = trim($tr->find('td')->eq(0)->text())) { |
|
40 | + continue; |
|
41 | + } |
|
42 | + $params = []; |
|
43 | + foreach ($tr->find('td')->eq(2)->find('li') as $param) { |
|
44 | + if ($parsedParam = parseParams(pq($param)->text())) { |
|
45 | + $params[] = $parsedParam; |
|
46 | + } |
|
47 | + } |
|
48 | + $returns = parseReturns($uls = $tr->find('td')->eq(3)->htmlOuter()); |
|
49 | + $method = [ |
|
50 | + 'name' => $name, |
|
51 | + 'description' => $tr->find('td')->eq(1)->text(), |
|
52 | + 'params' => $params, |
|
53 | + 'returns' => $returns |
|
54 | + ]; |
|
55 | + $item['methods'][] = $method; |
|
56 | + } |
|
57 | + $data[] = $item; |
|
58 | 58 | }; |
59 | 59 | file_put_contents('data.json', json_encode($data)); |
60 | 60 |
@@ -46,55 +46,55 @@ |
||
46 | 46 | HTML; |
47 | 47 | |
48 | 48 | $description = [ |
49 | - ['Метод', 'Описание'] |
|
49 | + ['Метод', 'Описание'] |
|
50 | 50 | ]; |
51 | 51 | $sectionData = []; |
52 | 52 | foreach ($data as $section) { |
53 | - $description[] = [ |
|
54 | - '$client->' . $section['name'] . '()', |
|
55 | - $section['description'] |
|
56 | - ]; |
|
57 | - $sectionData[] = asHeader($section['description']); |
|
58 | - $sectionData[] = <<<HTML |
|
53 | + $description[] = [ |
|
54 | + '$client->' . $section['name'] . '()', |
|
55 | + $section['description'] |
|
56 | + ]; |
|
57 | + $sectionData[] = asHeader($section['description']); |
|
58 | + $sectionData[] = <<<HTML |
|
59 | 59 | ```php |
60 | 60 | \$client->{$section['name']}(); |
61 | 61 | ``` |
62 | 62 | HTML; |
63 | 63 | |
64 | - $methods = [ |
|
65 | - ['Метод', 'Описание', 'Входные данные', 'Выходные данные'] |
|
66 | - ]; |
|
64 | + $methods = [ |
|
65 | + ['Метод', 'Описание', 'Входные данные', 'Выходные данные'] |
|
66 | + ]; |
|
67 | 67 | |
68 | - foreach ($section['methods'] as $method) { |
|
69 | - $results = []; |
|
70 | - $params = []; |
|
71 | - foreach ($method['returns'] as $result) { |
|
72 | - $results[] = formParamLine($result); |
|
73 | - if (isset($result['result'])) { |
|
74 | - foreach ($result['result'] as $res) { |
|
75 | - $results[] = formParamLine($res); |
|
76 | - } |
|
77 | - } |
|
78 | - } |
|
79 | - if (isset($method['params'])) { |
|
80 | - foreach ($method['params'] as $param) { |
|
81 | - $params[] = '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); |
|
82 | - } |
|
83 | - } |
|
68 | + foreach ($section['methods'] as $method) { |
|
69 | + $results = []; |
|
70 | + $params = []; |
|
71 | + foreach ($method['returns'] as $result) { |
|
72 | + $results[] = formParamLine($result); |
|
73 | + if (isset($result['result'])) { |
|
74 | + foreach ($result['result'] as $res) { |
|
75 | + $results[] = formParamLine($res); |
|
76 | + } |
|
77 | + } |
|
78 | + } |
|
79 | + if (isset($method['params'])) { |
|
80 | + foreach ($method['params'] as $param) { |
|
81 | + $params[] = '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - $methods[] = [ |
|
86 | - formMethodName($method['name']), |
|
87 | - stripLines($method['description']), |
|
88 | - join('<br /><br />', $params), |
|
89 | - join('<br /><br />', $results), |
|
90 | - ]; |
|
91 | - } |
|
92 | - $sectionData[] = asTable($methods); |
|
85 | + $methods[] = [ |
|
86 | + formMethodName($method['name']), |
|
87 | + stripLines($method['description']), |
|
88 | + join('<br /><br />', $params), |
|
89 | + join('<br /><br />', $results), |
|
90 | + ]; |
|
91 | + } |
|
92 | + $sectionData[] = asTable($methods); |
|
93 | 93 | } |
94 | 94 | $content .= asTable($description); |
95 | 95 | |
96 | 96 | foreach ($sectionData as $sectionDatum) { |
97 | - $content .= $sectionDatum; |
|
97 | + $content .= $sectionDatum; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | $content .= asHeader('Внимание'); |