Skip to content

Commit d58b90c

Browse files
committed
Add autoload instruction to composer.json and some PHPDocs
1 parent 42e0b5e commit d58b90c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

composer.json

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"name": "krylov123/textru-api",
33
"description": "Text.ru API's php connector",
4+
"autoload": {
5+
"psr-4": {
6+
"TextRuApi\\": "src/"
7+
}
8+
},
49
"require": {
510
"php": "5.6.* || >=7.0"
611
},

src/TextRuApi.php

+32
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
class TextRuApi
99
{
1010

11+
/**
12+
* @var
13+
*/
1114
private $userkey;
15+
private $default_options;
1216

1317
private static $allowed_options_get = ["exceptdomain", "excepturl", "visible", "copying", "callback"];
1418

@@ -22,6 +26,11 @@ public function __construct($userkey, $default_options = [])
2226
$this->default_options = $default_options;
2327
}
2428

29+
/**
30+
* Return $userkey or set $userkey if param provided
31+
* @param null $userkey
32+
* @return $this
33+
*/
2534
public function userkey($userkey = null)
2635
{
2736
if (is_null($userkey)) return $this->userkey;
@@ -31,6 +40,14 @@ public function userkey($userkey = null)
3140
return $this;
3241
}
3342

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+
*/
3451
public static function add($userkey, $text, $options = [])
3552
{
3653
if ((empty($userkey)) || (empty($text))) throw new WrongParameterException("Required params is empty", 400123);
@@ -64,6 +81,14 @@ public function adds($text, $options = [])
6481
return $this::add($this->userkey, $text, $options);
6582
}
6683

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+
*/
6792
public static function get($userkey, $uid, $jsonvisible = null)
6893
{
6994
if ((empty($userkey)) || (empty($uid))) throw new WrongParameterException("Required params is empty", 400131);
@@ -97,6 +122,13 @@ public static function gets($uid, $jsonvisible = null)
97122
return $this::add($this->userkey, $uid, $jsonvisible);
98123
}
99124

125+
/**
126+
* Curl wrapper, send POST request with predefined settings
127+
* @param $postfields
128+
* @param string $url
129+
* @return mixed
130+
* @throws CurlRequestException
131+
*/
100132
public static function sendCurl($postfields, $url = 'http://api.text.ru/post')
101133
{
102134
if (is_array($postfields)) $postfields = http_build_query($postfields, '', '&');

0 commit comments

Comments
 (0)