Skip to content

Commit 685152e

Browse files
authored
Merge pull request #20 from php-api-clients/feature-repository-webhooks
Webhooks
2 parents c3caf27 + 4bf6ffb commit 685152e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2327
-94
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"api-clients/middleware-pool": "^3.0",
3434
"api-clients/resource-generator": "^1.0",
3535
"api-clients/resource-test-utilities": "^1.0",
36-
"api-clients/test-utilities": "^4.1"
36+
"api-clients/test-utilities": "^4.3"
3737
},
3838
"autoload": {
3939
"psr-4": {

composer.lock

Lines changed: 543 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/organization-async.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types=1);
2+
3+
use ApiClients\Client\Github\AsyncClient;
4+
use ApiClients\Client\Github\Resource\Async\Organization;
5+
use React\EventLoop\Factory;
6+
use function ApiClients\Foundation\resource_pretty_print;
7+
8+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
9+
10+
$loop = Factory::create();
11+
$client = AsyncClient::create($loop, require 'resolve_token.php');
12+
13+
$organizations = [
14+
'php-api-clients',
15+
'reactphp',
16+
'recoilphp',
17+
];
18+
19+
if (count($argv) > 1) {
20+
unset($argv[0]);
21+
foreach ($argv as $organization) {
22+
$organizations[] = $organization;
23+
}
24+
}
25+
26+
foreach ($organizations as $organization) {
27+
$client->organization($organization)->then(function (Organization $user) {
28+
resource_pretty_print($user);
29+
30+
return $user->refresh();
31+
})->done(function (Organization $user) {
32+
resource_pretty_print($user);
33+
}, 'display_throwable');
34+
}
35+
36+
$loop->run();
37+
38+
displayState($client->getRateLimitState());
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types=1);
2+
use ApiClients\Client\Github\AsyncClient;
3+
use ApiClients\Client\Github\Resource\Async\Organization;
4+
use React\EventLoop\Factory;
5+
use function ApiClients\Foundation\resource_pretty_print;
6+
7+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
8+
9+
$loop = Factory::create();
10+
11+
$client = AsyncClient::create($loop, require 'resolve_token.php');
12+
13+
$client->organization($argv[1] ?? 'php-api-clients')->then(function (Organization $organization) {
14+
resource_pretty_print($organization);
15+
$organization->webHooks()->subscribe(function ($webHook) {
16+
resource_pretty_print($webHook, 2, true);
17+
}, function ($error) {
18+
echo (string)$error;
19+
});
20+
})->done(null, 'display_throwable');
21+
22+
$loop->run();
23+
24+
displayState($client->getRateLimitState());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types=1);
2+
use ApiClients\Client\Github\AsyncClient;
3+
use ApiClients\Client\Github\Resource\Async\Repository;
4+
use ApiClients\Client\Github\Resource\Async\User;
5+
use React\EventLoop\Factory;
6+
use function ApiClients\Foundation\resource_pretty_print;
7+
8+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
9+
10+
$loop = Factory::create();
11+
12+
$client = AsyncClient::create($loop, require 'resolve_token.php');
13+
14+
$client->user($argv[1] ?? 'php-api-clients')->then(function (User $user) use ($argv) {
15+
resource_pretty_print($user);
16+
17+
return $user->repository($argv[2] ?? 'github');
18+
})->then(function (Repository $repository) {
19+
resource_pretty_print($repository, 1, true);
20+
$repository->webHooks()->subscribe(function ($webHook) {
21+
resource_pretty_print($webHook, 2, true);
22+
}, function ($error) {
23+
echo (string)$error;
24+
});
25+
})->done(null, 'display_throwable');
26+
27+
$loop->run();
28+
29+
displayState($client->getRateLimitState());

examples/user-repository.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types=1);
2+
use ApiClients\Client\Github\Client;
3+
use function ApiClients\Foundation\resource_pretty_print;
4+
5+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
6+
7+
$client = Client::create(require 'resolve_token.php');
8+
9+
$repository = $client->user($argv[1] ?? 'php-api-clients')->repository($argv[2] ?? 'github');
10+
resource_pretty_print($repository);
11+
12+
displayState($client->getRateLimitState());

src/AsyncClient.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ public function user(string $user): PromiseInterface
9898
return $this->client->handle(new Command\UserCommand($user));
9999
}
100100

101+
/**
102+
* @param string $organization
103+
* @return PromiseInterface
104+
*/
105+
public function organization(string $organization): PromiseInterface
106+
{
107+
return $this->client->handle(new Command\OrganizationCommand($organization));
108+
}
109+
101110
/**
102111
* @return PromiseInterface
103112
*/

src/AsyncClientInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function meta(): PromiseInterface;
2929

3030
public function user(string $user): PromiseInterface;
3131

32+
public function organization(string $organization): PromiseInterface;
33+
3234
public function whoami(): PromiseInterface;
3335

3436
public function emojis(): Observable;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\CommandBus\Command;
4+
5+
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;
6+
7+
/**
8+
* @Handler("ApiClients\Client\Github\CommandBus\Handler\DeleteHandler")
9+
*/
10+
final class DeleteCommand
11+
{
12+
/**
13+
* @var string
14+
*/
15+
private $url;
16+
17+
/**
18+
* @param string $url
19+
*/
20+
public function __construct(string $url)
21+
{
22+
$this->url = $url;
23+
}
24+
25+
/**
26+
* @return string
27+
*/
28+
public function getUrl(): string
29+
{
30+
return $this->url;
31+
}
32+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\CommandBus\Command\Organization;
4+
5+
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;
6+
7+
/**
8+
* @Handler("ApiClients\Client\Github\CommandBus\Handler\Organization\AddWebHookHandler")
9+
*/
10+
final class AddWebHookCommand
11+
{
12+
/**
13+
* @var string
14+
*/
15+
private $organization;
16+
17+
/**
18+
* @var string
19+
*/
20+
private $name;
21+
22+
/**
23+
* @var array
24+
*/
25+
private $config;
26+
27+
/**
28+
* @var array
29+
*/
30+
private $events;
31+
32+
/**
33+
* @var bool
34+
*/
35+
private $active;
36+
37+
/**
38+
* @param string $organization
39+
* @param string $name
40+
* @param array $config
41+
* @param array $events
42+
* @param bool $active
43+
*/
44+
public function __construct(string $organization, string $name, array $config, array $events, bool $active)
45+
{
46+
$this->organization = $organization;
47+
$this->name = $name;
48+
$this->config = $config;
49+
$this->events = $events;
50+
$this->active = $active;
51+
}
52+
53+
/**
54+
* @return string
55+
*/
56+
public function getOrganization(): string
57+
{
58+
return $this->organization;
59+
}
60+
61+
/**
62+
* @return string
63+
*/
64+
public function getName(): string
65+
{
66+
return $this->name;
67+
}
68+
69+
/**
70+
* @return array
71+
*/
72+
public function getConfig(): array
73+
{
74+
return $this->config;
75+
}
76+
77+
/**
78+
* @return array
79+
*/
80+
public function getEvents(): array
81+
{
82+
return $this->events;
83+
}
84+
85+
/**
86+
* @return bool
87+
*/
88+
public function isActive(): bool
89+
{
90+
return $this->active;
91+
}
92+
}

0 commit comments

Comments
 (0)