add Amp\Loop example
[m6w6/seekat] / examples / hooks.php
1 #!/usr/bin/env php
2 <?php
3
4 require_once __DIR__."/../vendor/autoload.php";
5
6 use seekat\{API, API\Future, API\Links};
7 use Monolog\{Logger, Handler};
8
9 $cli = new http\Client("curl", "seekat");
10 $cli->configure([
11 "max_host_connections" => 10,
12 "max_total_connections" => 50,
13 "use_eventloop" => true,
14 ]);
15
16 $log = new Logger("seekat");
17 $log->pushHandler(new Handler\StreamHandler(STDERR, Logger::NOTICE));
18
19 $api = new API(Future\react(), API\auth("token", getenv("GITHUB_TOKEN")), null, $cli, $log);
20
21 $api(function() use($api) {
22 $repos = yield $api->users->m6w6->repos([
23 "visibility" => "public",
24 "affiliation" => "owner"
25 ]);
26 while ($repos) {
27 $next = Links\next($repos);
28
29 $batch = [];
30 foreach ($repos as $repo) {
31 $batch[] = $repo->hooks();
32 }
33 $result = yield $batch;
34 foreach ($result as $key => $hooks) {
35 if (!count($hooks)) {
36 continue;
37 }
38 printf("%s:\n", $repos->{$key}->name);
39 foreach ($hooks as $hook) {
40 if ($hook->name == "web") {
41 printf("\t%s\n", $hook->config->url);
42 } else {
43 printf("\t%s\n", $hook->name);
44 }
45 }
46 }
47
48 $repos = yield $next;
49 }
50 });