Skip to content

Commit 2eed199

Browse files
authored
Merge pull request #70 from php-api-clients/app
Support for getting current app
2 parents 6978d50 + 7540003 commit 2eed199

File tree

11 files changed

+472
-0
lines changed

11 files changed

+472
-0
lines changed

src/AsyncClient.php

+5
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ public function rateLimit(): PromiseInterface
151151
return $this->client->handle(new Command\RateLimitCommand());
152152
}
153153

154+
public function app(): PromiseInterface
155+
{
156+
return $this->client->handle(new Command\AppCommand());
157+
}
158+
154159
public function renderMarkdown(
155160
ReadableStreamInterface $stream,
156161
string $mode = 'markdown',

src/CommandBus/Command/AppCommand.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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\AppHandler")
9+
*/
10+
final class AppCommand
11+
{
12+
}

src/CommandBus/Handler/AppHandler.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\CommandBus\Handler;
4+
5+
use ApiClients\Client\Github\CommandBus\Command\AppCommand;
6+
use ApiClients\Client\Github\Resource\AppInterface;
7+
use ApiClients\Tools\Services\Client\FetchAndHydrateService;
8+
use React\Promise\PromiseInterface;
9+
use function React\Promise\resolve;
10+
11+
final class AppHandler
12+
{
13+
/**
14+
* @var FetchAndHydrateService
15+
*/
16+
private $service;
17+
18+
/**
19+
* RateLimitHandler constructor.
20+
* @param FetchAndHydrateService $service
21+
*/
22+
public function __construct(FetchAndHydrateService $service)
23+
{
24+
$this->service = $service;
25+
}
26+
27+
/**
28+
* @param AppCommand $command
29+
* @return PromiseInterface
30+
*/
31+
public function handle(AppCommand $command): PromiseInterface
32+
{
33+
return resolve(
34+
$this->service->fetch(
35+
'app',
36+
'',
37+
AppInterface::HYDRATE_CLASS
38+
)
39+
);
40+
}
41+
}

src/Resource/App.php

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource;
4+
5+
use ApiClients\Foundation\Hydrator\Annotation\EmptyResource;
6+
use ApiClients\Foundation\Hydrator\Annotation\Nested;
7+
use ApiClients\Foundation\Resource\AbstractResource;
8+
use DateTimeInterface;
9+
10+
/**
11+
* @Nested(
12+
* owner="User"
13+
* )
14+
* @EmptyResource("EmptyApp")
15+
*/
16+
abstract class App extends AbstractResource implements AppInterface
17+
{
18+
/**
19+
* @var int
20+
*/
21+
protected $id;
22+
23+
/**
24+
* @var string
25+
*/
26+
protected $slug;
27+
28+
/**
29+
* @var User
30+
*/
31+
protected $owner;
32+
33+
/**
34+
* @var string
35+
*/
36+
protected $name;
37+
38+
/**
39+
* @var string
40+
*/
41+
protected $description;
42+
43+
/**
44+
* @var string
45+
*/
46+
protected $external_url;
47+
48+
/**
49+
* @var string
50+
*/
51+
protected $html_url;
52+
53+
/**
54+
* @var DateTimeInterface
55+
*/
56+
protected $created_at;
57+
58+
/**
59+
* @var DateTimeInterface
60+
*/
61+
protected $updated_at;
62+
63+
/**
64+
* @var array
65+
*/
66+
protected $permissions;
67+
68+
/**
69+
* @var array
70+
*/
71+
protected $events;
72+
73+
/**
74+
* @var int
75+
*/
76+
protected $installations_count;
77+
78+
/**
79+
* @return int
80+
*/
81+
public function id(): int
82+
{
83+
return $this->id;
84+
}
85+
86+
/**
87+
* @return string
88+
*/
89+
public function slug(): string
90+
{
91+
return $this->slug;
92+
}
93+
94+
/**
95+
* @return User
96+
*/
97+
public function owner(): User
98+
{
99+
return $this->owner;
100+
}
101+
102+
/**
103+
* @return string
104+
*/
105+
public function name(): string
106+
{
107+
return $this->name;
108+
}
109+
110+
/**
111+
* @return string
112+
*/
113+
public function description(): string
114+
{
115+
return $this->description;
116+
}
117+
118+
/**
119+
* @return string
120+
*/
121+
public function externalUrl(): string
122+
{
123+
return $this->external_url;
124+
}
125+
126+
/**
127+
* @return string
128+
*/
129+
public function htmlUrl(): string
130+
{
131+
return $this->html_url;
132+
}
133+
134+
/**
135+
* @return DateTimeInterface
136+
*/
137+
public function createdAt(): DateTimeInterface
138+
{
139+
return $this->created_at;
140+
}
141+
142+
/**
143+
* @return DateTimeInterface
144+
*/
145+
public function updatedAt(): DateTimeInterface
146+
{
147+
return $this->updated_at;
148+
}
149+
150+
/**
151+
* @return array
152+
*/
153+
public function permissions(): array
154+
{
155+
return $this->permissions;
156+
}
157+
158+
/**
159+
* @return array
160+
*/
161+
public function events(): array
162+
{
163+
return $this->events;
164+
}
165+
166+
/**
167+
* @return int
168+
*/
169+
public function installationsCount(): int
170+
{
171+
return $this->installations_count;
172+
}
173+
}

src/Resource/AppInterface.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource;
4+
5+
use ApiClients\Foundation\Resource\ResourceInterface;
6+
use DateTimeInterface;
7+
8+
interface AppInterface extends ResourceInterface
9+
{
10+
const HYDRATE_CLASS = 'App';
11+
12+
/**
13+
* @return int
14+
*/
15+
public function id(): int;
16+
17+
/**
18+
* @return string
19+
*/
20+
public function slug(): string;
21+
22+
/**
23+
* @return User
24+
*/
25+
public function owner(): User;
26+
27+
/**
28+
* @return string
29+
*/
30+
public function name(): string;
31+
32+
/**
33+
* @return string
34+
*/
35+
public function description(): string;
36+
37+
/**
38+
* @return string
39+
*/
40+
public function externalUrl(): string;
41+
42+
/**
43+
* @return string
44+
*/
45+
public function htmlUrl(): string;
46+
47+
/**
48+
* @return DateTimeInterface
49+
*/
50+
public function createdAt(): DateTimeInterface;
51+
52+
/**
53+
* @return DateTimeInterface
54+
*/
55+
public function updatedAt(): DateTimeInterface;
56+
57+
/**
58+
* @return array
59+
*/
60+
public function permissions(): array;
61+
62+
/**
63+
* @return array
64+
*/
65+
public function events(): array;
66+
67+
/**
68+
* @return int
69+
*/
70+
public function installationsCount(): int;
71+
}

src/Resource/Async/App.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Async;
4+
5+
use ApiClients\Client\Github\Resource\App as BaseApp;
6+
7+
class App extends BaseApp
8+
{
9+
public function refresh(): App
10+
{
11+
throw new \Exception('TODO: create refresh method!');
12+
}
13+
}

src/Resource/Async/EmptyApp.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Resource\Async;
4+
5+
use ApiClients\Client\Github\Resource\EmptyApp as BaseEmptyApp;
6+
7+
class EmptyApp extends BaseEmptyApp
8+
{
9+
}

0 commit comments

Comments
 (0)