Skip to content

Commit 1ccccc7

Browse files
authored
Merge pull request #13 from clue-labs/docs
Improve documentation
2 parents e3c9fcb + 64158b1 commit 1ccccc7

File tree

3 files changed

+95
-15
lines changed

3 files changed

+95
-15
lines changed

README.md

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,26 @@ $browser = new Clue\React\Buzz\Browser($loop);
6363
$client = new Client($browser);
6464
```
6565

66-
If you need custom DNS, SSL/TLS or proxy settings, you can explicitly pass a
67-
custom [`Browser`](https://github.com/clue/reactphp-buzz#browser) instance.
66+
If you need custom connector settings (DNS resolution, TLS parameters, timeouts,
67+
proxy servers etc.), you can explicitly pass a custom instance of the
68+
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface)
69+
to the [`Browser`](https://github.com/clue/reactphp-buzz#browser) instance:
70+
71+
```php
72+
$connector = new \React\Socket\Connector($loop, array(
73+
'dns' => '127.0.0.1',
74+
'tcp' => array(
75+
'bindto' => '192.168.10.1:0'
76+
),
77+
'tls' => array(
78+
'verify_peer' => false,
79+
'verify_peer_name' => false
80+
)
81+
));
82+
83+
$browser = new Browser($loop, $connector);
84+
$client = new Client($browser);
85+
```
6886

6987
#### Promises
7088

@@ -76,21 +94,27 @@ Sending requests uses a [Promise](https://github.com/reactphp/promise)-based int
7694

7795
#### search()
7896

79-
The `search($query, $filters = array())` method can be used to search packages matching the given query string and optionally matching the given filter parameter.
80-
It resolves with an array containing zero or more `Package` objects.
97+
The `search(string $query, array $filters = array()): PromiseInterface<Package[],Exception>` method can be used to
98+
search packages matching the given query string and optionally matching the given filter parameter.
99+
100+
It resolves with an array containing zero or more [`Package`](#package) objects
101+
on success or rejects with an `Exception` on error.
81102

82103
```php
83-
$client->search('packagist')->then(function ($results) {
84-
foreach ($results as $result) {
104+
$client->search('packagist')->then(function (array $packages) {
105+
foreach ($packages as $package) {
85106
echo $package->getName() . PHP_EOL;
86107
}
87108
});
88109
```
89110

90111
#### get()
91112

92-
The `get($name)` method can be used to get package details for the given package name.
93-
It resolves with a single `Package` object.
113+
The `get(string $name): PromiseInterface<Package,Exception>` method can be used to
114+
get package details for the given package name.
115+
116+
It resolves with a single [`Package`](#package) object
117+
on success or rejects with an `Exception` on error.
94118

95119
```php
96120
$client->get('clue/packagist-api-react')->then(function (Package $package) {
@@ -100,11 +124,14 @@ $client->get('clue/packagist-api-react')->then(function (Package $package) {
100124

101125
#### all()
102126

103-
The `all($filters = array())` method an be used to list all package names, optionally matching the given filter parameter.
104-
It resolves with an array of package names.
127+
The `all(array $filters = array()): PromiseInterface<string[],Exception>` method an be used to
128+
list all package names, optionally matching the given filter parameter.
129+
130+
It resolves with an array of package names
131+
on success or rejects with an `Exception` on error.
105132

106133
```php
107-
$client->all(array('vendor' => 'clue'))->then(function ($list) {
134+
$client->all(array('vendor' => 'clue'))->then(function (array $names) {
108135
// array containing (among others) "clue/packagist-api-react"
109136
});
110137
```
@@ -130,7 +157,7 @@ The `getDescription()` method can be used to the package description.
130157
The recommended way to install this library is [through Composer](https://getcomposer.org).
131158
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
132159

133-
This project follows [SemVer](http://semver.org/).
160+
This project follows [SemVer](https://semver.org/).
134161
This will install the latest supported version:
135162

136163
```bash
@@ -161,4 +188,7 @@ $ php vendor/bin/phpunit
161188

162189
## License
163190

164-
MIT
191+
This project is released under the permissive [MIT license](LICENSE).
192+
193+
> Did you know that I offer custom development services and issuing invoices for
194+
sponsorships of releases and for contributions? Contact me (@clue) for details.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "clue/packagist-api-react",
33
"description": "Simple async access to packagist.org's API, like listing project details, number of downloads etc., built on top of ReactPHP.",
44
"keywords": ["packagist", "composer packages", "ReactPHP", "async"],
5-
"homepage": "https://github.com/clue/php-packagist-api-react",
5+
"homepage": "https://github.com/clue/reactphp-packagist-api",
66
"license": "MIT",
77
"authors": [
88
{

src/Client.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace Clue\React\Packagist\Api;
44

5-
use Packagist\Api\Result\Factory;
65
use Clue\React\Buzz\Browser;
6+
use Packagist\Api\Result\Factory;
7+
use Packagist\Api\Result\Package;
78
use Psr\Http\Message\ResponseInterface;
9+
use React\Promise\PromiseInterface;
810
use Rize\UriTemplate;
911

1012
class Client
@@ -29,6 +31,24 @@ public function __construct(Browser $http, Factory $resultFactory = null, UriTem
2931
$this->uri = $uri;
3032
}
3133

34+
/**
35+
* Search packages matching the given query string and optionally matching the given filter parameter.
36+
*
37+
* It resolves with an array containing zero or more [`Package`](#package) objects
38+
* on success or rejects with an `Exception` on error.
39+
*
40+
* ```php
41+
* $client->search('packagist')->then(function (array $packages) {
42+
* foreach ($packages as $package) {
43+
* echo $package->getName() . PHP_EOL;
44+
* }
45+
* });
46+
* ```
47+
*
48+
* @param string $query
49+
* @param array $filters
50+
* @return PromiseInterface<Package[],\Exception>
51+
*/
3252
public function search($query, array $filters = array())
3353
{
3454
$filters['q'] = $query;
@@ -59,6 +79,21 @@ public function search($query, array $filters = array())
5979
return $fetch($url);
6080
}
6181

82+
/**
83+
* Get package details for the given package name.
84+
*
85+
* It resolves with a single [`Package`](#package) object
86+
* on success or rejects with an `Exception` on error.
87+
*
88+
* ```php
89+
* $client->get('clue/packagist-api-react')->then(function (Package $package) {
90+
* echo $package->getDescription();
91+
* });
92+
* ```
93+
*
94+
* @param string $package
95+
* @return PromiseInterface<Package,\Exception>
96+
*/
6297
public function get($package)
6398
{
6499
return $this->respond(
@@ -71,6 +106,21 @@ public function get($package)
71106
);
72107
}
73108

109+
/**
110+
* List all package names, optionally matching the given filter parameter.
111+
*
112+
* It resolves with an array of package names
113+
* on success or rejects with an `Exception` on error.
114+
*
115+
* ```php
116+
* $client->all(array('vendor' => 'clue'))->then(function (array $names) {
117+
* // array containing (among others) "clue/packagist-api-react"
118+
* });
119+
* ```
120+
*
121+
* @param array $filters
122+
* @return PromiseInterface<string[],\Exception>
123+
*/
74124
public function all(array $filters = array())
75125
{
76126
return $this->respond(

0 commit comments

Comments
 (0)