Skip to content

Commit 4355f85

Browse files
authored
Merge pull request #1 from php-api-clients/feature-astronomy
Feature: Astronomy
2 parents 9b76ad8 + 6caec7a commit 4355f85

Some content is hidden

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

42 files changed

+1032
-0
lines changed

examples/astronomy-async.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use ApiClients\Client\WeatherUnderground\AsyncClient;
4+
use ApiClients\Client\WeatherUnderground\Resource\AstronomyInterface;
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+
$client->astronomy('Broek_op_Langedijk')->done(function (AstronomyInterface $astronomy) {
14+
resource_pretty_print($astronomy);
15+
});
16+
17+
$loop->run();

examples/astronomy.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use ApiClients\Client\WeatherUnderground\Client;
4+
use function ApiClients\Foundation\resource_pretty_print;
5+
6+
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
7+
8+
$client = new Client(require 'resolve_token.php');
9+
10+
resource_pretty_print($client->astronomy('Broek_op_Langedijk'));

src/AsyncClient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ public function conditions(string $location): PromiseInterface
4646
{
4747
return $this->client->handle(new Command\ConditionsCommand($location));
4848
}
49+
50+
public function astronomy(string $location): PromiseInterface
51+
{
52+
return $this->client->handle(new Command\AstronomyCommand($location));
53+
}
4954
}

src/Client.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ApiClients\Client\WeatherUnderground;
44

5+
use ApiClients\Client\WeatherUnderground\Resource\AstronomyInterface;
56
use ApiClients\Client\WeatherUnderground\Resource\ConditionInterface;
67
use ApiClients\Client\WeatherUnderground\Resource\UserInterface;
78
use React\EventLoop\Factory;
@@ -26,6 +27,14 @@ public function __construct(string $token)
2627
$this->client = AsyncClient::create($this->loop, $token);
2728
}
2829

30+
public function astronomy(string $location): AstronomyInterface
31+
{
32+
return await(
33+
$this->client->astronomy($location),
34+
$this->loop
35+
);
36+
}
37+
2938
public function conditions(string $location): ConditionInterface
3039
{
3140
return await(
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\WeatherUnderground\CommandBus\Command;
4+
5+
use WyriHaximus\Tactician\CommandHandler\Annotations\Handler;
6+
7+
/**
8+
* @Handler("ApiClients\Client\WeatherUnderground\CommandBus\Handler\AstronomyHandler")
9+
*/
10+
final class AstronomyCommand
11+
{
12+
/**
13+
* @var string
14+
*/
15+
private $location;
16+
17+
/**
18+
* @param string $location
19+
*/
20+
public function __construct(string $location = '')
21+
{
22+
$this->location = $location;
23+
}
24+
25+
/**
26+
* @return string
27+
*/
28+
public function getLocation(): string
29+
{
30+
return $this->location;
31+
}
32+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\WeatherUnderground\CommandBus\Handler;
4+
5+
use ApiClients\Client\WeatherUnderground\CommandBus\Command\AstronomyCommand;
6+
use ApiClients\Client\WeatherUnderground\Resource\AstronomyInterface;
7+
use ApiClients\Client\WeatherUnderground\Resource\ConditionInterface;
8+
use ApiClients\Tools\Services\Client\FetchAndHydrateService;
9+
use React\Promise\PromiseInterface;
10+
11+
final class AstronomyHandler
12+
{
13+
/**
14+
* @var FetchAndHydrateService
15+
*/
16+
private $service;
17+
18+
/**
19+
* @param FetchAndHydrateService $service
20+
*/
21+
public function __construct(FetchAndHydrateService $service)
22+
{
23+
$this->service = $service;
24+
}
25+
26+
/**
27+
* Fetch the given repository and hydrate it
28+
*
29+
* @param AstronomyCommand $command
30+
* @return PromiseInterface
31+
*/
32+
public function handle(AstronomyCommand $command): PromiseInterface
33+
{
34+
return $this->service->fetch(
35+
'astronomy/q/' . $command->getLocation() . '.json',
36+
'',
37+
AstronomyInterface::HYDRATE_CLASS
38+
);
39+
}
40+
}

src/Resource/Astronomy.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\WeatherUnderground\Resource;
4+
5+
use ApiClients\Foundation\Hydrator\Annotations\EmptyResource;
6+
use ApiClients\Foundation\Hydrator\Annotations\Nested;
7+
use ApiClients\Foundation\Resource\AbstractResource;
8+
9+
/**
10+
* @Nested(
11+
* response="Response",
12+
* moon_phase="Astronomy\MoonPhase",
13+
* sun_phase="Astronomy\SunPhase"
14+
* )
15+
* @EmptyResource("EmptyAstronomy")
16+
*/
17+
abstract class Astronomy extends AbstractResource implements AstronomyInterface
18+
{
19+
/**
20+
* @var Response
21+
*/
22+
protected $response;
23+
24+
/**
25+
* @var Astronomy\MoonPhase
26+
*/
27+
protected $moon_phase;
28+
29+
/**
30+
* @var Astronomy\SunPhase
31+
*/
32+
protected $sun_phase;
33+
34+
/**
35+
* @return Response
36+
*/
37+
public function response() : Response
38+
{
39+
return $this->response;
40+
}
41+
42+
/**
43+
* @return Astronomy\MoonPhase
44+
*/
45+
public function moonPhase() : Astronomy\MoonPhase
46+
{
47+
return $this->moon_phase;
48+
}
49+
50+
/**
51+
* @return Astronomy\SunPhase
52+
*/
53+
public function sunPhase() : Astronomy\SunPhase
54+
{
55+
return $this->sun_phase;
56+
}
57+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\WeatherUnderground\Resource\Astronomy;
4+
5+
use ApiClients\Foundation\Resource\EmptyResourceInterface;
6+
7+
abstract class EmptyMoonPhase implements MoonPhaseInterface, EmptyResourceInterface
8+
{
9+
/**
10+
* @return string
11+
*/
12+
public function percentIlluminated() : string
13+
{
14+
return null;
15+
}
16+
17+
/**
18+
* @return string
19+
*/
20+
public function ageOfMoon() : string
21+
{
22+
return null;
23+
}
24+
25+
/**
26+
* @return string
27+
*/
28+
public function phaseofMoon() : string
29+
{
30+
return null;
31+
}
32+
33+
/**
34+
* @return string
35+
*/
36+
public function hemisphere() : string
37+
{
38+
return null;
39+
}
40+
41+
/**
42+
* @return Time
43+
*/
44+
public function currentTime() : Time
45+
{
46+
return null;
47+
}
48+
49+
/**
50+
* @return Time
51+
*/
52+
public function sunrise() : Time
53+
{
54+
return null;
55+
}
56+
57+
/**
58+
* @return Time
59+
*/
60+
public function sunset() : Time
61+
{
62+
return null;
63+
}
64+
65+
/**
66+
* @return Time
67+
*/
68+
public function moonrise() : Time
69+
{
70+
return null;
71+
}
72+
73+
/**
74+
* @return Time
75+
*/
76+
public function moonset() : Time
77+
{
78+
return null;
79+
}
80+
}
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+
3+
namespace ApiClients\Client\WeatherUnderground\Resource\Astronomy;
4+
5+
use ApiClients\Foundation\Resource\EmptyResourceInterface;
6+
7+
abstract class EmptySunPhase implements SunPhaseInterface, EmptyResourceInterface
8+
{
9+
/**
10+
* @return Time
11+
*/
12+
public function sunrise() : Time
13+
{
14+
return null;
15+
}
16+
17+
/**
18+
* @return Time
19+
*/
20+
public function sunset() : Time
21+
{
22+
return null;
23+
}
24+
}

0 commit comments

Comments
 (0)