Skip to content

Commit 3d8c66c

Browse files
committed
Merge branch 'master' into watching
2 parents bdd78ce + 0e9d4fe commit 3d8c66c

File tree

9 files changed

+334
-400
lines changed

9 files changed

+334
-400
lines changed

composer.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
"php": "^7.0",
1515
"api-clients/client-services": "^1.0",
1616
"api-clients/foundation": "dev-master",
17-
"api-clients/middleware": "^2.0",
18-
"api-clients/middleware-http-exceptions": "^1.0",
19-
"api-clients/middleware-json": "^1.0",
20-
"api-clients/middleware-token-authorization": "^2.0",
21-
"api-clients/middleware-user-agent": "^1.0",
17+
"api-clients/middleware": "^4.0",
18+
"api-clients/middleware-http-exceptions": "^2.0",
19+
"api-clients/middleware-json": "^2.0",
20+
"api-clients/middleware-token-authorization": "^3.0",
21+
"api-clients/middleware-user-agent": "^2.0",
2222
"api-clients/rx": "^2.1",
2323
"api-clients/rx-operators": "^2.0"
2424
},
2525
"require-dev": {
26-
"api-clients/appveyor": "dev-master",
2726
"api-clients/resource-generator": "dev-master",
2827
"api-clients/resource-test-utilities": "dev-master",
2928
"api-clients/test-utilities": "^4.1"

composer.lock

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

src/AsyncClient.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
use ApiClients\Foundation\ClientInterface;
77
use ApiClients\Foundation\Factory;
88
use ApiClients\Foundation\Options;
9+
use ApiClients\Foundation\Resource\ResourceInterface;
910
use React\EventLoop\LoopInterface;
11+
use React\Promise\CancellablePromiseInterface;
1012
use React\Promise\PromiseInterface;
1113
use Rx\Observable;
1214
use Rx\Scheduler;
@@ -71,6 +73,16 @@ public static function createFromClient(ClientInterface $client, RateLimitState
7173
return new self($client, $rateLimitState);
7274
}
7375

76+
public function hydrate(string $resource): CancellablePromiseInterface
77+
{
78+
return $this->client->hydrate($resource);
79+
}
80+
81+
public function extract(ResourceInterface $resource): CancellablePromiseInterface
82+
{
83+
return $this->client->extract($resource);
84+
}
85+
7486
public function meta(): PromiseInterface
7587
{
7688
return $this->client->handle(new Command\MetaCommand());

src/AsyncClientInterface.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,29 @@
22

33
namespace ApiClients\Client\Github;
44

5+
use ApiClients\Foundation\Resource\ResourceInterface;
6+
use React\Promise\CancellablePromiseInterface;
57
use React\Promise\PromiseInterface;
68
use Rx\Observable;
79

810
interface AsyncClientInterface
911
{
12+
/**
13+
* Take a string create by the extract method and hydrate it back to a resource.
14+
*
15+
* @param string $resource
16+
* @return CancellablePromiseInterface
17+
*/
18+
public function hydrate(string $resource): CancellablePromiseInterface;
19+
20+
/**
21+
* Extract a resource into a string for storage.
22+
*
23+
* @param ResourceInterface $resource
24+
* @return CancellablePromiseInterface
25+
*/
26+
public function extract(ResourceInterface $resource): CancellablePromiseInterface;
27+
1028
public function meta(): PromiseInterface;
1129

1230
public function user(string $user): PromiseInterface;

src/Client.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ApiClients\Client\Github\Resource\UserInterface;
66
use ApiClients\Foundation\Factory as FoundationClientFactory;
77
use ApiClients\Foundation\Options;
8+
use ApiClients\Foundation\Resource\ResourceInterface;
89
use React\EventLoop\Factory;
910
use React\EventLoop\LoopInterface;
1011
use Rx\Scheduler;
@@ -20,7 +21,7 @@ final class Client implements ClientInterface
2021
/**
2122
* @var AsyncClient
2223
*/
23-
private $client;
24+
private $asyncClient;
2425

2526
/**
2627
* @param LoopInterface $loop
@@ -29,7 +30,7 @@ final class Client implements ClientInterface
2930
private function __construct(LoopInterface $loop, AsyncClient $client)
3031
{
3132
$this->loop = $loop;
32-
$this->client = $client;
33+
$this->asyncClient = $client;
3334
}
3435

3536
/**
@@ -59,14 +60,30 @@ public static function create(
5960
return new self($loop, $asyncClient);
6061
}
6162

63+
public function hydrate(string $resource): ResourceInterface
64+
{
65+
return await(
66+
$this->asyncClient->hydrate($resource),
67+
$this->loop
68+
);
69+
}
70+
71+
public function extract(ResourceInterface $resource): string
72+
{
73+
return await(
74+
$this->asyncClient->extract($resource),
75+
$this->loop
76+
);
77+
}
78+
6279
/**
6380
* @param string $user
6481
* @return UserInterface
6582
*/
6683
public function user(string $user): UserInterface
6784
{
6885
return await(
69-
$this->client->user($user),
86+
$this->asyncClient->user($user),
7087
$this->loop
7188
);
7289
}
@@ -76,6 +93,6 @@ public function user(string $user): UserInterface
7693
*/
7794
public function getRateLimitState(): RateLimitState
7895
{
79-
return $this->client->getRateLimitState();
96+
return $this->asyncClient->getRateLimitState();
8097
}
8198
}

src/ClientInterface.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,26 @@
33
namespace ApiClients\Client\Github;
44

55
use ApiClients\Client\Github\Resource\UserInterface;
6+
use ApiClients\Foundation\Resource\ResourceInterface;
67

78
interface ClientInterface
89
{
10+
/**
11+
* Take a string create by the extract method and hydrate it back to a resource.
12+
*
13+
* @param string $resource
14+
* @return ResourceInterface
15+
*/
16+
public function hydrate(string $resource): ResourceInterface;
17+
18+
/**
19+
* Extract a resource into a string for storage.
20+
*
21+
* @param ResourceInterface $resource
22+
* @return string
23+
*/
24+
public function extract(ResourceInterface $resource): string;
25+
926
public function user(string $user): UserInterface;
1027

1128
public function getRateLimitState(): RateLimitState;

src/Middleware/RateLimitStateMiddleware.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace ApiClients\Client\Github\Middleware;
44

55
use ApiClients\Client\Github\RateLimitState;
6-
use ApiClients\Foundation\Middleware\DefaultPriorityTrait;
76
use ApiClients\Foundation\Middleware\ErrorTrait;
87
use ApiClients\Foundation\Middleware\MiddlewareInterface;
98
use ApiClients\Foundation\Middleware\PreTrait;
@@ -13,7 +12,6 @@
1312

1413
final class RateLimitStateMiddleware implements MiddlewareInterface
1514
{
16-
use DefaultPriorityTrait;
1715
use PreTrait;
1816
use ErrorTrait;
1917

@@ -42,8 +40,11 @@ public function __construct(RateLimitState $state)
4240
* @param array $options
4341
* @return CancellablePromiseInterface
4442
*/
45-
public function post(ResponseInterface $response, array $options = []): CancellablePromiseInterface
46-
{
43+
public function post(
44+
ResponseInterface $response,
45+
string $transactionId,
46+
array $options = []
47+
): CancellablePromiseInterface {
4748
foreach (self::HEADERS as $header => $method) {
4849
if (!$response->hasHeader($header)) {
4950
continue;

src/Resource/Repository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function url(): string
188188
*/
189189
public function description(): string
190190
{
191-
return $this->description;
191+
return (string)$this->description;
192192
}
193193

194194
/**

tests/Middleware/RateLimitStateMiddlewareTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ public function testPost()
1818

1919
$middleware = new RateLimitStateMiddleware($state);
2020

21-
$middleware->post(new Response(200, ['X-RateLimit-Limit' => '2']));
21+
$middleware->post(new Response(200, ['X-RateLimit-Limit' => '2']), 'abc');
2222
self::assertSame(2, $state->getLimit());
2323

24-
$middleware->post(new Response(200, ['X-RateLimit-Remaining' => '1']));
24+
$middleware->post(new Response(200, ['X-RateLimit-Remaining' => '1']), 'abc');
25+
2526
self::assertSame(1, $state->getRemaining());
2627

27-
$middleware->post(new Response(200, ['X-RateLimit-Reset' => $time]));
28+
$middleware->post(new Response(200, ['X-RateLimit-Reset' => $time]), 'abc');
2829
self::assertSame($time, $state->getReset());
2930
}
3031
}

0 commit comments

Comments
 (0)