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.
- Endpoint does not use /profiles prefix, but decided to keep it consistent since this is how it's listed in the documentation - Even though the data structure is simple, created the entity and factory to keep it standard
- Loading branch information
Showing
9 changed files
with
1,119 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Entities; | ||
|
||
class Proxy | ||
{ | ||
public function __construct( | ||
public readonly string $pk, | ||
public readonly string $uid, | ||
public readonly string $country, | ||
public readonly string $countryName, | ||
public readonly string $city, | ||
public readonly float $gpsLat, | ||
public readonly float $gpsLong | ||
) { | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Factories; | ||
|
||
use Rapkis\Controld\Contracts\Factories\Factory; | ||
use Rapkis\Controld\Entities\Proxy; | ||
|
||
class ProxyFactory implements Factory | ||
{ | ||
public function make(array $data): Proxy | ||
{ | ||
return new Proxy( | ||
pk: $data['PK'], | ||
uid: $data['uid'], | ||
country: $data['country'], | ||
countryName: $data['country_name'], | ||
city: $data['city'], | ||
gpsLat: $data['gps_lat'], | ||
gpsLong: $data['gps_long'], | ||
); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Resources\Profiles; | ||
|
||
use Illuminate\Http\Client\PendingRequest; | ||
use Rapkis\Controld\Factories\ProxyFactory; | ||
|
||
class Proxies | ||
{ | ||
public function __construct(private readonly PendingRequest $client, private readonly ProxyFactory $proxy) | ||
{ | ||
} | ||
|
||
public function list(): \Rapkis\Controld\Responses\Proxies | ||
{ | ||
$response = $this->client->get('proxies')->json('body.proxies'); | ||
|
||
$result = new \Rapkis\Controld\Responses\Proxies(); | ||
|
||
foreach ($response as $proxy) { | ||
$proxy = $this->proxy->make($proxy); | ||
$result->put($proxy->pk, $proxy); | ||
} | ||
|
||
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rapkis\Controld\Responses; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
class Proxies extends Collection | ||
{ | ||
} |
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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rapkis\Controld\Entities\Proxy; | ||
use Rapkis\Controld\Factories\ProxyFactory; | ||
|
||
it('builds a proxy', function (array $data, Proxy $expected) { | ||
expect((new ProxyFactory())->make($data))->toEqual($expected); | ||
})->with([ | ||
[ | ||
[ | ||
'city' => 'Washington DC', | ||
'country' => 'US', | ||
'country_name' => 'United States', | ||
'PK' => 'WAS', | ||
'gps_lat' => 38.9047, | ||
'gps_long' => -77.0164, | ||
'uid' => 'United States:Washington DC', | ||
], | ||
new Proxy( | ||
pk: 'WAS', | ||
uid: 'United States:Washington DC', | ||
country: 'US', | ||
countryName: 'United States', | ||
city: 'Washington DC', | ||
gpsLat: 38.9047, | ||
gpsLong: -77.0164, | ||
), | ||
], | ||
]); |
Oops, something went wrong.