Skip to content

Commit

Permalink
Add RetrieveOwnedByAccountRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Jan 11, 2022
1 parent 4cc7cf2 commit 1e1458b
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/Ownership/1-owned-by-account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

use Sprain\NftPort\Data\Blockchain;
use Sprain\NftPort\Request\Ownership\RetrieveOwnedByAccountRequest;

require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../credentials.php';


// Retrieve owned by account
// https://docs.nftport.xyz/docs/nftport/b3A6MjE0MDYzNzM-retrieve-nf-ts-owned-by-an-account

$response = (new RetrieveOwnedByAccountRequest(
$apiKey,
$ethAddress,
Blockchain::Polygon->name(),
))->execute();

print_r($response);
44 changes: 44 additions & 0 deletions lib/NftPort/Request/Ownership/RetrieveOwnedByAccountRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Sprain\NftPort\Request\Ownership;

use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\SerializedName;
use Sprain\NftPort\Request\IdRequestInterface;
use Sprain\NftPort\Request\Request;
use Sprain\NftPort\Request\RequestCommonsTrait;
use Sprain\NftPort\Response\Ownership\RetrieveOwnedByAccountResponse;

class RetrieveOwnedByAccountRequest extends Request implements IdRequestInterface
{
use RequestCommonsTrait;

public const API_PATH = '/accounts/{id}';
public const RESPONSE_CLASS = RetrieveOwnedByAccountResponse::class;
public const HTTP_METHOD = self::HTTP_METHOD_GET;

public function __construct(
#[Exclude]
protected string $apiKey,
private string $id,
#[SerializedName('chain')]
private string $chain,
#[SerializedName('continuation')]
private ?string $continuation = null,
#[SerializedName('include')]
private ?string $include = null,
#[SerializedName('page_number')]
private ?string $pageNumber = null,
#[SerializedName('page_size')]
private ?string $pageSize = null,
) {
parent::__construct($apiKey);
}

public function getId(): string
{
return $this->id;
}
}
31 changes: 31 additions & 0 deletions lib/NftPort/Response/Ownership/RetrieveOwnedByAccountResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Sprain\NftPort\Response\Ownership;

use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\Type;
use Sprain\NftPort\Response\ResponseInterface;

class RetrieveOwnedByAccountResponse implements ResponseInterface
{
#[SerializedName('response')]
public ?string $response = null;

#[SerializedName('nfts')]
#[Type('array')]
public ?array $nfts = null;

#[SerializedName('chain')]
public ?string $chain = null;

#[SerializedName('total')]
public ?int $total = null;

#[SerializedName('continuation')]
public ?string $continuation = null;

#[SerializedName('error')]
public ?string $error = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types=1);

namespace Sprain\NftPort\Tests\Request\Ownership;

use Sprain\NftPort\Request\Minting\CustomizableMintRequest;
use Sprain\NftPort\Request\Ownership\RetrieveOwnedByAccountRequest;
use Sprain\NftPort\Request\Request;
use Sprain\NftPort\Response\Minting\CustomizableMintResponse;
use Sprain\NftPort\Response\Ownership\RetrieveOwnedByAccountResponse;
use Sprain\NftPort\Tests\Request\CommonRequestTest;
use Sprain\NftPort\Data\Blockchain;

class RetrieveOwnedByAccountRequestTest extends CommonRequestTest
{
public function testErrorResponse(): void
{
$this->doTestErrorResponse();
}

public function testSuccessfulResponse(): void
{
$this->doTestSuccessfulResponse(
RetrieveOwnedByAccountResponse::class
);
}

protected function getRequest(): Request
{
return new RetrieveOwnedByAccountRequest(
'apiKey',
'someWalletAddress',
Blockchain::Polygon->name()
);
}
}

0 comments on commit 1e1458b

Please sign in to comment.