generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Standard implementation as other endpoints - Fix incorrect test case names - Remove ExampleTest.php
- Loading branch information
Showing
15 changed files
with
352 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Entities; | ||
|
||
class Network | ||
{ | ||
public function __construct( | ||
public readonly string $iataCode, | ||
public readonly string $city, | ||
public readonly string $country, | ||
public readonly float $gpsLat, | ||
public readonly float $gpsLong, | ||
public readonly int $apiStatus, | ||
public readonly int $dnsStatus, | ||
public readonly int $proxyStatus, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Factories; | ||
|
||
use Rapkis\Controld\Contracts\Factories\Factory; | ||
use Rapkis\Controld\Responses\DatacenterIp; | ||
|
||
class DatacenterIpFactory implements Factory | ||
{ | ||
public function make(array $data): DatacenterIp | ||
{ | ||
return new DatacenterIp( | ||
ip: $data['ip'], | ||
type: $data['type'], | ||
organization: $data['org'], | ||
country: $data['country'], | ||
handler: $data['handler'], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Rapkis\Controld\Factories; | ||
|
||
use Rapkis\Controld\Contracts\Factories\Factory; | ||
use Rapkis\Controld\Entities\Network; | ||
|
||
class NetworkFactory implements Factory | ||
{ | ||
public function make(array $data): Network | ||
{ | ||
return new Network( | ||
iataCode: $data['iata_code'], | ||
city: $data['city_name'], | ||
country: $data['country_name'], | ||
gpsLat: (float) $data['location']['lat'], | ||
gpsLong: (float) $data['location']['long'], | ||
apiStatus: (int) $data['status']['api'], | ||
dnsStatus: (int) $data['status']['dns'], | ||
proxyStatus: (int) $data['status']['pxy'], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Resources; | ||
|
||
use Illuminate\Http\Client\PendingRequest; | ||
use Rapkis\Controld\Factories\DatacenterIpFactory; | ||
use Rapkis\Controld\Factories\NetworkFactory; | ||
use Rapkis\Controld\Responses\DatacenterIp; | ||
use Rapkis\Controld\Responses\Networks; | ||
|
||
class Misc | ||
{ | ||
public function __construct( | ||
private readonly PendingRequest $client, | ||
private readonly DatacenterIpFactory $ip, | ||
private readonly NetworkFactory $network, | ||
) { | ||
} | ||
|
||
public function ip(): DatacenterIp | ||
{ | ||
return $this->ip->make($this->client->get('ip')->json('body')); | ||
} | ||
|
||
public function networkStats() | ||
{ | ||
$response = $this->client->get('network')->json('body'); | ||
|
||
$result = new Networks(time: $response['time'], currentPop: $response['current_pop']); | ||
|
||
foreach ($response['network'] as $network) { | ||
$network = $this->network->make($network); | ||
$result->put($network->iataCode, $network); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Responses; | ||
|
||
class DatacenterIp | ||
{ | ||
public function __construct( | ||
public readonly string $ip, | ||
public readonly string $type, | ||
public readonly string $organization, | ||
public readonly string $country, | ||
public readonly string $handler, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Responses; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
class Networks extends Collection | ||
{ | ||
public function __construct(public readonly int $time, public readonly string $currentPop, $items = []) | ||
{ | ||
parent::__construct($items); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rapkis\Controld\Factories\DatacenterIpFactory; | ||
use Rapkis\Controld\Responses\DatacenterIp; | ||
|
||
it('builds a data center ip', function (array $data, DatacenterIp $expected) { | ||
expect((new DatacenterIpFactory())->make($data))->toEqual($expected); | ||
})->with([ | ||
[ | ||
[ | ||
'ip' => '66.207.0.0', | ||
'type' => 'v4', | ||
'org' => 'Beanfield Technologies', | ||
'country' => 'CA', | ||
'handler' => 'dva-h01', | ||
], | ||
new DatacenterIp( | ||
ip: '66.207.0.0', | ||
type: 'v4', | ||
organization: 'Beanfield Technologies', | ||
country: 'CA', | ||
handler: 'dva-h01', | ||
), | ||
], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rapkis\Controld\Entities\Network; | ||
use Rapkis\Controld\Factories\NetworkFactory; | ||
|
||
it('builds a network', function (array $data, Network $expected) { | ||
expect((new NetworkFactory())->make($data))->toEqual($expected); | ||
})->with([ | ||
[ | ||
[ | ||
'iata_code' => 'SYD', | ||
'city_name' => 'Sydney', | ||
'country_name' => 'AU', | ||
'location' => [ | ||
'lat' => -111.1111, | ||
'long' => 222.2222, | ||
], | ||
'status' => [ | ||
'api' => 1, | ||
'dns' => 0, | ||
'pxy' => -1, | ||
], | ||
], | ||
new Network( | ||
iataCode: 'SYD', | ||
city: 'Sydney', | ||
country: 'AU', | ||
gpsLat: -111.1111, | ||
gpsLong: 222.2222, | ||
apiStatus: 1, | ||
dnsStatus: 0, | ||
proxyStatus: -1, | ||
), | ||
], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"body": { | ||
"ip": "66.207.0.0", | ||
"type": "v4", | ||
"org": "Beanfield Technologies", | ||
"country": "CA", | ||
"handler": "dva-h01" | ||
}, | ||
"success": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"body": { | ||
"network": [ | ||
{ | ||
"iata_code": "AMS", | ||
"city_name": "Amsterdam", | ||
"country_name": "NL", | ||
"location": { | ||
"lat": 52.377956, | ||
"long": 4.89707 | ||
}, | ||
"status": { | ||
"api": 1, | ||
"dns": 1, | ||
"pxy": -1 | ||
} | ||
}, | ||
{ | ||
"iata_code": "CDG", | ||
"city_name": "Paris", | ||
"country_name": "FR", | ||
"location": { | ||
"lat": 48.81340913389218, | ||
"long": 2.5556617457046547 | ||
}, | ||
"status": { | ||
"api": 1, | ||
"dns": 1, | ||
"pxy": -1 | ||
} | ||
}, | ||
{ | ||
"iata_code": "CGH", | ||
"city_name": "São Paulo", | ||
"country_name": "BR", | ||
"location": { | ||
"lat": -23.72876040612837, | ||
"long": -46.48397842634525 | ||
}, | ||
"status": { | ||
"api": 1, | ||
"dns": 1, | ||
"pxy": 1 | ||
} | ||
}, | ||
{ | ||
"iata_code": "CHI", | ||
"city_name": "Chicago", | ||
"country_name": "US", | ||
"location": { | ||
"lat": 41.855159216729724, | ||
"long": -87.67313302781018 | ||
}, | ||
"status": { | ||
"api": 1, | ||
"dns": 1, | ||
"pxy": -1 | ||
} | ||
}, | ||
{ | ||
"iata_code": "DAL", | ||
"city_name": "Dallas", | ||
"country_name": "US", | ||
"location": { | ||
"lat": 32.83519150465354, | ||
"long": -96.66913588349176 | ||
}, | ||
"status": { | ||
"api": 1, | ||
"dns": 1, | ||
"pxy": -1 | ||
} | ||
} | ||
], | ||
"time": 1695135064, | ||
"current_pop": "IAD" | ||
}, | ||
"success": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Support\Facades\Http; | ||
use Rapkis\Controld\Factories\DatacenterIpFactory; | ||
use Rapkis\Controld\Factories\NetworkFactory; | ||
use Rapkis\Controld\Resources\Misc; | ||
use Rapkis\Controld\Responses\DatacenterIp; | ||
use Rapkis\Controld\Responses\Networks; | ||
|
||
beforeEach(function () { | ||
Http::preventStrayRequests(); | ||
}); | ||
|
||
it('shows datacenter ip', function () { | ||
$request = Http::fake([ | ||
'ip' => Http::response(mockJsonEndpoint('misc-ip')), | ||
])->asJson(); | ||
|
||
$resource = new Misc( | ||
$request, | ||
app(DatacenterIpFactory::class), | ||
$this->createStub(NetworkFactory::class), | ||
); | ||
|
||
$result = $resource->ip(); | ||
|
||
expect($result)->toBeInstanceOf(DatacenterIp::class); | ||
}); | ||
|
||
it('lists network statuses', function () { | ||
$request = Http::fake([ | ||
'network' => Http::response(mockJsonEndpoint('misc-network')), | ||
])->asJson(); | ||
|
||
$resource = new Misc( | ||
$request, | ||
$this->createStub(DatacenterIpFactory::class), | ||
app(NetworkFactory::class), | ||
); | ||
|
||
$result = $resource->networkStats(); | ||
|
||
expect($result)->toBeInstanceOf(Networks::class) | ||
->and($result)->toHaveCount(5) | ||
->and($result->time)->toBe(1695135064) | ||
->and($result->currentPop)->toBe('IAD'); | ||
}); |