8
8
class TextRuApi
9
9
{
10
10
11
+ /**
12
+ * @var
13
+ */
11
14
private $ userkey ;
15
+ private $ default_options ;
12
16
13
17
private static $ allowed_options_get = ["exceptdomain " , "excepturl " , "visible " , "copying " , "callback " ];
14
18
@@ -22,6 +26,11 @@ public function __construct($userkey, $default_options = [])
22
26
$ this ->default_options = $ default_options ;
23
27
}
24
28
29
+ /**
30
+ * Return $userkey or set $userkey if param provided
31
+ * @param null $userkey
32
+ * @return $this
33
+ */
25
34
public function userkey ($ userkey = null )
26
35
{
27
36
if (is_null ($ userkey )) return $ this ->userkey ;
@@ -31,6 +40,14 @@ public function userkey($userkey = null)
31
40
return $ this ;
32
41
}
33
42
43
+ /**
44
+ * Send API add request to TextRu
45
+ * @param $userkey
46
+ * @param $text
47
+ * @param array $options
48
+ * @return array
49
+ * @throws WrongParameterException
50
+ */
34
51
public static function add ($ userkey , $ text , $ options = [])
35
52
{
36
53
if ((empty ($ userkey )) || (empty ($ text ))) throw new WrongParameterException ("Required params is empty " , 400123 );
@@ -64,6 +81,14 @@ public function adds($text, $options = [])
64
81
return $ this ::add ($ this ->userkey , $ text , $ options );
65
82
}
66
83
84
+ /**
85
+ * Send API get request to TextRu
86
+ * @param $userkey
87
+ * @param $uid
88
+ * @param null $jsonvisible
89
+ * @return array
90
+ * @throws WrongParameterException
91
+ */
67
92
public static function get ($ userkey , $ uid , $ jsonvisible = null )
68
93
{
69
94
if ((empty ($ userkey )) || (empty ($ uid ))) throw new WrongParameterException ("Required params is empty " , 400131 );
@@ -97,6 +122,13 @@ public static function gets($uid, $jsonvisible = null)
97
122
return $ this ::add ($ this ->userkey , $ uid , $ jsonvisible );
98
123
}
99
124
125
+ /**
126
+ * Curl wrapper, send POST request with predefined settings
127
+ * @param $postfields
128
+ * @param string $url
129
+ * @return mixed
130
+ * @throws CurlRequestException
131
+ */
100
132
public static function sendCurl ($ postfields , $ url = 'http://api.text.ru/post ' )
101
133
{
102
134
if (is_array ($ postfields )) $ postfields = http_build_query ($ postfields , '' , '& ' );
0 commit comments