@@ -39,10 +39,49 @@ public static function add($userkey, $text, $options = [])
39
39
$ post_options = ["userkey " => $ userkey , "text " => $ text ];
40
40
if (!empty ($ options )) $ post_options = array_merge ($ post_options , $ options );
41
41
42
- return $ this ::sendCurl ($ post_options );
42
+ $ answer_decoded = self ::sendCurl ($ post_options );
43
+
44
+ $ result = [
45
+ "error " => ["code " => null , "desc " => null ],
46
+ "text_uid " => null
47
+ ];
48
+
49
+ if (isset ($ answer_decoded ->error_code )) $ result ["error " ]["code " ] = $ answer_decoded ->error_code ;
50
+ if (isset ($ answer_decoded ->error_desc )) $ result ["error " ]["desc " ] = $ answer_decoded ->error_desc ;
51
+ if (isset ($ answer_decoded ->text_uid )) $ result ["text_uid " ] = $ answer_decoded ->text_uid ;
52
+
53
+ return $ result ;
43
54
44
55
}
45
56
57
+ public static function get ($ userkey , $ uid , $ jsonvisible = null )
58
+ {
59
+ if ((empty ($ userkey )) || (empty ($ uid ))) throw new WrongParameterException ("Required params is empty " , 400131 );
60
+
61
+ $ post_options = ["userkey " => $ userkey , "uid " => $ uid ];
62
+ if (!is_null ($ jsonvisible )) $ post_options ["jsonvisible " ] = "detail " ;
63
+
64
+ $ answer_decoded = self ::sendCurl ($ post_options );
65
+
66
+ $ result = [
67
+ "error " => ["code " => null , "desc " => null ],
68
+ "text_unique " => null ,
69
+ "result_json " => null ,
70
+ "spell_check " => null ,
71
+ "seo_check " => null
72
+ ];
73
+
74
+ if (isset ($ answer_decoded ->error_code )) $ result ["error " ]["code " ] = $ answer_decoded ->error_code ;
75
+ if (isset ($ answer_decoded ->error_desc )) $ result ["error " ]["desc " ] = $ answer_decoded ->error_desc ;
76
+
77
+ if (isset ($ answer_decoded ->text_unique )) $ result ["text_unique " ] = $ answer_decoded ->text_unique ;
78
+ if (isset ($ answer_decoded ->result_json )) $ result ["result_json " ] = $ answer_decoded ->result_json ;
79
+ if (isset ($ answer_decoded ->spell_check )) $ result ["spell_check " ] = $ answer_decoded ->spell_check ;
80
+ if (isset ($ answer_decoded ->seo_check )) $ result ["seo_check " ] = $ answer_decoded ->seo_check ;
81
+
82
+ return $ result ;
83
+ }
84
+
46
85
public static function sendCurl ($ postfields , $ url = 'http://api.text.ru/post ' )
47
86
{
48
87
if (is_array ($ postfields )) $ postfields = http_build_query ($ postfields , '' , '& ' );
@@ -55,20 +94,8 @@ public static function sendCurl($postfields, $url = 'http://api.text.ru/post')
55
94
$ answer = curl_exec ($ ch );
56
95
$ errno = curl_errno ($ ch );
57
96
58
- $ result = [
59
- "error " => ["code " => null , "desc " => null ],
60
- "text_uid " => null
61
- ];
62
-
63
97
if ($ errno ) throw new CurlRequestException (curl_error ($ ch ), $ errno );
64
98
65
- $ answer_decoded = json_decode ($ answer );
66
-
67
- if (isset ($ answer_decoded ->error_code )) $ result ["error " ]["code " ] = $ answer_decoded ->error_code ;
68
- if (isset ($ answer_decoded ->error_desc )) $ result ["error " ]["desc " ] = $ answer_decoded ->error_desc ;
69
- if (isset ($ answer_decoded ->text_uid )) $ result ["text_uid " ] = $ answer_decoded ->text_uid ;
70
-
71
- return $ result ;
72
-
99
+ return json_decode ($ answer );
73
100
}
74
101
}
0 commit comments