Skip to content

Commit 1e1458b

Browse files
committed
Add RetrieveOwnedByAccountRequest
1 parent 4cc7cf2 commit 1e1458b

4 files changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types=1);
2+
3+
use Sprain\NftPort\Data\Blockchain;
4+
use Sprain\NftPort\Request\Ownership\RetrieveOwnedByAccountRequest;
5+
6+
require_once __DIR__ . '/../../vendor/autoload.php';
7+
require_once __DIR__ . '/../credentials.php';
8+
9+
10+
// Retrieve owned by account
11+
// https://docs.nftport.xyz/docs/nftport/b3A6MjE0MDYzNzM-retrieve-nf-ts-owned-by-an-account
12+
13+
$response = (new RetrieveOwnedByAccountRequest(
14+
$apiKey,
15+
$ethAddress,
16+
Blockchain::Polygon->name(),
17+
))->execute();
18+
19+
print_r($response);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sprain\NftPort\Request\Ownership;
6+
7+
use JMS\Serializer\Annotation\Exclude;
8+
use JMS\Serializer\Annotation\SerializedName;
9+
use Sprain\NftPort\Request\IdRequestInterface;
10+
use Sprain\NftPort\Request\Request;
11+
use Sprain\NftPort\Request\RequestCommonsTrait;
12+
use Sprain\NftPort\Response\Ownership\RetrieveOwnedByAccountResponse;
13+
14+
class RetrieveOwnedByAccountRequest extends Request implements IdRequestInterface
15+
{
16+
use RequestCommonsTrait;
17+
18+
public const API_PATH = '/accounts/{id}';
19+
public const RESPONSE_CLASS = RetrieveOwnedByAccountResponse::class;
20+
public const HTTP_METHOD = self::HTTP_METHOD_GET;
21+
22+
public function __construct(
23+
#[Exclude]
24+
protected string $apiKey,
25+
private string $id,
26+
#[SerializedName('chain')]
27+
private string $chain,
28+
#[SerializedName('continuation')]
29+
private ?string $continuation = null,
30+
#[SerializedName('include')]
31+
private ?string $include = null,
32+
#[SerializedName('page_number')]
33+
private ?string $pageNumber = null,
34+
#[SerializedName('page_size')]
35+
private ?string $pageSize = null,
36+
) {
37+
parent::__construct($apiKey);
38+
}
39+
40+
public function getId(): string
41+
{
42+
return $this->id;
43+
}
44+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sprain\NftPort\Response\Ownership;
6+
7+
use JMS\Serializer\Annotation\SerializedName;
8+
use JMS\Serializer\Annotation\Type;
9+
use Sprain\NftPort\Response\ResponseInterface;
10+
11+
class RetrieveOwnedByAccountResponse implements ResponseInterface
12+
{
13+
#[SerializedName('response')]
14+
public ?string $response = null;
15+
16+
#[SerializedName('nfts')]
17+
#[Type('array')]
18+
public ?array $nfts = null;
19+
20+
#[SerializedName('chain')]
21+
public ?string $chain = null;
22+
23+
#[SerializedName('total')]
24+
public ?int $total = null;
25+
26+
#[SerializedName('continuation')]
27+
public ?string $continuation = null;
28+
29+
#[SerializedName('error')]
30+
public ?string $error = null;
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Sprain\NftPort\Tests\Request\Ownership;
4+
5+
use Sprain\NftPort\Request\Minting\CustomizableMintRequest;
6+
use Sprain\NftPort\Request\Ownership\RetrieveOwnedByAccountRequest;
7+
use Sprain\NftPort\Request\Request;
8+
use Sprain\NftPort\Response\Minting\CustomizableMintResponse;
9+
use Sprain\NftPort\Response\Ownership\RetrieveOwnedByAccountResponse;
10+
use Sprain\NftPort\Tests\Request\CommonRequestTest;
11+
use Sprain\NftPort\Data\Blockchain;
12+
13+
class RetrieveOwnedByAccountRequestTest extends CommonRequestTest
14+
{
15+
public function testErrorResponse(): void
16+
{
17+
$this->doTestErrorResponse();
18+
}
19+
20+
public function testSuccessfulResponse(): void
21+
{
22+
$this->doTestSuccessfulResponse(
23+
RetrieveOwnedByAccountResponse::class
24+
);
25+
}
26+
27+
protected function getRequest(): Request
28+
{
29+
return new RetrieveOwnedByAccountRequest(
30+
'apiKey',
31+
'someWalletAddress',
32+
Blockchain::Polygon->name()
33+
);
34+
}
35+
}

0 commit comments

Comments
 (0)